#![allow(clippy::ptr_arg)]
use std::collections::{BTreeSet, HashMap};
use tokio::time::sleep;
#[derive(Clone)]
pub struct Discovery<C> {
pub client: common::Client<C>,
pub auth: Box<dyn common::GetToken>,
_user_agent: String,
_base_url: String,
_root_url: String,
}
impl<C> common::Hub for Discovery<C> {}
impl<'a, C> Discovery<C> {
pub fn new<A: 'static + common::GetToken>(client: common::Client<C>, auth: A) -> Discovery<C> {
Discovery {
client,
auth: Box::new(auth),
_user_agent: "google-api-rust-client/7.0.0".to_string(),
_base_url: "https://www.googleapis.com/discovery/v1/".to_string(),
_root_url: "https://www.googleapis.com/".to_string(),
}
}
pub fn apis(&'a self) -> ApiMethods<'a, C> {
ApiMethods { hub: self }
}
pub fn user_agent(&mut self, agent_name: String) -> String {
std::mem::replace(&mut self._user_agent, agent_name)
}
pub fn base_url(&mut self, new_base_url: String) -> String {
std::mem::replace(&mut self._base_url, new_base_url)
}
pub fn root_url(&mut self, new_root_url: String) -> String {
std::mem::replace(&mut self._root_url, new_root_url)
}
}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[serde_with::serde_as]
#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct DirectoryList {
#[serde(rename = "discoveryVersion")]
pub discovery_version: Option<String>,
pub items: Option<Vec<DirectoryListItems>>,
pub kind: Option<String>,
}
impl common::ResponseResult for DirectoryList {}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[serde_with::serde_as]
#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct JsonSchema {
#[serde(rename = "$ref")]
pub ref_: Option<String>,
#[serde(rename = "additionalProperties")]
pub additional_properties: Option<Option<Box<JsonSchema>>>,
pub annotations: Option<JsonSchemaAnnotations>,
pub default: Option<String>,
pub deprecated: Option<bool>,
pub description: Option<String>,
#[serde(rename = "enum")]
pub enum_: Option<Vec<String>>,
#[serde(rename = "enumDeprecated")]
pub enum_deprecated: Option<Vec<bool>>,
#[serde(rename = "enumDescriptions")]
pub enum_descriptions: Option<Vec<String>>,
pub format: Option<String>,
pub id: Option<String>,
pub items: Option<Option<Box<JsonSchema>>>,
pub location: Option<String>,
pub maximum: Option<String>,
pub minimum: Option<String>,
pub pattern: Option<String>,
pub properties: Option<HashMap<String, JsonSchema>>,
#[serde(rename = "readOnly")]
pub read_only: Option<bool>,
pub repeated: Option<bool>,
pub required: Option<bool>,
#[serde(rename = "type")]
pub type_: Option<String>,
pub variant: Option<JsonSchemaVariant>,
}
impl common::Part for JsonSchema {}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[serde_with::serde_as]
#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct RestDescription {
pub auth: Option<RestDescriptionAuth>,
#[serde(rename = "basePath")]
pub base_path: Option<String>,
#[serde(rename = "baseUrl")]
pub base_url: Option<String>,
#[serde(rename = "batchPath")]
pub batch_path: Option<String>,
#[serde(rename = "canonicalName")]
pub canonical_name: Option<String>,
pub description: Option<String>,
#[serde(rename = "discoveryVersion")]
pub discovery_version: Option<String>,
#[serde(rename = "documentationLink")]
pub documentation_link: Option<String>,
pub endpoints: Option<Vec<RestDescriptionEndpoints>>,
pub etag: Option<String>,
#[serde(rename = "exponentialBackoffDefault")]
pub exponential_backoff_default: Option<bool>,
pub features: Option<Vec<String>>,
pub icons: Option<RestDescriptionIcons>,
pub id: Option<String>,
pub kind: Option<String>,
pub labels: Option<Vec<String>>,
pub methods: Option<HashMap<String, RestMethod>>,
pub name: Option<String>,
#[serde(rename = "ownerDomain")]
pub owner_domain: Option<String>,
#[serde(rename = "ownerName")]
pub owner_name: Option<String>,
#[serde(rename = "packagePath")]
pub package_path: Option<String>,
pub parameters: Option<HashMap<String, JsonSchema>>,
pub protocol: Option<String>,
pub resources: Option<HashMap<String, RestResource>>,
pub revision: Option<String>,
#[serde(rename = "rootUrl")]
pub root_url: Option<String>,
pub schemas: Option<HashMap<String, JsonSchema>>,
#[serde(rename = "servicePath")]
pub service_path: Option<String>,
pub title: Option<String>,
pub version: Option<String>,
pub version_module: Option<bool>,
}
impl common::ResponseResult for RestDescription {}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[serde_with::serde_as]
#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct RestMethod {
#[serde(rename = "apiVersion")]
pub api_version: Option<String>,
pub deprecated: Option<bool>,
pub description: Option<String>,
#[serde(rename = "etagRequired")]
pub etag_required: Option<bool>,
#[serde(rename = "flatPath")]
pub flat_path: Option<String>,
#[serde(rename = "httpMethod")]
pub http_method: Option<String>,
pub id: Option<String>,
#[serde(rename = "mediaUpload")]
pub media_upload: Option<RestMethodMediaUpload>,
#[serde(rename = "parameterOrder")]
pub parameter_order: Option<Vec<String>>,
pub parameters: Option<HashMap<String, JsonSchema>>,
pub path: Option<String>,
pub request: Option<RestMethodRequest>,
pub response: Option<RestMethodResponse>,
pub scopes: Option<Vec<String>>,
#[serde(rename = "supportsMediaDownload")]
pub supports_media_download: Option<bool>,
#[serde(rename = "supportsMediaUpload")]
pub supports_media_upload: Option<bool>,
#[serde(rename = "supportsSubscription")]
pub supports_subscription: Option<bool>,
#[serde(rename = "useMediaDownloadService")]
pub use_media_download_service: Option<bool>,
}
impl common::Part for RestMethod {}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[serde_with::serde_as]
#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct RestResource {
pub deprecated: Option<bool>,
pub methods: Option<HashMap<String, RestMethod>>,
pub resources: Option<HashMap<String, RestResource>>,
}
impl common::Part for RestResource {}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[serde_with::serde_as]
#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct DirectoryListItems {
pub description: Option<String>,
#[serde(rename = "discoveryLink")]
pub discovery_link: Option<String>,
#[serde(rename = "discoveryRestUrl")]
pub discovery_rest_url: Option<String>,
#[serde(rename = "documentationLink")]
pub documentation_link: Option<String>,
pub icons: Option<DirectoryListItemsIcons>,
pub id: Option<String>,
pub kind: Option<String>,
pub labels: Option<Vec<String>>,
pub name: Option<String>,
pub preferred: Option<bool>,
pub title: Option<String>,
pub version: Option<String>,
}
impl common::NestedType for DirectoryListItems {}
impl common::Part for DirectoryListItems {}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[serde_with::serde_as]
#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct DirectoryListItemsIcons {
pub x16: Option<String>,
pub x32: Option<String>,
}
impl common::NestedType for DirectoryListItemsIcons {}
impl common::Part for DirectoryListItemsIcons {}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[serde_with::serde_as]
#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct JsonSchemaAnnotations {
pub required: Option<Vec<String>>,
}
impl common::NestedType for JsonSchemaAnnotations {}
impl common::Part for JsonSchemaAnnotations {}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[serde_with::serde_as]
#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct JsonSchemaVariant {
pub discriminant: Option<String>,
pub map: Option<Vec<JsonSchemaVariantMap>>,
}
impl common::NestedType for JsonSchemaVariant {}
impl common::Part for JsonSchemaVariant {}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[serde_with::serde_as]
#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct JsonSchemaVariantMap {
#[serde(rename = "$ref")]
pub ref_: Option<String>,
pub type_value: Option<String>,
}
impl common::NestedType for JsonSchemaVariantMap {}
impl common::Part for JsonSchemaVariantMap {}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[serde_with::serde_as]
#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct RestDescriptionAuth {
pub oauth2: Option<RestDescriptionAuthOauth2>,
}
impl common::NestedType for RestDescriptionAuth {}
impl common::Part for RestDescriptionAuth {}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[serde_with::serde_as]
#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct RestDescriptionAuthOauth2 {
pub scopes: Option<HashMap<String, RestDescriptionAuthOauth2Scopes>>,
}
impl common::NestedType for RestDescriptionAuthOauth2 {}
impl common::Part for RestDescriptionAuthOauth2 {}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[serde_with::serde_as]
#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct RestDescriptionAuthOauth2Scopes {
pub description: Option<String>,
}
impl common::NestedType for RestDescriptionAuthOauth2Scopes {}
impl common::Part for RestDescriptionAuthOauth2Scopes {}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[serde_with::serde_as]
#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct RestDescriptionEndpoints {
pub deprecated: Option<bool>,
pub description: Option<String>,
#[serde(rename = "endpointUrl")]
pub endpoint_url: Option<String>,
pub location: Option<String>,
}
impl common::NestedType for RestDescriptionEndpoints {}
impl common::Part for RestDescriptionEndpoints {}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[serde_with::serde_as]
#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct RestDescriptionIcons {
pub x16: Option<String>,
pub x32: Option<String>,
}
impl common::NestedType for RestDescriptionIcons {}
impl common::Part for RestDescriptionIcons {}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[serde_with::serde_as]
#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct RestMethodMediaUpload {
pub accept: Option<Vec<String>>,
#[serde(rename = "maxSize")]
pub max_size: Option<String>,
pub protocols: Option<RestMethodMediaUploadProtocols>,
}
impl common::NestedType for RestMethodMediaUpload {}
impl common::Part for RestMethodMediaUpload {}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[serde_with::serde_as]
#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct RestMethodMediaUploadProtocols {
pub resumable: Option<RestMethodMediaUploadProtocolsResumable>,
pub simple: Option<RestMethodMediaUploadProtocolsSimple>,
}
impl common::NestedType for RestMethodMediaUploadProtocols {}
impl common::Part for RestMethodMediaUploadProtocols {}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[serde_with::serde_as]
#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct RestMethodMediaUploadProtocolsResumable {
pub multipart: Option<bool>,
pub path: Option<String>,
}
impl common::NestedType for RestMethodMediaUploadProtocolsResumable {}
impl common::Part for RestMethodMediaUploadProtocolsResumable {}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[serde_with::serde_as]
#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct RestMethodMediaUploadProtocolsSimple {
pub multipart: Option<bool>,
pub path: Option<String>,
}
impl common::NestedType for RestMethodMediaUploadProtocolsSimple {}
impl common::Part for RestMethodMediaUploadProtocolsSimple {}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[serde_with::serde_as]
#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct RestMethodRequest {
#[serde(rename = "$ref")]
pub ref_: Option<String>,
#[serde(rename = "parameterName")]
pub parameter_name: Option<String>,
}
impl common::NestedType for RestMethodRequest {}
impl common::Part for RestMethodRequest {}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[serde_with::serde_as]
#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct RestMethodResponse {
#[serde(rename = "$ref")]
pub ref_: Option<String>,
}
impl common::NestedType for RestMethodResponse {}
impl common::Part for RestMethodResponse {}
pub struct ApiMethods<'a, C>
where
C: 'a,
{
hub: &'a Discovery<C>,
}
impl<'a, C> common::MethodsBuilder for ApiMethods<'a, C> {}
impl<'a, C> ApiMethods<'a, C> {
pub fn get_rest(&self, api: &str, version: &str) -> ApiGetRestCall<'a, C> {
ApiGetRestCall {
hub: self.hub,
_api: api.to_string(),
_version: version.to_string(),
_delegate: Default::default(),
_additional_params: Default::default(),
}
}
pub fn list(&self) -> ApiListCall<'a, C> {
ApiListCall {
hub: self.hub,
_preferred: Default::default(),
_name: Default::default(),
_delegate: Default::default(),
_additional_params: Default::default(),
}
}
}
pub struct ApiGetRestCall<'a, C>
where
C: 'a,
{
hub: &'a Discovery<C>,
_api: String,
_version: String,
_delegate: Option<&'a mut dyn common::Delegate>,
_additional_params: HashMap<String, String>,
}
impl<'a, C> common::CallBuilder for ApiGetRestCall<'a, C> {}
impl<'a, C> ApiGetRestCall<'a, C>
where
C: common::Connector,
{
pub async fn doit(mut self) -> common::Result<(common::Response, RestDescription)> {
use std::borrow::Cow;
use std::io::{Read, Seek};
use common::{url::Params, ToParts};
use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
let mut dd = common::DefaultDelegate;
let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
dlg.begin(common::MethodInfo {
id: "discovery.apis.getRest",
http_method: hyper::Method::GET,
});
for &field in ["alt", "api", "version"].iter() {
if self._additional_params.contains_key(field) {
dlg.finished(false);
return Err(common::Error::FieldClash(field));
}
}
let mut params = Params::with_capacity(4 + self._additional_params.len());
params.push("api", self._api);
params.push("version", self._version);
params.extend(self._additional_params.iter());
params.push("alt", "json");
let mut url = self.hub._base_url.clone() + "apis/{api}/{version}/rest";
#[allow(clippy::single_element_loop)]
for &(find_this, param_name) in [("{api}", "api"), ("{version}", "version")].iter() {
url = params.uri_replacement(url, param_name, find_this, false);
}
{
let to_remove = ["version", "api"];
params.remove_params(&to_remove);
}
let url = params.parse_with_url(&url);
loop {
let mut req_result = {
let client = &self.hub.client;
dlg.pre_request();
let mut req_builder = hyper::Request::builder()
.method(hyper::Method::GET)
.uri(url.as_str())
.header(USER_AGENT, self.hub._user_agent.clone());
let request = req_builder
.header(CONTENT_LENGTH, 0_u64)
.body(common::to_body::<String>(None));
client.request(request.unwrap()).await
};
match req_result {
Err(err) => {
if let common::Retry::After(d) = dlg.http_error(&err) {
sleep(d).await;
continue;
}
dlg.finished(false);
return Err(common::Error::HttpError(err));
}
Ok(res) => {
let (mut parts, body) = res.into_parts();
let mut body = common::Body::new(body);
if !parts.status.is_success() {
let bytes = common::to_bytes(body).await.unwrap_or_default();
let error = serde_json::from_str(&common::to_string(&bytes));
let response = common::to_response(parts, bytes.into());
if let common::Retry::After(d) =
dlg.http_failure(&response, error.as_ref().ok())
{
sleep(d).await;
continue;
}
dlg.finished(false);
return Err(match error {
Ok(value) => common::Error::BadRequest(value),
_ => common::Error::Failure(response),
});
}
let response = {
let bytes = common::to_bytes(body).await.unwrap_or_default();
let encoded = common::to_string(&bytes);
match serde_json::from_str(&encoded) {
Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
Err(error) => {
dlg.response_json_decode_error(&encoded, &error);
return Err(common::Error::JsonDecodeError(
encoded.to_string(),
error,
));
}
}
};
dlg.finished(true);
return Ok(response);
}
}
}
}
pub fn api(mut self, new_value: &str) -> ApiGetRestCall<'a, C> {
self._api = new_value.to_string();
self
}
pub fn version(mut self, new_value: &str) -> ApiGetRestCall<'a, C> {
self._version = new_value.to_string();
self
}
pub fn delegate(mut self, new_value: &'a mut dyn common::Delegate) -> ApiGetRestCall<'a, C> {
self._delegate = Some(new_value);
self
}
pub fn param<T>(mut self, name: T, value: T) -> ApiGetRestCall<'a, C>
where
T: AsRef<str>,
{
self._additional_params
.insert(name.as_ref().to_string(), value.as_ref().to_string());
self
}
}
pub struct ApiListCall<'a, C>
where
C: 'a,
{
hub: &'a Discovery<C>,
_preferred: Option<bool>,
_name: Option<String>,
_delegate: Option<&'a mut dyn common::Delegate>,
_additional_params: HashMap<String, String>,
}
impl<'a, C> common::CallBuilder for ApiListCall<'a, C> {}
impl<'a, C> ApiListCall<'a, C>
where
C: common::Connector,
{
pub async fn doit(mut self) -> common::Result<(common::Response, DirectoryList)> {
use std::borrow::Cow;
use std::io::{Read, Seek};
use common::{url::Params, ToParts};
use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
let mut dd = common::DefaultDelegate;
let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
dlg.begin(common::MethodInfo {
id: "discovery.apis.list",
http_method: hyper::Method::GET,
});
for &field in ["alt", "preferred", "name"].iter() {
if self._additional_params.contains_key(field) {
dlg.finished(false);
return Err(common::Error::FieldClash(field));
}
}
let mut params = Params::with_capacity(4 + self._additional_params.len());
if let Some(value) = self._preferred.as_ref() {
params.push("preferred", value.to_string());
}
if let Some(value) = self._name.as_ref() {
params.push("name", value);
}
params.extend(self._additional_params.iter());
params.push("alt", "json");
let mut url = self.hub._base_url.clone() + "apis";
let url = params.parse_with_url(&url);
loop {
let mut req_result = {
let client = &self.hub.client;
dlg.pre_request();
let mut req_builder = hyper::Request::builder()
.method(hyper::Method::GET)
.uri(url.as_str())
.header(USER_AGENT, self.hub._user_agent.clone());
let request = req_builder
.header(CONTENT_LENGTH, 0_u64)
.body(common::to_body::<String>(None));
client.request(request.unwrap()).await
};
match req_result {
Err(err) => {
if let common::Retry::After(d) = dlg.http_error(&err) {
sleep(d).await;
continue;
}
dlg.finished(false);
return Err(common::Error::HttpError(err));
}
Ok(res) => {
let (mut parts, body) = res.into_parts();
let mut body = common::Body::new(body);
if !parts.status.is_success() {
let bytes = common::to_bytes(body).await.unwrap_or_default();
let error = serde_json::from_str(&common::to_string(&bytes));
let response = common::to_response(parts, bytes.into());
if let common::Retry::After(d) =
dlg.http_failure(&response, error.as_ref().ok())
{
sleep(d).await;
continue;
}
dlg.finished(false);
return Err(match error {
Ok(value) => common::Error::BadRequest(value),
_ => common::Error::Failure(response),
});
}
let response = {
let bytes = common::to_bytes(body).await.unwrap_or_default();
let encoded = common::to_string(&bytes);
match serde_json::from_str(&encoded) {
Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
Err(error) => {
dlg.response_json_decode_error(&encoded, &error);
return Err(common::Error::JsonDecodeError(
encoded.to_string(),
error,
));
}
}
};
dlg.finished(true);
return Ok(response);
}
}
}
}
pub fn preferred(mut self, new_value: bool) -> ApiListCall<'a, C> {
self._preferred = Some(new_value);
self
}
pub fn name(mut self, new_value: &str) -> ApiListCall<'a, C> {
self._name = Some(new_value.to_string());
self
}
pub fn delegate(mut self, new_value: &'a mut dyn common::Delegate) -> ApiListCall<'a, C> {
self._delegate = Some(new_value);
self
}
pub fn param<T>(mut self, name: T, value: T) -> ApiListCall<'a, C>
where
T: AsRef<str>,
{
self._additional_params
.insert(name.as_ref().to_string(), value.as_ref().to_string());
self
}
}