google_webmasters3/
api.rs

1#![allow(clippy::ptr_arg)]
2
3use std::collections::{BTreeSet, HashMap};
4
5use tokio::time::sleep;
6
7// ##############
8// UTILITIES ###
9// ############
10
11/// Identifies the an OAuth2 authorization scope.
12/// A scope is needed when requesting an
13/// [authorization token](https://developers.google.com/youtube/v3/guides/authentication).
14#[derive(PartialEq, Eq, Ord, PartialOrd, Hash, Debug, Clone, Copy)]
15pub enum Scope {
16    /// View and manage Search Console data for your verified sites
17    Full,
18
19    /// View Search Console data for your verified sites
20    Readonly,
21}
22
23impl AsRef<str> for Scope {
24    fn as_ref(&self) -> &str {
25        match *self {
26            Scope::Full => "https://www.googleapis.com/auth/webmasters",
27            Scope::Readonly => "https://www.googleapis.com/auth/webmasters.readonly",
28        }
29    }
30}
31
32#[allow(clippy::derivable_impls)]
33impl Default for Scope {
34    fn default() -> Scope {
35        Scope::Readonly
36    }
37}
38
39// ########
40// HUB ###
41// ######
42
43/// Central instance to access all Webmasters related resource activities
44///
45/// # Examples
46///
47/// Instantiate a new hub
48///
49/// ```test_harness,no_run
50/// extern crate hyper;
51/// extern crate hyper_rustls;
52/// extern crate google_webmasters3 as webmasters3;
53/// use webmasters3::api::SearchAnalyticsQueryRequest;
54/// use webmasters3::{Result, Error};
55/// # async fn dox() {
56/// use webmasters3::{Webmasters, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
57///
58/// // Get an ApplicationSecret instance by some means. It contains the `client_id` and
59/// // `client_secret`, among other things.
60/// let secret: yup_oauth2::ApplicationSecret = Default::default();
61/// // Instantiate the authenticator. It will choose a suitable authentication flow for you,
62/// // unless you replace  `None` with the desired Flow.
63/// // Provide your own `AuthenticatorDelegate` to adjust the way it operates and get feedback about
64/// // what's going on. You probably want to bring in your own `TokenStorage` to persist tokens and
65/// // retrieve them from storage.
66/// let connector = hyper_rustls::HttpsConnectorBuilder::new()
67///     .with_native_roots()
68///     .unwrap()
69///     .https_only()
70///     .enable_http2()
71///     .build();
72///
73/// let executor = hyper_util::rt::TokioExecutor::new();
74/// let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
75///     secret,
76///     yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
77///     yup_oauth2::client::CustomHyperClientBuilder::from(
78///         hyper_util::client::legacy::Client::builder(executor).build(connector),
79///     ),
80/// ).build().await.unwrap();
81///
82/// let client = hyper_util::client::legacy::Client::builder(
83///     hyper_util::rt::TokioExecutor::new()
84/// )
85/// .build(
86///     hyper_rustls::HttpsConnectorBuilder::new()
87///         .with_native_roots()
88///         .unwrap()
89///         .https_or_http()
90///         .enable_http2()
91///         .build()
92/// );
93/// let mut hub = Webmasters::new(client, auth);
94/// // As the method needs a request, you would usually fill it with the desired information
95/// // into the respective structure. Some of the parts shown here might not be applicable !
96/// // Values shown here are possibly random and not representative !
97/// let mut req = SearchAnalyticsQueryRequest::default();
98///
99/// // You can configure optional parameters by calling the respective setters at will, and
100/// // execute the final call using `doit()`.
101/// // Values shown here are possibly random and not representative !
102/// let result = hub.searchanalytics().query(req, "siteUrl")
103///              .doit().await;
104///
105/// match result {
106///     Err(e) => match e {
107///         // The Error enum provides details about what exactly happened.
108///         // You can also just use its `Debug`, `Display` or `Error` traits
109///          Error::HttpError(_)
110///         |Error::Io(_)
111///         |Error::MissingAPIKey
112///         |Error::MissingToken(_)
113///         |Error::Cancelled
114///         |Error::UploadSizeLimitExceeded(_, _)
115///         |Error::Failure(_)
116///         |Error::BadRequest(_)
117///         |Error::FieldClash(_)
118///         |Error::JsonDecodeError(_, _) => println!("{}", e),
119///     },
120///     Ok(res) => println!("Success: {:?}", res),
121/// }
122/// # }
123/// ```
124#[derive(Clone)]
125pub struct Webmasters<C> {
126    pub client: common::Client<C>,
127    pub auth: Box<dyn common::GetToken>,
128    _user_agent: String,
129    _base_url: String,
130    _root_url: String,
131}
132
133impl<C> common::Hub for Webmasters<C> {}
134
135impl<'a, C> Webmasters<C> {
136    pub fn new<A: 'static + common::GetToken>(client: common::Client<C>, auth: A) -> Webmasters<C> {
137        Webmasters {
138            client,
139            auth: Box::new(auth),
140            _user_agent: "google-api-rust-client/7.0.0".to_string(),
141            _base_url: "https://www.googleapis.com/webmasters/v3/".to_string(),
142            _root_url: "https://www.googleapis.com/".to_string(),
143        }
144    }
145
146    pub fn searchanalytics(&'a self) -> SearchanalyticMethods<'a, C> {
147        SearchanalyticMethods { hub: self }
148    }
149    pub fn sitemaps(&'a self) -> SitemapMethods<'a, C> {
150        SitemapMethods { hub: self }
151    }
152    pub fn sites(&'a self) -> SiteMethods<'a, C> {
153        SiteMethods { hub: self }
154    }
155
156    /// Set the user-agent header field to use in all requests to the server.
157    /// It defaults to `google-api-rust-client/7.0.0`.
158    ///
159    /// Returns the previously set user-agent.
160    pub fn user_agent(&mut self, agent_name: String) -> String {
161        std::mem::replace(&mut self._user_agent, agent_name)
162    }
163
164    /// Set the base url to use in all requests to the server.
165    /// It defaults to `https://www.googleapis.com/webmasters/v3/`.
166    ///
167    /// Returns the previously set base url.
168    pub fn base_url(&mut self, new_base_url: String) -> String {
169        std::mem::replace(&mut self._base_url, new_base_url)
170    }
171
172    /// Set the root url to use in all requests to the server.
173    /// It defaults to `https://www.googleapis.com/`.
174    ///
175    /// Returns the previously set root url.
176    pub fn root_url(&mut self, new_root_url: String) -> String {
177        std::mem::replace(&mut self._root_url, new_root_url)
178    }
179}
180
181// ############
182// SCHEMAS ###
183// ##########
184/// There is no detailed description.
185///
186/// This type is not used in any activity, and only used as *part* of another schema.
187///
188#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
189#[serde_with::serde_as]
190#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
191pub struct ApiDataRow {
192    /// no description provided
193    pub clicks: Option<f64>,
194    /// no description provided
195    pub ctr: Option<f64>,
196    /// no description provided
197    pub impressions: Option<f64>,
198    /// no description provided
199    pub keys: Option<Vec<String>>,
200    /// no description provided
201    pub position: Option<f64>,
202}
203
204impl common::Part for ApiDataRow {}
205
206/// There is no detailed description.
207///
208/// This type is not used in any activity, and only used as *part* of another schema.
209///
210#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
211#[serde_with::serde_as]
212#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
213pub struct ApiDimensionFilter {
214    /// no description provided
215    pub dimension: Option<String>,
216    /// no description provided
217    pub expression: Option<String>,
218    /// no description provided
219    pub operator: Option<String>,
220}
221
222impl common::Part for ApiDimensionFilter {}
223
224/// There is no detailed description.
225///
226/// This type is not used in any activity, and only used as *part* of another schema.
227///
228#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
229#[serde_with::serde_as]
230#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
231pub struct ApiDimensionFilterGroup {
232    /// no description provided
233    pub filters: Option<Vec<ApiDimensionFilter>>,
234    /// no description provided
235    #[serde(rename = "groupType")]
236    pub group_type: Option<String>,
237}
238
239impl common::Part for ApiDimensionFilterGroup {}
240
241/// There is no detailed description.
242///
243/// # Activities
244///
245/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
246/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
247///
248/// * [query searchanalytics](SearchanalyticQueryCall) (request)
249#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
250#[serde_with::serde_as]
251#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
252pub struct SearchAnalyticsQueryRequest {
253    /// [Optional; Default is "auto"] How data is aggregated. If aggregated by property, all data for the same property is aggregated; if aggregated by page, all data is aggregated by canonical URI. If you filter or group by page, choose AUTO; otherwise you can aggregate either by property or by page, depending on how you want your data calculated; see  the help documentation to learn how data is calculated differently by site versus by page.
254    ///
255    /// Note: If you group or filter by page, you cannot aggregate by property.
256    ///
257    /// If you specify any value other than AUTO, the aggregation type in the result will match the requested type, or if you request an invalid type, you will get an error. The API will never change your aggregation type if the requested type is invalid.
258    #[serde(rename = "aggregationType")]
259    pub aggregation_type: Option<String>,
260    /// [Optional] If "all" (case-insensitive), data will include fresh data. If "final" (case-insensitive) or if this parameter is omitted, the returned data will include only finalized data.
261    #[serde(rename = "dataState")]
262    pub data_state: Option<String>,
263    /// [Optional] Zero or more filters to apply to the dimension grouping values; for example, 'query contains "buy"' to see only data where the query string contains the substring "buy" (not case-sensitive). You can filter by a dimension without grouping by it.
264    #[serde(rename = "dimensionFilterGroups")]
265    pub dimension_filter_groups: Option<Vec<ApiDimensionFilterGroup>>,
266    /// [Optional] Zero or more dimensions to group results by. Dimensions are the group-by values in the Search Analytics page. Dimensions are combined to create a unique row key for each row. Results are grouped in the order that you supply these dimensions.
267    pub dimensions: Option<Vec<String>>,
268    /// [Required] End date of the requested date range, in YYYY-MM-DD format, in PST (UTC - 8:00). Must be greater than or equal to the start date. This value is included in the range.
269    #[serde(rename = "endDate")]
270    pub end_date: Option<String>,
271    /// [Optional; Default is 1000] The maximum number of rows to return. Must be a number from 1 to 5,000 (inclusive).
272    #[serde(rename = "rowLimit")]
273    pub row_limit: Option<i32>,
274    /// [Optional; Default is "web"] The search type to filter for.
275    #[serde(rename = "searchType")]
276    pub search_type: Option<String>,
277    /// [Required] Start date of the requested date range, in YYYY-MM-DD format, in PST time (UTC - 8:00). Must be less than or equal to the end date. This value is included in the range.
278    #[serde(rename = "startDate")]
279    pub start_date: Option<String>,
280    /// [Optional; Default is 0] Zero-based index of the first row in the response. Must be a non-negative number.
281    #[serde(rename = "startRow")]
282    pub start_row: Option<i32>,
283}
284
285impl common::RequestValue for SearchAnalyticsQueryRequest {}
286
287/// A list of rows, one per result, grouped by key. Metrics in each row are aggregated for all data grouped by that key either by page or property, as specified by the aggregation type parameter.
288///
289/// # Activities
290///
291/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
292/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
293///
294/// * [query searchanalytics](SearchanalyticQueryCall) (response)
295#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
296#[serde_with::serde_as]
297#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
298pub struct SearchAnalyticsQueryResponse {
299    /// How the results were aggregated.
300    #[serde(rename = "responseAggregationType")]
301    pub response_aggregation_type: Option<String>,
302    /// A list of rows grouped by the key values in the order given in the query.
303    pub rows: Option<Vec<ApiDataRow>>,
304}
305
306impl common::ResponseResult for SearchAnalyticsQueryResponse {}
307
308/// List of sitemaps.
309///
310/// # Activities
311///
312/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
313/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
314///
315/// * [list sitemaps](SitemapListCall) (response)
316#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
317#[serde_with::serde_as]
318#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
319pub struct SitemapsListResponse {
320    /// Contains detailed information about a specific URL submitted as a sitemap.
321    pub sitemap: Option<Vec<WmxSitemap>>,
322}
323
324impl common::ResponseResult for SitemapsListResponse {}
325
326/// List of sites with access level information.
327///
328/// # Activities
329///
330/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
331/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
332///
333/// * [list sites](SiteListCall) (response)
334#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
335#[serde_with::serde_as]
336#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
337pub struct SitesListResponse {
338    /// Contains permission level information about a Search Console site. For more information, see Permissions in Search Console.
339    #[serde(rename = "siteEntry")]
340    pub site_entry: Option<Vec<WmxSite>>,
341}
342
343impl common::ResponseResult for SitesListResponse {}
344
345/// Contains permission level information about a Search Console site. For more information, see  Permissions in Search Console.
346///
347/// # Activities
348///
349/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
350/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
351///
352/// * [get sites](SiteGetCall) (response)
353#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
354#[serde_with::serde_as]
355#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
356pub struct WmxSite {
357    /// The user's permission level for the site.
358    #[serde(rename = "permissionLevel")]
359    pub permission_level: Option<String>,
360    /// The URL of the site.
361    #[serde(rename = "siteUrl")]
362    pub site_url: Option<String>,
363}
364
365impl common::ResponseResult for WmxSite {}
366
367/// Contains detailed information about a specific URL submitted as a sitemap.
368///
369/// # Activities
370///
371/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
372/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
373///
374/// * [get sitemaps](SitemapGetCall) (response)
375#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
376#[serde_with::serde_as]
377#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
378pub struct WmxSitemap {
379    /// The various content types in the sitemap.
380    pub contents: Option<Vec<WmxSitemapContent>>,
381    /// Number of errors in the sitemap. These are issues with the sitemap itself that need to be fixed before it can be processed correctly.
382    #[serde_as(as = "Option<serde_with::DisplayFromStr>")]
383    pub errors: Option<i64>,
384    /// If true, the sitemap has not been processed.
385    #[serde(rename = "isPending")]
386    pub is_pending: Option<bool>,
387    /// If true, the sitemap is a collection of sitemaps.
388    #[serde(rename = "isSitemapsIndex")]
389    pub is_sitemaps_index: Option<bool>,
390    /// Date & time in which this sitemap was last downloaded. Date format is in RFC 3339 format (yyyy-mm-dd).
391    #[serde(rename = "lastDownloaded")]
392    pub last_downloaded: Option<chrono::DateTime<chrono::offset::Utc>>,
393    /// Date & time in which this sitemap was submitted. Date format is in RFC 3339 format (yyyy-mm-dd).
394    #[serde(rename = "lastSubmitted")]
395    pub last_submitted: Option<chrono::DateTime<chrono::offset::Utc>>,
396    /// The url of the sitemap.
397    pub path: Option<String>,
398    /// The type of the sitemap. For example: rssFeed.
399    #[serde(rename = "type")]
400    pub type_: Option<String>,
401    /// Number of warnings for the sitemap. These are generally non-critical issues with URLs in the sitemaps.
402    #[serde_as(as = "Option<serde_with::DisplayFromStr>")]
403    pub warnings: Option<i64>,
404}
405
406impl common::ResponseResult for WmxSitemap {}
407
408/// Information about the various content types in the sitemap.
409///
410/// This type is not used in any activity, and only used as *part* of another schema.
411///
412#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
413#[serde_with::serde_as]
414#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
415pub struct WmxSitemapContent {
416    /// The number of URLs from the sitemap that were indexed (of the content type).
417    #[serde_as(as = "Option<serde_with::DisplayFromStr>")]
418    pub indexed: Option<i64>,
419    /// The number of URLs in the sitemap (of the content type).
420    #[serde_as(as = "Option<serde_with::DisplayFromStr>")]
421    pub submitted: Option<i64>,
422    /// The specific type of content in this sitemap. For example: web.
423    #[serde(rename = "type")]
424    pub type_: Option<String>,
425}
426
427impl common::Part for WmxSitemapContent {}
428
429// ###################
430// MethodBuilders ###
431// #################
432
433/// A builder providing access to all methods supported on *searchanalytic* resources.
434/// It is not used directly, but through the [`Webmasters`] hub.
435///
436/// # Example
437///
438/// Instantiate a resource builder
439///
440/// ```test_harness,no_run
441/// extern crate hyper;
442/// extern crate hyper_rustls;
443/// extern crate google_webmasters3 as webmasters3;
444///
445/// # async fn dox() {
446/// use webmasters3::{Webmasters, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
447///
448/// let secret: yup_oauth2::ApplicationSecret = Default::default();
449/// let connector = hyper_rustls::HttpsConnectorBuilder::new()
450///     .with_native_roots()
451///     .unwrap()
452///     .https_only()
453///     .enable_http2()
454///     .build();
455///
456/// let executor = hyper_util::rt::TokioExecutor::new();
457/// let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
458///     secret,
459///     yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
460///     yup_oauth2::client::CustomHyperClientBuilder::from(
461///         hyper_util::client::legacy::Client::builder(executor).build(connector),
462///     ),
463/// ).build().await.unwrap();
464///
465/// let client = hyper_util::client::legacy::Client::builder(
466///     hyper_util::rt::TokioExecutor::new()
467/// )
468/// .build(
469///     hyper_rustls::HttpsConnectorBuilder::new()
470///         .with_native_roots()
471///         .unwrap()
472///         .https_or_http()
473///         .enable_http2()
474///         .build()
475/// );
476/// let mut hub = Webmasters::new(client, auth);
477/// // Usually you wouldn't bind this to a variable, but keep calling *CallBuilders*
478/// // like `query(...)`
479/// // to build up your call.
480/// let rb = hub.searchanalytics();
481/// # }
482/// ```
483pub struct SearchanalyticMethods<'a, C>
484where
485    C: 'a,
486{
487    hub: &'a Webmasters<C>,
488}
489
490impl<'a, C> common::MethodsBuilder for SearchanalyticMethods<'a, C> {}
491
492impl<'a, C> SearchanalyticMethods<'a, C> {
493    /// Create a builder to help you perform the following task:
494    ///
495    /// Query your data with filters and parameters that you define. Returns zero or more rows grouped by the row keys that you define. You must define a date range of one or more days.
496    ///
497    /// When date is one of the group by values, any days without data are omitted from the result list. If you need to know which days have data, issue a broad date range query grouped by date for any metric, and see which day rows are returned.
498    ///
499    /// # Arguments
500    ///
501    /// * `request` - No description provided.
502    /// * `siteUrl` - The site's URL, including protocol. For example: http://www.example.com/
503    pub fn query(
504        &self,
505        request: SearchAnalyticsQueryRequest,
506        site_url: &str,
507    ) -> SearchanalyticQueryCall<'a, C> {
508        SearchanalyticQueryCall {
509            hub: self.hub,
510            _request: request,
511            _site_url: site_url.to_string(),
512            _delegate: Default::default(),
513            _additional_params: Default::default(),
514            _scopes: Default::default(),
515        }
516    }
517}
518
519/// A builder providing access to all methods supported on *sitemap* resources.
520/// It is not used directly, but through the [`Webmasters`] hub.
521///
522/// # Example
523///
524/// Instantiate a resource builder
525///
526/// ```test_harness,no_run
527/// extern crate hyper;
528/// extern crate hyper_rustls;
529/// extern crate google_webmasters3 as webmasters3;
530///
531/// # async fn dox() {
532/// use webmasters3::{Webmasters, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
533///
534/// let secret: yup_oauth2::ApplicationSecret = Default::default();
535/// let connector = hyper_rustls::HttpsConnectorBuilder::new()
536///     .with_native_roots()
537///     .unwrap()
538///     .https_only()
539///     .enable_http2()
540///     .build();
541///
542/// let executor = hyper_util::rt::TokioExecutor::new();
543/// let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
544///     secret,
545///     yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
546///     yup_oauth2::client::CustomHyperClientBuilder::from(
547///         hyper_util::client::legacy::Client::builder(executor).build(connector),
548///     ),
549/// ).build().await.unwrap();
550///
551/// let client = hyper_util::client::legacy::Client::builder(
552///     hyper_util::rt::TokioExecutor::new()
553/// )
554/// .build(
555///     hyper_rustls::HttpsConnectorBuilder::new()
556///         .with_native_roots()
557///         .unwrap()
558///         .https_or_http()
559///         .enable_http2()
560///         .build()
561/// );
562/// let mut hub = Webmasters::new(client, auth);
563/// // Usually you wouldn't bind this to a variable, but keep calling *CallBuilders*
564/// // like `delete(...)`, `get(...)`, `list(...)` and `submit(...)`
565/// // to build up your call.
566/// let rb = hub.sitemaps();
567/// # }
568/// ```
569pub struct SitemapMethods<'a, C>
570where
571    C: 'a,
572{
573    hub: &'a Webmasters<C>,
574}
575
576impl<'a, C> common::MethodsBuilder for SitemapMethods<'a, C> {}
577
578impl<'a, C> SitemapMethods<'a, C> {
579    /// Create a builder to help you perform the following task:
580    ///
581    /// Deletes a sitemap from this site.
582    ///
583    /// # Arguments
584    ///
585    /// * `siteUrl` - The site's URL, including protocol. For example: http://www.example.com/
586    /// * `feedpath` - The URL of the actual sitemap. For example: http://www.example.com/sitemap.xml
587    pub fn delete(&self, site_url: &str, feedpath: &str) -> SitemapDeleteCall<'a, C> {
588        SitemapDeleteCall {
589            hub: self.hub,
590            _site_url: site_url.to_string(),
591            _feedpath: feedpath.to_string(),
592            _delegate: Default::default(),
593            _additional_params: Default::default(),
594            _scopes: Default::default(),
595        }
596    }
597
598    /// Create a builder to help you perform the following task:
599    ///
600    /// Retrieves information about a specific sitemap.
601    ///
602    /// # Arguments
603    ///
604    /// * `siteUrl` - The site's URL, including protocol. For example: http://www.example.com/
605    /// * `feedpath` - The URL of the actual sitemap. For example: http://www.example.com/sitemap.xml
606    pub fn get(&self, site_url: &str, feedpath: &str) -> SitemapGetCall<'a, C> {
607        SitemapGetCall {
608            hub: self.hub,
609            _site_url: site_url.to_string(),
610            _feedpath: feedpath.to_string(),
611            _delegate: Default::default(),
612            _additional_params: Default::default(),
613            _scopes: Default::default(),
614        }
615    }
616
617    /// Create a builder to help you perform the following task:
618    ///
619    /// Lists the sitemaps-entries submitted for this site, or included in the sitemap index file (if sitemapIndex is specified in the request).
620    ///
621    /// # Arguments
622    ///
623    /// * `siteUrl` - The site's URL, including protocol. For example: http://www.example.com/
624    pub fn list(&self, site_url: &str) -> SitemapListCall<'a, C> {
625        SitemapListCall {
626            hub: self.hub,
627            _site_url: site_url.to_string(),
628            _sitemap_index: Default::default(),
629            _delegate: Default::default(),
630            _additional_params: Default::default(),
631            _scopes: Default::default(),
632        }
633    }
634
635    /// Create a builder to help you perform the following task:
636    ///
637    /// Submits a sitemap for a site.
638    ///
639    /// # Arguments
640    ///
641    /// * `siteUrl` - The site's URL, including protocol. For example: http://www.example.com/
642    /// * `feedpath` - The URL of the sitemap to add. For example: http://www.example.com/sitemap.xml
643    pub fn submit(&self, site_url: &str, feedpath: &str) -> SitemapSubmitCall<'a, C> {
644        SitemapSubmitCall {
645            hub: self.hub,
646            _site_url: site_url.to_string(),
647            _feedpath: feedpath.to_string(),
648            _delegate: Default::default(),
649            _additional_params: Default::default(),
650            _scopes: Default::default(),
651        }
652    }
653}
654
655/// A builder providing access to all methods supported on *site* resources.
656/// It is not used directly, but through the [`Webmasters`] hub.
657///
658/// # Example
659///
660/// Instantiate a resource builder
661///
662/// ```test_harness,no_run
663/// extern crate hyper;
664/// extern crate hyper_rustls;
665/// extern crate google_webmasters3 as webmasters3;
666///
667/// # async fn dox() {
668/// use webmasters3::{Webmasters, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
669///
670/// let secret: yup_oauth2::ApplicationSecret = Default::default();
671/// let connector = hyper_rustls::HttpsConnectorBuilder::new()
672///     .with_native_roots()
673///     .unwrap()
674///     .https_only()
675///     .enable_http2()
676///     .build();
677///
678/// let executor = hyper_util::rt::TokioExecutor::new();
679/// let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
680///     secret,
681///     yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
682///     yup_oauth2::client::CustomHyperClientBuilder::from(
683///         hyper_util::client::legacy::Client::builder(executor).build(connector),
684///     ),
685/// ).build().await.unwrap();
686///
687/// let client = hyper_util::client::legacy::Client::builder(
688///     hyper_util::rt::TokioExecutor::new()
689/// )
690/// .build(
691///     hyper_rustls::HttpsConnectorBuilder::new()
692///         .with_native_roots()
693///         .unwrap()
694///         .https_or_http()
695///         .enable_http2()
696///         .build()
697/// );
698/// let mut hub = Webmasters::new(client, auth);
699/// // Usually you wouldn't bind this to a variable, but keep calling *CallBuilders*
700/// // like `add(...)`, `delete(...)`, `get(...)` and `list(...)`
701/// // to build up your call.
702/// let rb = hub.sites();
703/// # }
704/// ```
705pub struct SiteMethods<'a, C>
706where
707    C: 'a,
708{
709    hub: &'a Webmasters<C>,
710}
711
712impl<'a, C> common::MethodsBuilder for SiteMethods<'a, C> {}
713
714impl<'a, C> SiteMethods<'a, C> {
715    /// Create a builder to help you perform the following task:
716    ///
717    /// Adds a site to the set of the user's sites in Search Console.
718    ///
719    /// # Arguments
720    ///
721    /// * `siteUrl` - The URL of the site to add.
722    pub fn add(&self, site_url: &str) -> SiteAddCall<'a, C> {
723        SiteAddCall {
724            hub: self.hub,
725            _site_url: site_url.to_string(),
726            _delegate: Default::default(),
727            _additional_params: Default::default(),
728            _scopes: Default::default(),
729        }
730    }
731
732    /// Create a builder to help you perform the following task:
733    ///
734    /// Removes a site from the set of the user's Search Console sites.
735    ///
736    /// # Arguments
737    ///
738    /// * `siteUrl` - The URI of the property as defined in Search Console. Examples: http://www.example.com/ or android-app://com.example/ Note: for property-sets, use the URI that starts with sc-set: which is used in Search Console URLs.
739    pub fn delete(&self, site_url: &str) -> SiteDeleteCall<'a, C> {
740        SiteDeleteCall {
741            hub: self.hub,
742            _site_url: site_url.to_string(),
743            _delegate: Default::default(),
744            _additional_params: Default::default(),
745            _scopes: Default::default(),
746        }
747    }
748
749    /// Create a builder to help you perform the following task:
750    ///
751    /// Retrieves information about specific site.
752    ///
753    /// # Arguments
754    ///
755    /// * `siteUrl` - The URI of the property as defined in Search Console. Examples: http://www.example.com/ or android-app://com.example/ Note: for property-sets, use the URI that starts with sc-set: which is used in Search Console URLs.
756    pub fn get(&self, site_url: &str) -> SiteGetCall<'a, C> {
757        SiteGetCall {
758            hub: self.hub,
759            _site_url: site_url.to_string(),
760            _delegate: Default::default(),
761            _additional_params: Default::default(),
762            _scopes: Default::default(),
763        }
764    }
765
766    /// Create a builder to help you perform the following task:
767    ///
768    /// Lists the user's Search Console sites.
769    pub fn list(&self) -> SiteListCall<'a, C> {
770        SiteListCall {
771            hub: self.hub,
772            _delegate: Default::default(),
773            _additional_params: Default::default(),
774            _scopes: Default::default(),
775        }
776    }
777}
778
779// ###################
780// CallBuilders   ###
781// #################
782
783/// Query your data with filters and parameters that you define. Returns zero or more rows grouped by the row keys that you define. You must define a date range of one or more days.
784///
785/// When date is one of the group by values, any days without data are omitted from the result list. If you need to know which days have data, issue a broad date range query grouped by date for any metric, and see which day rows are returned.
786///
787/// A builder for the *query* method supported by a *searchanalytic* resource.
788/// It is not used directly, but through a [`SearchanalyticMethods`] instance.
789///
790/// # Example
791///
792/// Instantiate a resource method builder
793///
794/// ```test_harness,no_run
795/// # extern crate hyper;
796/// # extern crate hyper_rustls;
797/// # extern crate google_webmasters3 as webmasters3;
798/// use webmasters3::api::SearchAnalyticsQueryRequest;
799/// # async fn dox() {
800/// # use webmasters3::{Webmasters, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
801///
802/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
803/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
804/// #     .with_native_roots()
805/// #     .unwrap()
806/// #     .https_only()
807/// #     .enable_http2()
808/// #     .build();
809///
810/// # let executor = hyper_util::rt::TokioExecutor::new();
811/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
812/// #     secret,
813/// #     yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
814/// #     yup_oauth2::client::CustomHyperClientBuilder::from(
815/// #         hyper_util::client::legacy::Client::builder(executor).build(connector),
816/// #     ),
817/// # ).build().await.unwrap();
818///
819/// # let client = hyper_util::client::legacy::Client::builder(
820/// #     hyper_util::rt::TokioExecutor::new()
821/// # )
822/// # .build(
823/// #     hyper_rustls::HttpsConnectorBuilder::new()
824/// #         .with_native_roots()
825/// #         .unwrap()
826/// #         .https_or_http()
827/// #         .enable_http2()
828/// #         .build()
829/// # );
830/// # let mut hub = Webmasters::new(client, auth);
831/// // As the method needs a request, you would usually fill it with the desired information
832/// // into the respective structure. Some of the parts shown here might not be applicable !
833/// // Values shown here are possibly random and not representative !
834/// let mut req = SearchAnalyticsQueryRequest::default();
835///
836/// // You can configure optional parameters by calling the respective setters at will, and
837/// // execute the final call using `doit()`.
838/// // Values shown here are possibly random and not representative !
839/// let result = hub.searchanalytics().query(req, "siteUrl")
840///              .doit().await;
841/// # }
842/// ```
843pub struct SearchanalyticQueryCall<'a, C>
844where
845    C: 'a,
846{
847    hub: &'a Webmasters<C>,
848    _request: SearchAnalyticsQueryRequest,
849    _site_url: String,
850    _delegate: Option<&'a mut dyn common::Delegate>,
851    _additional_params: HashMap<String, String>,
852    _scopes: BTreeSet<String>,
853}
854
855impl<'a, C> common::CallBuilder for SearchanalyticQueryCall<'a, C> {}
856
857impl<'a, C> SearchanalyticQueryCall<'a, C>
858where
859    C: common::Connector,
860{
861    /// Perform the operation you have build so far.
862    pub async fn doit(
863        mut self,
864    ) -> common::Result<(common::Response, SearchAnalyticsQueryResponse)> {
865        use std::borrow::Cow;
866        use std::io::{Read, Seek};
867
868        use common::{url::Params, ToParts};
869        use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
870
871        let mut dd = common::DefaultDelegate;
872        let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
873        dlg.begin(common::MethodInfo {
874            id: "webmasters.searchanalytics.query",
875            http_method: hyper::Method::POST,
876        });
877
878        for &field in ["alt", "siteUrl"].iter() {
879            if self._additional_params.contains_key(field) {
880                dlg.finished(false);
881                return Err(common::Error::FieldClash(field));
882            }
883        }
884
885        let mut params = Params::with_capacity(4 + self._additional_params.len());
886        params.push("siteUrl", self._site_url);
887
888        params.extend(self._additional_params.iter());
889
890        params.push("alt", "json");
891        let mut url = self.hub._base_url.clone() + "sites/{siteUrl}/searchAnalytics/query";
892        if self._scopes.is_empty() {
893            self._scopes.insert(Scope::Readonly.as_ref().to_string());
894        }
895
896        #[allow(clippy::single_element_loop)]
897        for &(find_this, param_name) in [("{siteUrl}", "siteUrl")].iter() {
898            url = params.uri_replacement(url, param_name, find_this, false);
899        }
900        {
901            let to_remove = ["siteUrl"];
902            params.remove_params(&to_remove);
903        }
904
905        let url = params.parse_with_url(&url);
906
907        let mut json_mime_type = mime::APPLICATION_JSON;
908        let mut request_value_reader = {
909            let mut value = serde_json::value::to_value(&self._request).expect("serde to work");
910            common::remove_json_null_values(&mut value);
911            let mut dst = std::io::Cursor::new(Vec::with_capacity(128));
912            serde_json::to_writer(&mut dst, &value).unwrap();
913            dst
914        };
915        let request_size = request_value_reader
916            .seek(std::io::SeekFrom::End(0))
917            .unwrap();
918        request_value_reader
919            .seek(std::io::SeekFrom::Start(0))
920            .unwrap();
921
922        loop {
923            let token = match self
924                .hub
925                .auth
926                .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
927                .await
928            {
929                Ok(token) => token,
930                Err(e) => match dlg.token(e) {
931                    Ok(token) => token,
932                    Err(e) => {
933                        dlg.finished(false);
934                        return Err(common::Error::MissingToken(e));
935                    }
936                },
937            };
938            request_value_reader
939                .seek(std::io::SeekFrom::Start(0))
940                .unwrap();
941            let mut req_result = {
942                let client = &self.hub.client;
943                dlg.pre_request();
944                let mut req_builder = hyper::Request::builder()
945                    .method(hyper::Method::POST)
946                    .uri(url.as_str())
947                    .header(USER_AGENT, self.hub._user_agent.clone());
948
949                if let Some(token) = token.as_ref() {
950                    req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
951                }
952
953                let request = req_builder
954                    .header(CONTENT_TYPE, json_mime_type.to_string())
955                    .header(CONTENT_LENGTH, request_size as u64)
956                    .body(common::to_body(
957                        request_value_reader.get_ref().clone().into(),
958                    ));
959
960                client.request(request.unwrap()).await
961            };
962
963            match req_result {
964                Err(err) => {
965                    if let common::Retry::After(d) = dlg.http_error(&err) {
966                        sleep(d).await;
967                        continue;
968                    }
969                    dlg.finished(false);
970                    return Err(common::Error::HttpError(err));
971                }
972                Ok(res) => {
973                    let (mut parts, body) = res.into_parts();
974                    let mut body = common::Body::new(body);
975                    if !parts.status.is_success() {
976                        let bytes = common::to_bytes(body).await.unwrap_or_default();
977                        let error = serde_json::from_str(&common::to_string(&bytes));
978                        let response = common::to_response(parts, bytes.into());
979
980                        if let common::Retry::After(d) =
981                            dlg.http_failure(&response, error.as_ref().ok())
982                        {
983                            sleep(d).await;
984                            continue;
985                        }
986
987                        dlg.finished(false);
988
989                        return Err(match error {
990                            Ok(value) => common::Error::BadRequest(value),
991                            _ => common::Error::Failure(response),
992                        });
993                    }
994                    let response = {
995                        let bytes = common::to_bytes(body).await.unwrap_or_default();
996                        let encoded = common::to_string(&bytes);
997                        match serde_json::from_str(&encoded) {
998                            Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
999                            Err(error) => {
1000                                dlg.response_json_decode_error(&encoded, &error);
1001                                return Err(common::Error::JsonDecodeError(
1002                                    encoded.to_string(),
1003                                    error,
1004                                ));
1005                            }
1006                        }
1007                    };
1008
1009                    dlg.finished(true);
1010                    return Ok(response);
1011                }
1012            }
1013        }
1014    }
1015
1016    ///
1017    /// Sets the *request* property to the given value.
1018    ///
1019    /// Even though the property as already been set when instantiating this call,
1020    /// we provide this method for API completeness.
1021    pub fn request(
1022        mut self,
1023        new_value: SearchAnalyticsQueryRequest,
1024    ) -> SearchanalyticQueryCall<'a, C> {
1025        self._request = new_value;
1026        self
1027    }
1028    /// The site's URL, including protocol. For example: http://www.example.com/
1029    ///
1030    /// Sets the *site url* path property to the given value.
1031    ///
1032    /// Even though the property as already been set when instantiating this call,
1033    /// we provide this method for API completeness.
1034    pub fn site_url(mut self, new_value: &str) -> SearchanalyticQueryCall<'a, C> {
1035        self._site_url = new_value.to_string();
1036        self
1037    }
1038    /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
1039    /// while executing the actual API request.
1040    ///
1041    /// ````text
1042    ///                   It should be used to handle progress information, and to implement a certain level of resilience.
1043    /// ````
1044    ///
1045    /// Sets the *delegate* property to the given value.
1046    pub fn delegate(
1047        mut self,
1048        new_value: &'a mut dyn common::Delegate,
1049    ) -> SearchanalyticQueryCall<'a, C> {
1050        self._delegate = Some(new_value);
1051        self
1052    }
1053
1054    /// Set any additional parameter of the query string used in the request.
1055    /// It should be used to set parameters which are not yet available through their own
1056    /// setters.
1057    ///
1058    /// Please note that this method must not be used to set any of the known parameters
1059    /// which have their own setter method. If done anyway, the request will fail.
1060    ///
1061    /// # Additional Parameters
1062    ///
1063    /// * *alt* (query-string) - Data format for the response.
1064    /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
1065    /// * *key* (query-string) - API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.
1066    /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
1067    /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
1068    /// * *quotaUser* (query-string) - An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
1069    /// * *userIp* (query-string) - Deprecated. Please use quotaUser instead.
1070    pub fn param<T>(mut self, name: T, value: T) -> SearchanalyticQueryCall<'a, C>
1071    where
1072        T: AsRef<str>,
1073    {
1074        self._additional_params
1075            .insert(name.as_ref().to_string(), value.as_ref().to_string());
1076        self
1077    }
1078
1079    /// Identifies the authorization scope for the method you are building.
1080    ///
1081    /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
1082    /// [`Scope::Readonly`].
1083    ///
1084    /// The `scope` will be added to a set of scopes. This is important as one can maintain access
1085    /// tokens for more than one scope.
1086    ///
1087    /// Usually there is more than one suitable scope to authorize an operation, some of which may
1088    /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
1089    /// sufficient, a read-write scope will do as well.
1090    pub fn add_scope<St>(mut self, scope: St) -> SearchanalyticQueryCall<'a, C>
1091    where
1092        St: AsRef<str>,
1093    {
1094        self._scopes.insert(String::from(scope.as_ref()));
1095        self
1096    }
1097    /// Identifies the authorization scope(s) for the method you are building.
1098    ///
1099    /// See [`Self::add_scope()`] for details.
1100    pub fn add_scopes<I, St>(mut self, scopes: I) -> SearchanalyticQueryCall<'a, C>
1101    where
1102        I: IntoIterator<Item = St>,
1103        St: AsRef<str>,
1104    {
1105        self._scopes
1106            .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
1107        self
1108    }
1109
1110    /// Removes all scopes, and no default scope will be used either.
1111    /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
1112    /// for details).
1113    pub fn clear_scopes(mut self) -> SearchanalyticQueryCall<'a, C> {
1114        self._scopes.clear();
1115        self
1116    }
1117}
1118
1119/// Deletes a sitemap from this site.
1120///
1121/// A builder for the *delete* method supported by a *sitemap* resource.
1122/// It is not used directly, but through a [`SitemapMethods`] instance.
1123///
1124/// # Example
1125///
1126/// Instantiate a resource method builder
1127///
1128/// ```test_harness,no_run
1129/// # extern crate hyper;
1130/// # extern crate hyper_rustls;
1131/// # extern crate google_webmasters3 as webmasters3;
1132/// # async fn dox() {
1133/// # use webmasters3::{Webmasters, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
1134///
1135/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
1136/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
1137/// #     .with_native_roots()
1138/// #     .unwrap()
1139/// #     .https_only()
1140/// #     .enable_http2()
1141/// #     .build();
1142///
1143/// # let executor = hyper_util::rt::TokioExecutor::new();
1144/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
1145/// #     secret,
1146/// #     yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
1147/// #     yup_oauth2::client::CustomHyperClientBuilder::from(
1148/// #         hyper_util::client::legacy::Client::builder(executor).build(connector),
1149/// #     ),
1150/// # ).build().await.unwrap();
1151///
1152/// # let client = hyper_util::client::legacy::Client::builder(
1153/// #     hyper_util::rt::TokioExecutor::new()
1154/// # )
1155/// # .build(
1156/// #     hyper_rustls::HttpsConnectorBuilder::new()
1157/// #         .with_native_roots()
1158/// #         .unwrap()
1159/// #         .https_or_http()
1160/// #         .enable_http2()
1161/// #         .build()
1162/// # );
1163/// # let mut hub = Webmasters::new(client, auth);
1164/// // You can configure optional parameters by calling the respective setters at will, and
1165/// // execute the final call using `doit()`.
1166/// // Values shown here are possibly random and not representative !
1167/// let result = hub.sitemaps().delete("siteUrl", "feedpath")
1168///              .doit().await;
1169/// # }
1170/// ```
1171pub struct SitemapDeleteCall<'a, C>
1172where
1173    C: 'a,
1174{
1175    hub: &'a Webmasters<C>,
1176    _site_url: String,
1177    _feedpath: String,
1178    _delegate: Option<&'a mut dyn common::Delegate>,
1179    _additional_params: HashMap<String, String>,
1180    _scopes: BTreeSet<String>,
1181}
1182
1183impl<'a, C> common::CallBuilder for SitemapDeleteCall<'a, C> {}
1184
1185impl<'a, C> SitemapDeleteCall<'a, C>
1186where
1187    C: common::Connector,
1188{
1189    /// Perform the operation you have build so far.
1190    pub async fn doit(mut self) -> common::Result<common::Response> {
1191        use std::borrow::Cow;
1192        use std::io::{Read, Seek};
1193
1194        use common::{url::Params, ToParts};
1195        use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
1196
1197        let mut dd = common::DefaultDelegate;
1198        let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
1199        dlg.begin(common::MethodInfo {
1200            id: "webmasters.sitemaps.delete",
1201            http_method: hyper::Method::DELETE,
1202        });
1203
1204        for &field in ["siteUrl", "feedpath"].iter() {
1205            if self._additional_params.contains_key(field) {
1206                dlg.finished(false);
1207                return Err(common::Error::FieldClash(field));
1208            }
1209        }
1210
1211        let mut params = Params::with_capacity(3 + self._additional_params.len());
1212        params.push("siteUrl", self._site_url);
1213        params.push("feedpath", self._feedpath);
1214
1215        params.extend(self._additional_params.iter());
1216
1217        let mut url = self.hub._base_url.clone() + "sites/{siteUrl}/sitemaps/{feedpath}";
1218        if self._scopes.is_empty() {
1219            self._scopes.insert(Scope::Full.as_ref().to_string());
1220        }
1221
1222        #[allow(clippy::single_element_loop)]
1223        for &(find_this, param_name) in
1224            [("{siteUrl}", "siteUrl"), ("{feedpath}", "feedpath")].iter()
1225        {
1226            url = params.uri_replacement(url, param_name, find_this, false);
1227        }
1228        {
1229            let to_remove = ["feedpath", "siteUrl"];
1230            params.remove_params(&to_remove);
1231        }
1232
1233        let url = params.parse_with_url(&url);
1234
1235        loop {
1236            let token = match self
1237                .hub
1238                .auth
1239                .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
1240                .await
1241            {
1242                Ok(token) => token,
1243                Err(e) => match dlg.token(e) {
1244                    Ok(token) => token,
1245                    Err(e) => {
1246                        dlg.finished(false);
1247                        return Err(common::Error::MissingToken(e));
1248                    }
1249                },
1250            };
1251            let mut req_result = {
1252                let client = &self.hub.client;
1253                dlg.pre_request();
1254                let mut req_builder = hyper::Request::builder()
1255                    .method(hyper::Method::DELETE)
1256                    .uri(url.as_str())
1257                    .header(USER_AGENT, self.hub._user_agent.clone());
1258
1259                if let Some(token) = token.as_ref() {
1260                    req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
1261                }
1262
1263                let request = req_builder
1264                    .header(CONTENT_LENGTH, 0_u64)
1265                    .body(common::to_body::<String>(None));
1266
1267                client.request(request.unwrap()).await
1268            };
1269
1270            match req_result {
1271                Err(err) => {
1272                    if let common::Retry::After(d) = dlg.http_error(&err) {
1273                        sleep(d).await;
1274                        continue;
1275                    }
1276                    dlg.finished(false);
1277                    return Err(common::Error::HttpError(err));
1278                }
1279                Ok(res) => {
1280                    let (mut parts, body) = res.into_parts();
1281                    let mut body = common::Body::new(body);
1282                    if !parts.status.is_success() {
1283                        let bytes = common::to_bytes(body).await.unwrap_or_default();
1284                        let error = serde_json::from_str(&common::to_string(&bytes));
1285                        let response = common::to_response(parts, bytes.into());
1286
1287                        if let common::Retry::After(d) =
1288                            dlg.http_failure(&response, error.as_ref().ok())
1289                        {
1290                            sleep(d).await;
1291                            continue;
1292                        }
1293
1294                        dlg.finished(false);
1295
1296                        return Err(match error {
1297                            Ok(value) => common::Error::BadRequest(value),
1298                            _ => common::Error::Failure(response),
1299                        });
1300                    }
1301                    let response = common::Response::from_parts(parts, body);
1302
1303                    dlg.finished(true);
1304                    return Ok(response);
1305                }
1306            }
1307        }
1308    }
1309
1310    /// The site's URL, including protocol. For example: http://www.example.com/
1311    ///
1312    /// Sets the *site url* path property to the given value.
1313    ///
1314    /// Even though the property as already been set when instantiating this call,
1315    /// we provide this method for API completeness.
1316    pub fn site_url(mut self, new_value: &str) -> SitemapDeleteCall<'a, C> {
1317        self._site_url = new_value.to_string();
1318        self
1319    }
1320    /// The URL of the actual sitemap. For example: http://www.example.com/sitemap.xml
1321    ///
1322    /// Sets the *feedpath* path property to the given value.
1323    ///
1324    /// Even though the property as already been set when instantiating this call,
1325    /// we provide this method for API completeness.
1326    pub fn feedpath(mut self, new_value: &str) -> SitemapDeleteCall<'a, C> {
1327        self._feedpath = new_value.to_string();
1328        self
1329    }
1330    /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
1331    /// while executing the actual API request.
1332    ///
1333    /// ````text
1334    ///                   It should be used to handle progress information, and to implement a certain level of resilience.
1335    /// ````
1336    ///
1337    /// Sets the *delegate* property to the given value.
1338    pub fn delegate(mut self, new_value: &'a mut dyn common::Delegate) -> SitemapDeleteCall<'a, C> {
1339        self._delegate = Some(new_value);
1340        self
1341    }
1342
1343    /// Set any additional parameter of the query string used in the request.
1344    /// It should be used to set parameters which are not yet available through their own
1345    /// setters.
1346    ///
1347    /// Please note that this method must not be used to set any of the known parameters
1348    /// which have their own setter method. If done anyway, the request will fail.
1349    ///
1350    /// # Additional Parameters
1351    ///
1352    /// * *alt* (query-string) - Data format for the response.
1353    /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
1354    /// * *key* (query-string) - API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.
1355    /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
1356    /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
1357    /// * *quotaUser* (query-string) - An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
1358    /// * *userIp* (query-string) - Deprecated. Please use quotaUser instead.
1359    pub fn param<T>(mut self, name: T, value: T) -> SitemapDeleteCall<'a, C>
1360    where
1361        T: AsRef<str>,
1362    {
1363        self._additional_params
1364            .insert(name.as_ref().to_string(), value.as_ref().to_string());
1365        self
1366    }
1367
1368    /// Identifies the authorization scope for the method you are building.
1369    ///
1370    /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
1371    /// [`Scope::Full`].
1372    ///
1373    /// The `scope` will be added to a set of scopes. This is important as one can maintain access
1374    /// tokens for more than one scope.
1375    ///
1376    /// Usually there is more than one suitable scope to authorize an operation, some of which may
1377    /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
1378    /// sufficient, a read-write scope will do as well.
1379    pub fn add_scope<St>(mut self, scope: St) -> SitemapDeleteCall<'a, C>
1380    where
1381        St: AsRef<str>,
1382    {
1383        self._scopes.insert(String::from(scope.as_ref()));
1384        self
1385    }
1386    /// Identifies the authorization scope(s) for the method you are building.
1387    ///
1388    /// See [`Self::add_scope()`] for details.
1389    pub fn add_scopes<I, St>(mut self, scopes: I) -> SitemapDeleteCall<'a, C>
1390    where
1391        I: IntoIterator<Item = St>,
1392        St: AsRef<str>,
1393    {
1394        self._scopes
1395            .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
1396        self
1397    }
1398
1399    /// Removes all scopes, and no default scope will be used either.
1400    /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
1401    /// for details).
1402    pub fn clear_scopes(mut self) -> SitemapDeleteCall<'a, C> {
1403        self._scopes.clear();
1404        self
1405    }
1406}
1407
1408/// Retrieves information about a specific sitemap.
1409///
1410/// A builder for the *get* method supported by a *sitemap* resource.
1411/// It is not used directly, but through a [`SitemapMethods`] instance.
1412///
1413/// # Example
1414///
1415/// Instantiate a resource method builder
1416///
1417/// ```test_harness,no_run
1418/// # extern crate hyper;
1419/// # extern crate hyper_rustls;
1420/// # extern crate google_webmasters3 as webmasters3;
1421/// # async fn dox() {
1422/// # use webmasters3::{Webmasters, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
1423///
1424/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
1425/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
1426/// #     .with_native_roots()
1427/// #     .unwrap()
1428/// #     .https_only()
1429/// #     .enable_http2()
1430/// #     .build();
1431///
1432/// # let executor = hyper_util::rt::TokioExecutor::new();
1433/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
1434/// #     secret,
1435/// #     yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
1436/// #     yup_oauth2::client::CustomHyperClientBuilder::from(
1437/// #         hyper_util::client::legacy::Client::builder(executor).build(connector),
1438/// #     ),
1439/// # ).build().await.unwrap();
1440///
1441/// # let client = hyper_util::client::legacy::Client::builder(
1442/// #     hyper_util::rt::TokioExecutor::new()
1443/// # )
1444/// # .build(
1445/// #     hyper_rustls::HttpsConnectorBuilder::new()
1446/// #         .with_native_roots()
1447/// #         .unwrap()
1448/// #         .https_or_http()
1449/// #         .enable_http2()
1450/// #         .build()
1451/// # );
1452/// # let mut hub = Webmasters::new(client, auth);
1453/// // You can configure optional parameters by calling the respective setters at will, and
1454/// // execute the final call using `doit()`.
1455/// // Values shown here are possibly random and not representative !
1456/// let result = hub.sitemaps().get("siteUrl", "feedpath")
1457///              .doit().await;
1458/// # }
1459/// ```
1460pub struct SitemapGetCall<'a, C>
1461where
1462    C: 'a,
1463{
1464    hub: &'a Webmasters<C>,
1465    _site_url: String,
1466    _feedpath: String,
1467    _delegate: Option<&'a mut dyn common::Delegate>,
1468    _additional_params: HashMap<String, String>,
1469    _scopes: BTreeSet<String>,
1470}
1471
1472impl<'a, C> common::CallBuilder for SitemapGetCall<'a, C> {}
1473
1474impl<'a, C> SitemapGetCall<'a, C>
1475where
1476    C: common::Connector,
1477{
1478    /// Perform the operation you have build so far.
1479    pub async fn doit(mut self) -> common::Result<(common::Response, WmxSitemap)> {
1480        use std::borrow::Cow;
1481        use std::io::{Read, Seek};
1482
1483        use common::{url::Params, ToParts};
1484        use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
1485
1486        let mut dd = common::DefaultDelegate;
1487        let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
1488        dlg.begin(common::MethodInfo {
1489            id: "webmasters.sitemaps.get",
1490            http_method: hyper::Method::GET,
1491        });
1492
1493        for &field in ["alt", "siteUrl", "feedpath"].iter() {
1494            if self._additional_params.contains_key(field) {
1495                dlg.finished(false);
1496                return Err(common::Error::FieldClash(field));
1497            }
1498        }
1499
1500        let mut params = Params::with_capacity(4 + self._additional_params.len());
1501        params.push("siteUrl", self._site_url);
1502        params.push("feedpath", self._feedpath);
1503
1504        params.extend(self._additional_params.iter());
1505
1506        params.push("alt", "json");
1507        let mut url = self.hub._base_url.clone() + "sites/{siteUrl}/sitemaps/{feedpath}";
1508        if self._scopes.is_empty() {
1509            self._scopes.insert(Scope::Readonly.as_ref().to_string());
1510        }
1511
1512        #[allow(clippy::single_element_loop)]
1513        for &(find_this, param_name) in
1514            [("{siteUrl}", "siteUrl"), ("{feedpath}", "feedpath")].iter()
1515        {
1516            url = params.uri_replacement(url, param_name, find_this, false);
1517        }
1518        {
1519            let to_remove = ["feedpath", "siteUrl"];
1520            params.remove_params(&to_remove);
1521        }
1522
1523        let url = params.parse_with_url(&url);
1524
1525        loop {
1526            let token = match self
1527                .hub
1528                .auth
1529                .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
1530                .await
1531            {
1532                Ok(token) => token,
1533                Err(e) => match dlg.token(e) {
1534                    Ok(token) => token,
1535                    Err(e) => {
1536                        dlg.finished(false);
1537                        return Err(common::Error::MissingToken(e));
1538                    }
1539                },
1540            };
1541            let mut req_result = {
1542                let client = &self.hub.client;
1543                dlg.pre_request();
1544                let mut req_builder = hyper::Request::builder()
1545                    .method(hyper::Method::GET)
1546                    .uri(url.as_str())
1547                    .header(USER_AGENT, self.hub._user_agent.clone());
1548
1549                if let Some(token) = token.as_ref() {
1550                    req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
1551                }
1552
1553                let request = req_builder
1554                    .header(CONTENT_LENGTH, 0_u64)
1555                    .body(common::to_body::<String>(None));
1556
1557                client.request(request.unwrap()).await
1558            };
1559
1560            match req_result {
1561                Err(err) => {
1562                    if let common::Retry::After(d) = dlg.http_error(&err) {
1563                        sleep(d).await;
1564                        continue;
1565                    }
1566                    dlg.finished(false);
1567                    return Err(common::Error::HttpError(err));
1568                }
1569                Ok(res) => {
1570                    let (mut parts, body) = res.into_parts();
1571                    let mut body = common::Body::new(body);
1572                    if !parts.status.is_success() {
1573                        let bytes = common::to_bytes(body).await.unwrap_or_default();
1574                        let error = serde_json::from_str(&common::to_string(&bytes));
1575                        let response = common::to_response(parts, bytes.into());
1576
1577                        if let common::Retry::After(d) =
1578                            dlg.http_failure(&response, error.as_ref().ok())
1579                        {
1580                            sleep(d).await;
1581                            continue;
1582                        }
1583
1584                        dlg.finished(false);
1585
1586                        return Err(match error {
1587                            Ok(value) => common::Error::BadRequest(value),
1588                            _ => common::Error::Failure(response),
1589                        });
1590                    }
1591                    let response = {
1592                        let bytes = common::to_bytes(body).await.unwrap_or_default();
1593                        let encoded = common::to_string(&bytes);
1594                        match serde_json::from_str(&encoded) {
1595                            Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
1596                            Err(error) => {
1597                                dlg.response_json_decode_error(&encoded, &error);
1598                                return Err(common::Error::JsonDecodeError(
1599                                    encoded.to_string(),
1600                                    error,
1601                                ));
1602                            }
1603                        }
1604                    };
1605
1606                    dlg.finished(true);
1607                    return Ok(response);
1608                }
1609            }
1610        }
1611    }
1612
1613    /// The site's URL, including protocol. For example: http://www.example.com/
1614    ///
1615    /// Sets the *site url* path property to the given value.
1616    ///
1617    /// Even though the property as already been set when instantiating this call,
1618    /// we provide this method for API completeness.
1619    pub fn site_url(mut self, new_value: &str) -> SitemapGetCall<'a, C> {
1620        self._site_url = new_value.to_string();
1621        self
1622    }
1623    /// The URL of the actual sitemap. For example: http://www.example.com/sitemap.xml
1624    ///
1625    /// Sets the *feedpath* path property to the given value.
1626    ///
1627    /// Even though the property as already been set when instantiating this call,
1628    /// we provide this method for API completeness.
1629    pub fn feedpath(mut self, new_value: &str) -> SitemapGetCall<'a, C> {
1630        self._feedpath = new_value.to_string();
1631        self
1632    }
1633    /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
1634    /// while executing the actual API request.
1635    ///
1636    /// ````text
1637    ///                   It should be used to handle progress information, and to implement a certain level of resilience.
1638    /// ````
1639    ///
1640    /// Sets the *delegate* property to the given value.
1641    pub fn delegate(mut self, new_value: &'a mut dyn common::Delegate) -> SitemapGetCall<'a, C> {
1642        self._delegate = Some(new_value);
1643        self
1644    }
1645
1646    /// Set any additional parameter of the query string used in the request.
1647    /// It should be used to set parameters which are not yet available through their own
1648    /// setters.
1649    ///
1650    /// Please note that this method must not be used to set any of the known parameters
1651    /// which have their own setter method. If done anyway, the request will fail.
1652    ///
1653    /// # Additional Parameters
1654    ///
1655    /// * *alt* (query-string) - Data format for the response.
1656    /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
1657    /// * *key* (query-string) - API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.
1658    /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
1659    /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
1660    /// * *quotaUser* (query-string) - An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
1661    /// * *userIp* (query-string) - Deprecated. Please use quotaUser instead.
1662    pub fn param<T>(mut self, name: T, value: T) -> SitemapGetCall<'a, C>
1663    where
1664        T: AsRef<str>,
1665    {
1666        self._additional_params
1667            .insert(name.as_ref().to_string(), value.as_ref().to_string());
1668        self
1669    }
1670
1671    /// Identifies the authorization scope for the method you are building.
1672    ///
1673    /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
1674    /// [`Scope::Readonly`].
1675    ///
1676    /// The `scope` will be added to a set of scopes. This is important as one can maintain access
1677    /// tokens for more than one scope.
1678    ///
1679    /// Usually there is more than one suitable scope to authorize an operation, some of which may
1680    /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
1681    /// sufficient, a read-write scope will do as well.
1682    pub fn add_scope<St>(mut self, scope: St) -> SitemapGetCall<'a, C>
1683    where
1684        St: AsRef<str>,
1685    {
1686        self._scopes.insert(String::from(scope.as_ref()));
1687        self
1688    }
1689    /// Identifies the authorization scope(s) for the method you are building.
1690    ///
1691    /// See [`Self::add_scope()`] for details.
1692    pub fn add_scopes<I, St>(mut self, scopes: I) -> SitemapGetCall<'a, C>
1693    where
1694        I: IntoIterator<Item = St>,
1695        St: AsRef<str>,
1696    {
1697        self._scopes
1698            .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
1699        self
1700    }
1701
1702    /// Removes all scopes, and no default scope will be used either.
1703    /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
1704    /// for details).
1705    pub fn clear_scopes(mut self) -> SitemapGetCall<'a, C> {
1706        self._scopes.clear();
1707        self
1708    }
1709}
1710
1711/// Lists the sitemaps-entries submitted for this site, or included in the sitemap index file (if sitemapIndex is specified in the request).
1712///
1713/// A builder for the *list* method supported by a *sitemap* resource.
1714/// It is not used directly, but through a [`SitemapMethods`] instance.
1715///
1716/// # Example
1717///
1718/// Instantiate a resource method builder
1719///
1720/// ```test_harness,no_run
1721/// # extern crate hyper;
1722/// # extern crate hyper_rustls;
1723/// # extern crate google_webmasters3 as webmasters3;
1724/// # async fn dox() {
1725/// # use webmasters3::{Webmasters, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
1726///
1727/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
1728/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
1729/// #     .with_native_roots()
1730/// #     .unwrap()
1731/// #     .https_only()
1732/// #     .enable_http2()
1733/// #     .build();
1734///
1735/// # let executor = hyper_util::rt::TokioExecutor::new();
1736/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
1737/// #     secret,
1738/// #     yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
1739/// #     yup_oauth2::client::CustomHyperClientBuilder::from(
1740/// #         hyper_util::client::legacy::Client::builder(executor).build(connector),
1741/// #     ),
1742/// # ).build().await.unwrap();
1743///
1744/// # let client = hyper_util::client::legacy::Client::builder(
1745/// #     hyper_util::rt::TokioExecutor::new()
1746/// # )
1747/// # .build(
1748/// #     hyper_rustls::HttpsConnectorBuilder::new()
1749/// #         .with_native_roots()
1750/// #         .unwrap()
1751/// #         .https_or_http()
1752/// #         .enable_http2()
1753/// #         .build()
1754/// # );
1755/// # let mut hub = Webmasters::new(client, auth);
1756/// // You can configure optional parameters by calling the respective setters at will, and
1757/// // execute the final call using `doit()`.
1758/// // Values shown here are possibly random and not representative !
1759/// let result = hub.sitemaps().list("siteUrl")
1760///              .sitemap_index("takimata")
1761///              .doit().await;
1762/// # }
1763/// ```
1764pub struct SitemapListCall<'a, C>
1765where
1766    C: 'a,
1767{
1768    hub: &'a Webmasters<C>,
1769    _site_url: String,
1770    _sitemap_index: Option<String>,
1771    _delegate: Option<&'a mut dyn common::Delegate>,
1772    _additional_params: HashMap<String, String>,
1773    _scopes: BTreeSet<String>,
1774}
1775
1776impl<'a, C> common::CallBuilder for SitemapListCall<'a, C> {}
1777
1778impl<'a, C> SitemapListCall<'a, C>
1779where
1780    C: common::Connector,
1781{
1782    /// Perform the operation you have build so far.
1783    pub async fn doit(mut self) -> common::Result<(common::Response, SitemapsListResponse)> {
1784        use std::borrow::Cow;
1785        use std::io::{Read, Seek};
1786
1787        use common::{url::Params, ToParts};
1788        use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
1789
1790        let mut dd = common::DefaultDelegate;
1791        let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
1792        dlg.begin(common::MethodInfo {
1793            id: "webmasters.sitemaps.list",
1794            http_method: hyper::Method::GET,
1795        });
1796
1797        for &field in ["alt", "siteUrl", "sitemapIndex"].iter() {
1798            if self._additional_params.contains_key(field) {
1799                dlg.finished(false);
1800                return Err(common::Error::FieldClash(field));
1801            }
1802        }
1803
1804        let mut params = Params::with_capacity(4 + self._additional_params.len());
1805        params.push("siteUrl", self._site_url);
1806        if let Some(value) = self._sitemap_index.as_ref() {
1807            params.push("sitemapIndex", value);
1808        }
1809
1810        params.extend(self._additional_params.iter());
1811
1812        params.push("alt", "json");
1813        let mut url = self.hub._base_url.clone() + "sites/{siteUrl}/sitemaps";
1814        if self._scopes.is_empty() {
1815            self._scopes.insert(Scope::Readonly.as_ref().to_string());
1816        }
1817
1818        #[allow(clippy::single_element_loop)]
1819        for &(find_this, param_name) in [("{siteUrl}", "siteUrl")].iter() {
1820            url = params.uri_replacement(url, param_name, find_this, false);
1821        }
1822        {
1823            let to_remove = ["siteUrl"];
1824            params.remove_params(&to_remove);
1825        }
1826
1827        let url = params.parse_with_url(&url);
1828
1829        loop {
1830            let token = match self
1831                .hub
1832                .auth
1833                .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
1834                .await
1835            {
1836                Ok(token) => token,
1837                Err(e) => match dlg.token(e) {
1838                    Ok(token) => token,
1839                    Err(e) => {
1840                        dlg.finished(false);
1841                        return Err(common::Error::MissingToken(e));
1842                    }
1843                },
1844            };
1845            let mut req_result = {
1846                let client = &self.hub.client;
1847                dlg.pre_request();
1848                let mut req_builder = hyper::Request::builder()
1849                    .method(hyper::Method::GET)
1850                    .uri(url.as_str())
1851                    .header(USER_AGENT, self.hub._user_agent.clone());
1852
1853                if let Some(token) = token.as_ref() {
1854                    req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
1855                }
1856
1857                let request = req_builder
1858                    .header(CONTENT_LENGTH, 0_u64)
1859                    .body(common::to_body::<String>(None));
1860
1861                client.request(request.unwrap()).await
1862            };
1863
1864            match req_result {
1865                Err(err) => {
1866                    if let common::Retry::After(d) = dlg.http_error(&err) {
1867                        sleep(d).await;
1868                        continue;
1869                    }
1870                    dlg.finished(false);
1871                    return Err(common::Error::HttpError(err));
1872                }
1873                Ok(res) => {
1874                    let (mut parts, body) = res.into_parts();
1875                    let mut body = common::Body::new(body);
1876                    if !parts.status.is_success() {
1877                        let bytes = common::to_bytes(body).await.unwrap_or_default();
1878                        let error = serde_json::from_str(&common::to_string(&bytes));
1879                        let response = common::to_response(parts, bytes.into());
1880
1881                        if let common::Retry::After(d) =
1882                            dlg.http_failure(&response, error.as_ref().ok())
1883                        {
1884                            sleep(d).await;
1885                            continue;
1886                        }
1887
1888                        dlg.finished(false);
1889
1890                        return Err(match error {
1891                            Ok(value) => common::Error::BadRequest(value),
1892                            _ => common::Error::Failure(response),
1893                        });
1894                    }
1895                    let response = {
1896                        let bytes = common::to_bytes(body).await.unwrap_or_default();
1897                        let encoded = common::to_string(&bytes);
1898                        match serde_json::from_str(&encoded) {
1899                            Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
1900                            Err(error) => {
1901                                dlg.response_json_decode_error(&encoded, &error);
1902                                return Err(common::Error::JsonDecodeError(
1903                                    encoded.to_string(),
1904                                    error,
1905                                ));
1906                            }
1907                        }
1908                    };
1909
1910                    dlg.finished(true);
1911                    return Ok(response);
1912                }
1913            }
1914        }
1915    }
1916
1917    /// The site's URL, including protocol. For example: http://www.example.com/
1918    ///
1919    /// Sets the *site url* path property to the given value.
1920    ///
1921    /// Even though the property as already been set when instantiating this call,
1922    /// we provide this method for API completeness.
1923    pub fn site_url(mut self, new_value: &str) -> SitemapListCall<'a, C> {
1924        self._site_url = new_value.to_string();
1925        self
1926    }
1927    /// A URL of a site's sitemap index. For example: http://www.example.com/sitemapindex.xml
1928    ///
1929    /// Sets the *sitemap index* query property to the given value.
1930    pub fn sitemap_index(mut self, new_value: &str) -> SitemapListCall<'a, C> {
1931        self._sitemap_index = Some(new_value.to_string());
1932        self
1933    }
1934    /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
1935    /// while executing the actual API request.
1936    ///
1937    /// ````text
1938    ///                   It should be used to handle progress information, and to implement a certain level of resilience.
1939    /// ````
1940    ///
1941    /// Sets the *delegate* property to the given value.
1942    pub fn delegate(mut self, new_value: &'a mut dyn common::Delegate) -> SitemapListCall<'a, C> {
1943        self._delegate = Some(new_value);
1944        self
1945    }
1946
1947    /// Set any additional parameter of the query string used in the request.
1948    /// It should be used to set parameters which are not yet available through their own
1949    /// setters.
1950    ///
1951    /// Please note that this method must not be used to set any of the known parameters
1952    /// which have their own setter method. If done anyway, the request will fail.
1953    ///
1954    /// # Additional Parameters
1955    ///
1956    /// * *alt* (query-string) - Data format for the response.
1957    /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
1958    /// * *key* (query-string) - API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.
1959    /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
1960    /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
1961    /// * *quotaUser* (query-string) - An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
1962    /// * *userIp* (query-string) - Deprecated. Please use quotaUser instead.
1963    pub fn param<T>(mut self, name: T, value: T) -> SitemapListCall<'a, C>
1964    where
1965        T: AsRef<str>,
1966    {
1967        self._additional_params
1968            .insert(name.as_ref().to_string(), value.as_ref().to_string());
1969        self
1970    }
1971
1972    /// Identifies the authorization scope for the method you are building.
1973    ///
1974    /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
1975    /// [`Scope::Readonly`].
1976    ///
1977    /// The `scope` will be added to a set of scopes. This is important as one can maintain access
1978    /// tokens for more than one scope.
1979    ///
1980    /// Usually there is more than one suitable scope to authorize an operation, some of which may
1981    /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
1982    /// sufficient, a read-write scope will do as well.
1983    pub fn add_scope<St>(mut self, scope: St) -> SitemapListCall<'a, C>
1984    where
1985        St: AsRef<str>,
1986    {
1987        self._scopes.insert(String::from(scope.as_ref()));
1988        self
1989    }
1990    /// Identifies the authorization scope(s) for the method you are building.
1991    ///
1992    /// See [`Self::add_scope()`] for details.
1993    pub fn add_scopes<I, St>(mut self, scopes: I) -> SitemapListCall<'a, C>
1994    where
1995        I: IntoIterator<Item = St>,
1996        St: AsRef<str>,
1997    {
1998        self._scopes
1999            .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
2000        self
2001    }
2002
2003    /// Removes all scopes, and no default scope will be used either.
2004    /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
2005    /// for details).
2006    pub fn clear_scopes(mut self) -> SitemapListCall<'a, C> {
2007        self._scopes.clear();
2008        self
2009    }
2010}
2011
2012/// Submits a sitemap for a site.
2013///
2014/// A builder for the *submit* method supported by a *sitemap* resource.
2015/// It is not used directly, but through a [`SitemapMethods`] instance.
2016///
2017/// # Example
2018///
2019/// Instantiate a resource method builder
2020///
2021/// ```test_harness,no_run
2022/// # extern crate hyper;
2023/// # extern crate hyper_rustls;
2024/// # extern crate google_webmasters3 as webmasters3;
2025/// # async fn dox() {
2026/// # use webmasters3::{Webmasters, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
2027///
2028/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
2029/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
2030/// #     .with_native_roots()
2031/// #     .unwrap()
2032/// #     .https_only()
2033/// #     .enable_http2()
2034/// #     .build();
2035///
2036/// # let executor = hyper_util::rt::TokioExecutor::new();
2037/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
2038/// #     secret,
2039/// #     yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
2040/// #     yup_oauth2::client::CustomHyperClientBuilder::from(
2041/// #         hyper_util::client::legacy::Client::builder(executor).build(connector),
2042/// #     ),
2043/// # ).build().await.unwrap();
2044///
2045/// # let client = hyper_util::client::legacy::Client::builder(
2046/// #     hyper_util::rt::TokioExecutor::new()
2047/// # )
2048/// # .build(
2049/// #     hyper_rustls::HttpsConnectorBuilder::new()
2050/// #         .with_native_roots()
2051/// #         .unwrap()
2052/// #         .https_or_http()
2053/// #         .enable_http2()
2054/// #         .build()
2055/// # );
2056/// # let mut hub = Webmasters::new(client, auth);
2057/// // You can configure optional parameters by calling the respective setters at will, and
2058/// // execute the final call using `doit()`.
2059/// // Values shown here are possibly random and not representative !
2060/// let result = hub.sitemaps().submit("siteUrl", "feedpath")
2061///              .doit().await;
2062/// # }
2063/// ```
2064pub struct SitemapSubmitCall<'a, C>
2065where
2066    C: 'a,
2067{
2068    hub: &'a Webmasters<C>,
2069    _site_url: String,
2070    _feedpath: String,
2071    _delegate: Option<&'a mut dyn common::Delegate>,
2072    _additional_params: HashMap<String, String>,
2073    _scopes: BTreeSet<String>,
2074}
2075
2076impl<'a, C> common::CallBuilder for SitemapSubmitCall<'a, C> {}
2077
2078impl<'a, C> SitemapSubmitCall<'a, C>
2079where
2080    C: common::Connector,
2081{
2082    /// Perform the operation you have build so far.
2083    pub async fn doit(mut self) -> common::Result<common::Response> {
2084        use std::borrow::Cow;
2085        use std::io::{Read, Seek};
2086
2087        use common::{url::Params, ToParts};
2088        use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
2089
2090        let mut dd = common::DefaultDelegate;
2091        let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
2092        dlg.begin(common::MethodInfo {
2093            id: "webmasters.sitemaps.submit",
2094            http_method: hyper::Method::PUT,
2095        });
2096
2097        for &field in ["siteUrl", "feedpath"].iter() {
2098            if self._additional_params.contains_key(field) {
2099                dlg.finished(false);
2100                return Err(common::Error::FieldClash(field));
2101            }
2102        }
2103
2104        let mut params = Params::with_capacity(3 + self._additional_params.len());
2105        params.push("siteUrl", self._site_url);
2106        params.push("feedpath", self._feedpath);
2107
2108        params.extend(self._additional_params.iter());
2109
2110        let mut url = self.hub._base_url.clone() + "sites/{siteUrl}/sitemaps/{feedpath}";
2111        if self._scopes.is_empty() {
2112            self._scopes.insert(Scope::Full.as_ref().to_string());
2113        }
2114
2115        #[allow(clippy::single_element_loop)]
2116        for &(find_this, param_name) in
2117            [("{siteUrl}", "siteUrl"), ("{feedpath}", "feedpath")].iter()
2118        {
2119            url = params.uri_replacement(url, param_name, find_this, false);
2120        }
2121        {
2122            let to_remove = ["feedpath", "siteUrl"];
2123            params.remove_params(&to_remove);
2124        }
2125
2126        let url = params.parse_with_url(&url);
2127
2128        loop {
2129            let token = match self
2130                .hub
2131                .auth
2132                .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
2133                .await
2134            {
2135                Ok(token) => token,
2136                Err(e) => match dlg.token(e) {
2137                    Ok(token) => token,
2138                    Err(e) => {
2139                        dlg.finished(false);
2140                        return Err(common::Error::MissingToken(e));
2141                    }
2142                },
2143            };
2144            let mut req_result = {
2145                let client = &self.hub.client;
2146                dlg.pre_request();
2147                let mut req_builder = hyper::Request::builder()
2148                    .method(hyper::Method::PUT)
2149                    .uri(url.as_str())
2150                    .header(USER_AGENT, self.hub._user_agent.clone());
2151
2152                if let Some(token) = token.as_ref() {
2153                    req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
2154                }
2155
2156                let request = req_builder
2157                    .header(CONTENT_LENGTH, 0_u64)
2158                    .body(common::to_body::<String>(None));
2159
2160                client.request(request.unwrap()).await
2161            };
2162
2163            match req_result {
2164                Err(err) => {
2165                    if let common::Retry::After(d) = dlg.http_error(&err) {
2166                        sleep(d).await;
2167                        continue;
2168                    }
2169                    dlg.finished(false);
2170                    return Err(common::Error::HttpError(err));
2171                }
2172                Ok(res) => {
2173                    let (mut parts, body) = res.into_parts();
2174                    let mut body = common::Body::new(body);
2175                    if !parts.status.is_success() {
2176                        let bytes = common::to_bytes(body).await.unwrap_or_default();
2177                        let error = serde_json::from_str(&common::to_string(&bytes));
2178                        let response = common::to_response(parts, bytes.into());
2179
2180                        if let common::Retry::After(d) =
2181                            dlg.http_failure(&response, error.as_ref().ok())
2182                        {
2183                            sleep(d).await;
2184                            continue;
2185                        }
2186
2187                        dlg.finished(false);
2188
2189                        return Err(match error {
2190                            Ok(value) => common::Error::BadRequest(value),
2191                            _ => common::Error::Failure(response),
2192                        });
2193                    }
2194                    let response = common::Response::from_parts(parts, body);
2195
2196                    dlg.finished(true);
2197                    return Ok(response);
2198                }
2199            }
2200        }
2201    }
2202
2203    /// The site's URL, including protocol. For example: http://www.example.com/
2204    ///
2205    /// Sets the *site url* path property to the given value.
2206    ///
2207    /// Even though the property as already been set when instantiating this call,
2208    /// we provide this method for API completeness.
2209    pub fn site_url(mut self, new_value: &str) -> SitemapSubmitCall<'a, C> {
2210        self._site_url = new_value.to_string();
2211        self
2212    }
2213    /// The URL of the sitemap to add. For example: http://www.example.com/sitemap.xml
2214    ///
2215    /// Sets the *feedpath* path property to the given value.
2216    ///
2217    /// Even though the property as already been set when instantiating this call,
2218    /// we provide this method for API completeness.
2219    pub fn feedpath(mut self, new_value: &str) -> SitemapSubmitCall<'a, C> {
2220        self._feedpath = new_value.to_string();
2221        self
2222    }
2223    /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
2224    /// while executing the actual API request.
2225    ///
2226    /// ````text
2227    ///                   It should be used to handle progress information, and to implement a certain level of resilience.
2228    /// ````
2229    ///
2230    /// Sets the *delegate* property to the given value.
2231    pub fn delegate(mut self, new_value: &'a mut dyn common::Delegate) -> SitemapSubmitCall<'a, C> {
2232        self._delegate = Some(new_value);
2233        self
2234    }
2235
2236    /// Set any additional parameter of the query string used in the request.
2237    /// It should be used to set parameters which are not yet available through their own
2238    /// setters.
2239    ///
2240    /// Please note that this method must not be used to set any of the known parameters
2241    /// which have their own setter method. If done anyway, the request will fail.
2242    ///
2243    /// # Additional Parameters
2244    ///
2245    /// * *alt* (query-string) - Data format for the response.
2246    /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
2247    /// * *key* (query-string) - API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.
2248    /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
2249    /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
2250    /// * *quotaUser* (query-string) - An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
2251    /// * *userIp* (query-string) - Deprecated. Please use quotaUser instead.
2252    pub fn param<T>(mut self, name: T, value: T) -> SitemapSubmitCall<'a, C>
2253    where
2254        T: AsRef<str>,
2255    {
2256        self._additional_params
2257            .insert(name.as_ref().to_string(), value.as_ref().to_string());
2258        self
2259    }
2260
2261    /// Identifies the authorization scope for the method you are building.
2262    ///
2263    /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
2264    /// [`Scope::Full`].
2265    ///
2266    /// The `scope` will be added to a set of scopes. This is important as one can maintain access
2267    /// tokens for more than one scope.
2268    ///
2269    /// Usually there is more than one suitable scope to authorize an operation, some of which may
2270    /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
2271    /// sufficient, a read-write scope will do as well.
2272    pub fn add_scope<St>(mut self, scope: St) -> SitemapSubmitCall<'a, C>
2273    where
2274        St: AsRef<str>,
2275    {
2276        self._scopes.insert(String::from(scope.as_ref()));
2277        self
2278    }
2279    /// Identifies the authorization scope(s) for the method you are building.
2280    ///
2281    /// See [`Self::add_scope()`] for details.
2282    pub fn add_scopes<I, St>(mut self, scopes: I) -> SitemapSubmitCall<'a, C>
2283    where
2284        I: IntoIterator<Item = St>,
2285        St: AsRef<str>,
2286    {
2287        self._scopes
2288            .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
2289        self
2290    }
2291
2292    /// Removes all scopes, and no default scope will be used either.
2293    /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
2294    /// for details).
2295    pub fn clear_scopes(mut self) -> SitemapSubmitCall<'a, C> {
2296        self._scopes.clear();
2297        self
2298    }
2299}
2300
2301/// Adds a site to the set of the user's sites in Search Console.
2302///
2303/// A builder for the *add* method supported by a *site* resource.
2304/// It is not used directly, but through a [`SiteMethods`] instance.
2305///
2306/// # Example
2307///
2308/// Instantiate a resource method builder
2309///
2310/// ```test_harness,no_run
2311/// # extern crate hyper;
2312/// # extern crate hyper_rustls;
2313/// # extern crate google_webmasters3 as webmasters3;
2314/// # async fn dox() {
2315/// # use webmasters3::{Webmasters, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
2316///
2317/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
2318/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
2319/// #     .with_native_roots()
2320/// #     .unwrap()
2321/// #     .https_only()
2322/// #     .enable_http2()
2323/// #     .build();
2324///
2325/// # let executor = hyper_util::rt::TokioExecutor::new();
2326/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
2327/// #     secret,
2328/// #     yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
2329/// #     yup_oauth2::client::CustomHyperClientBuilder::from(
2330/// #         hyper_util::client::legacy::Client::builder(executor).build(connector),
2331/// #     ),
2332/// # ).build().await.unwrap();
2333///
2334/// # let client = hyper_util::client::legacy::Client::builder(
2335/// #     hyper_util::rt::TokioExecutor::new()
2336/// # )
2337/// # .build(
2338/// #     hyper_rustls::HttpsConnectorBuilder::new()
2339/// #         .with_native_roots()
2340/// #         .unwrap()
2341/// #         .https_or_http()
2342/// #         .enable_http2()
2343/// #         .build()
2344/// # );
2345/// # let mut hub = Webmasters::new(client, auth);
2346/// // You can configure optional parameters by calling the respective setters at will, and
2347/// // execute the final call using `doit()`.
2348/// // Values shown here are possibly random and not representative !
2349/// let result = hub.sites().add("siteUrl")
2350///              .doit().await;
2351/// # }
2352/// ```
2353pub struct SiteAddCall<'a, C>
2354where
2355    C: 'a,
2356{
2357    hub: &'a Webmasters<C>,
2358    _site_url: String,
2359    _delegate: Option<&'a mut dyn common::Delegate>,
2360    _additional_params: HashMap<String, String>,
2361    _scopes: BTreeSet<String>,
2362}
2363
2364impl<'a, C> common::CallBuilder for SiteAddCall<'a, C> {}
2365
2366impl<'a, C> SiteAddCall<'a, C>
2367where
2368    C: common::Connector,
2369{
2370    /// Perform the operation you have build so far.
2371    pub async fn doit(mut self) -> common::Result<common::Response> {
2372        use std::borrow::Cow;
2373        use std::io::{Read, Seek};
2374
2375        use common::{url::Params, ToParts};
2376        use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
2377
2378        let mut dd = common::DefaultDelegate;
2379        let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
2380        dlg.begin(common::MethodInfo {
2381            id: "webmasters.sites.add",
2382            http_method: hyper::Method::PUT,
2383        });
2384
2385        for &field in ["siteUrl"].iter() {
2386            if self._additional_params.contains_key(field) {
2387                dlg.finished(false);
2388                return Err(common::Error::FieldClash(field));
2389            }
2390        }
2391
2392        let mut params = Params::with_capacity(2 + self._additional_params.len());
2393        params.push("siteUrl", self._site_url);
2394
2395        params.extend(self._additional_params.iter());
2396
2397        let mut url = self.hub._base_url.clone() + "sites/{siteUrl}";
2398        if self._scopes.is_empty() {
2399            self._scopes.insert(Scope::Full.as_ref().to_string());
2400        }
2401
2402        #[allow(clippy::single_element_loop)]
2403        for &(find_this, param_name) in [("{siteUrl}", "siteUrl")].iter() {
2404            url = params.uri_replacement(url, param_name, find_this, false);
2405        }
2406        {
2407            let to_remove = ["siteUrl"];
2408            params.remove_params(&to_remove);
2409        }
2410
2411        let url = params.parse_with_url(&url);
2412
2413        loop {
2414            let token = match self
2415                .hub
2416                .auth
2417                .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
2418                .await
2419            {
2420                Ok(token) => token,
2421                Err(e) => match dlg.token(e) {
2422                    Ok(token) => token,
2423                    Err(e) => {
2424                        dlg.finished(false);
2425                        return Err(common::Error::MissingToken(e));
2426                    }
2427                },
2428            };
2429            let mut req_result = {
2430                let client = &self.hub.client;
2431                dlg.pre_request();
2432                let mut req_builder = hyper::Request::builder()
2433                    .method(hyper::Method::PUT)
2434                    .uri(url.as_str())
2435                    .header(USER_AGENT, self.hub._user_agent.clone());
2436
2437                if let Some(token) = token.as_ref() {
2438                    req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
2439                }
2440
2441                let request = req_builder
2442                    .header(CONTENT_LENGTH, 0_u64)
2443                    .body(common::to_body::<String>(None));
2444
2445                client.request(request.unwrap()).await
2446            };
2447
2448            match req_result {
2449                Err(err) => {
2450                    if let common::Retry::After(d) = dlg.http_error(&err) {
2451                        sleep(d).await;
2452                        continue;
2453                    }
2454                    dlg.finished(false);
2455                    return Err(common::Error::HttpError(err));
2456                }
2457                Ok(res) => {
2458                    let (mut parts, body) = res.into_parts();
2459                    let mut body = common::Body::new(body);
2460                    if !parts.status.is_success() {
2461                        let bytes = common::to_bytes(body).await.unwrap_or_default();
2462                        let error = serde_json::from_str(&common::to_string(&bytes));
2463                        let response = common::to_response(parts, bytes.into());
2464
2465                        if let common::Retry::After(d) =
2466                            dlg.http_failure(&response, error.as_ref().ok())
2467                        {
2468                            sleep(d).await;
2469                            continue;
2470                        }
2471
2472                        dlg.finished(false);
2473
2474                        return Err(match error {
2475                            Ok(value) => common::Error::BadRequest(value),
2476                            _ => common::Error::Failure(response),
2477                        });
2478                    }
2479                    let response = common::Response::from_parts(parts, body);
2480
2481                    dlg.finished(true);
2482                    return Ok(response);
2483                }
2484            }
2485        }
2486    }
2487
2488    /// The URL of the site to add.
2489    ///
2490    /// Sets the *site url* path property to the given value.
2491    ///
2492    /// Even though the property as already been set when instantiating this call,
2493    /// we provide this method for API completeness.
2494    pub fn site_url(mut self, new_value: &str) -> SiteAddCall<'a, C> {
2495        self._site_url = new_value.to_string();
2496        self
2497    }
2498    /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
2499    /// while executing the actual API request.
2500    ///
2501    /// ````text
2502    ///                   It should be used to handle progress information, and to implement a certain level of resilience.
2503    /// ````
2504    ///
2505    /// Sets the *delegate* property to the given value.
2506    pub fn delegate(mut self, new_value: &'a mut dyn common::Delegate) -> SiteAddCall<'a, C> {
2507        self._delegate = Some(new_value);
2508        self
2509    }
2510
2511    /// Set any additional parameter of the query string used in the request.
2512    /// It should be used to set parameters which are not yet available through their own
2513    /// setters.
2514    ///
2515    /// Please note that this method must not be used to set any of the known parameters
2516    /// which have their own setter method. If done anyway, the request will fail.
2517    ///
2518    /// # Additional Parameters
2519    ///
2520    /// * *alt* (query-string) - Data format for the response.
2521    /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
2522    /// * *key* (query-string) - API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.
2523    /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
2524    /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
2525    /// * *quotaUser* (query-string) - An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
2526    /// * *userIp* (query-string) - Deprecated. Please use quotaUser instead.
2527    pub fn param<T>(mut self, name: T, value: T) -> SiteAddCall<'a, C>
2528    where
2529        T: AsRef<str>,
2530    {
2531        self._additional_params
2532            .insert(name.as_ref().to_string(), value.as_ref().to_string());
2533        self
2534    }
2535
2536    /// Identifies the authorization scope for the method you are building.
2537    ///
2538    /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
2539    /// [`Scope::Full`].
2540    ///
2541    /// The `scope` will be added to a set of scopes. This is important as one can maintain access
2542    /// tokens for more than one scope.
2543    ///
2544    /// Usually there is more than one suitable scope to authorize an operation, some of which may
2545    /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
2546    /// sufficient, a read-write scope will do as well.
2547    pub fn add_scope<St>(mut self, scope: St) -> SiteAddCall<'a, C>
2548    where
2549        St: AsRef<str>,
2550    {
2551        self._scopes.insert(String::from(scope.as_ref()));
2552        self
2553    }
2554    /// Identifies the authorization scope(s) for the method you are building.
2555    ///
2556    /// See [`Self::add_scope()`] for details.
2557    pub fn add_scopes<I, St>(mut self, scopes: I) -> SiteAddCall<'a, C>
2558    where
2559        I: IntoIterator<Item = St>,
2560        St: AsRef<str>,
2561    {
2562        self._scopes
2563            .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
2564        self
2565    }
2566
2567    /// Removes all scopes, and no default scope will be used either.
2568    /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
2569    /// for details).
2570    pub fn clear_scopes(mut self) -> SiteAddCall<'a, C> {
2571        self._scopes.clear();
2572        self
2573    }
2574}
2575
2576/// Removes a site from the set of the user's Search Console sites.
2577///
2578/// A builder for the *delete* method supported by a *site* resource.
2579/// It is not used directly, but through a [`SiteMethods`] instance.
2580///
2581/// # Example
2582///
2583/// Instantiate a resource method builder
2584///
2585/// ```test_harness,no_run
2586/// # extern crate hyper;
2587/// # extern crate hyper_rustls;
2588/// # extern crate google_webmasters3 as webmasters3;
2589/// # async fn dox() {
2590/// # use webmasters3::{Webmasters, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
2591///
2592/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
2593/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
2594/// #     .with_native_roots()
2595/// #     .unwrap()
2596/// #     .https_only()
2597/// #     .enable_http2()
2598/// #     .build();
2599///
2600/// # let executor = hyper_util::rt::TokioExecutor::new();
2601/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
2602/// #     secret,
2603/// #     yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
2604/// #     yup_oauth2::client::CustomHyperClientBuilder::from(
2605/// #         hyper_util::client::legacy::Client::builder(executor).build(connector),
2606/// #     ),
2607/// # ).build().await.unwrap();
2608///
2609/// # let client = hyper_util::client::legacy::Client::builder(
2610/// #     hyper_util::rt::TokioExecutor::new()
2611/// # )
2612/// # .build(
2613/// #     hyper_rustls::HttpsConnectorBuilder::new()
2614/// #         .with_native_roots()
2615/// #         .unwrap()
2616/// #         .https_or_http()
2617/// #         .enable_http2()
2618/// #         .build()
2619/// # );
2620/// # let mut hub = Webmasters::new(client, auth);
2621/// // You can configure optional parameters by calling the respective setters at will, and
2622/// // execute the final call using `doit()`.
2623/// // Values shown here are possibly random and not representative !
2624/// let result = hub.sites().delete("siteUrl")
2625///              .doit().await;
2626/// # }
2627/// ```
2628pub struct SiteDeleteCall<'a, C>
2629where
2630    C: 'a,
2631{
2632    hub: &'a Webmasters<C>,
2633    _site_url: String,
2634    _delegate: Option<&'a mut dyn common::Delegate>,
2635    _additional_params: HashMap<String, String>,
2636    _scopes: BTreeSet<String>,
2637}
2638
2639impl<'a, C> common::CallBuilder for SiteDeleteCall<'a, C> {}
2640
2641impl<'a, C> SiteDeleteCall<'a, C>
2642where
2643    C: common::Connector,
2644{
2645    /// Perform the operation you have build so far.
2646    pub async fn doit(mut self) -> common::Result<common::Response> {
2647        use std::borrow::Cow;
2648        use std::io::{Read, Seek};
2649
2650        use common::{url::Params, ToParts};
2651        use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
2652
2653        let mut dd = common::DefaultDelegate;
2654        let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
2655        dlg.begin(common::MethodInfo {
2656            id: "webmasters.sites.delete",
2657            http_method: hyper::Method::DELETE,
2658        });
2659
2660        for &field in ["siteUrl"].iter() {
2661            if self._additional_params.contains_key(field) {
2662                dlg.finished(false);
2663                return Err(common::Error::FieldClash(field));
2664            }
2665        }
2666
2667        let mut params = Params::with_capacity(2 + self._additional_params.len());
2668        params.push("siteUrl", self._site_url);
2669
2670        params.extend(self._additional_params.iter());
2671
2672        let mut url = self.hub._base_url.clone() + "sites/{siteUrl}";
2673        if self._scopes.is_empty() {
2674            self._scopes.insert(Scope::Full.as_ref().to_string());
2675        }
2676
2677        #[allow(clippy::single_element_loop)]
2678        for &(find_this, param_name) in [("{siteUrl}", "siteUrl")].iter() {
2679            url = params.uri_replacement(url, param_name, find_this, false);
2680        }
2681        {
2682            let to_remove = ["siteUrl"];
2683            params.remove_params(&to_remove);
2684        }
2685
2686        let url = params.parse_with_url(&url);
2687
2688        loop {
2689            let token = match self
2690                .hub
2691                .auth
2692                .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
2693                .await
2694            {
2695                Ok(token) => token,
2696                Err(e) => match dlg.token(e) {
2697                    Ok(token) => token,
2698                    Err(e) => {
2699                        dlg.finished(false);
2700                        return Err(common::Error::MissingToken(e));
2701                    }
2702                },
2703            };
2704            let mut req_result = {
2705                let client = &self.hub.client;
2706                dlg.pre_request();
2707                let mut req_builder = hyper::Request::builder()
2708                    .method(hyper::Method::DELETE)
2709                    .uri(url.as_str())
2710                    .header(USER_AGENT, self.hub._user_agent.clone());
2711
2712                if let Some(token) = token.as_ref() {
2713                    req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
2714                }
2715
2716                let request = req_builder
2717                    .header(CONTENT_LENGTH, 0_u64)
2718                    .body(common::to_body::<String>(None));
2719
2720                client.request(request.unwrap()).await
2721            };
2722
2723            match req_result {
2724                Err(err) => {
2725                    if let common::Retry::After(d) = dlg.http_error(&err) {
2726                        sleep(d).await;
2727                        continue;
2728                    }
2729                    dlg.finished(false);
2730                    return Err(common::Error::HttpError(err));
2731                }
2732                Ok(res) => {
2733                    let (mut parts, body) = res.into_parts();
2734                    let mut body = common::Body::new(body);
2735                    if !parts.status.is_success() {
2736                        let bytes = common::to_bytes(body).await.unwrap_or_default();
2737                        let error = serde_json::from_str(&common::to_string(&bytes));
2738                        let response = common::to_response(parts, bytes.into());
2739
2740                        if let common::Retry::After(d) =
2741                            dlg.http_failure(&response, error.as_ref().ok())
2742                        {
2743                            sleep(d).await;
2744                            continue;
2745                        }
2746
2747                        dlg.finished(false);
2748
2749                        return Err(match error {
2750                            Ok(value) => common::Error::BadRequest(value),
2751                            _ => common::Error::Failure(response),
2752                        });
2753                    }
2754                    let response = common::Response::from_parts(parts, body);
2755
2756                    dlg.finished(true);
2757                    return Ok(response);
2758                }
2759            }
2760        }
2761    }
2762
2763    /// The URI of the property as defined in Search Console. Examples: http://www.example.com/ or android-app://com.example/ Note: for property-sets, use the URI that starts with sc-set: which is used in Search Console URLs.
2764    ///
2765    /// Sets the *site url* path property to the given value.
2766    ///
2767    /// Even though the property as already been set when instantiating this call,
2768    /// we provide this method for API completeness.
2769    pub fn site_url(mut self, new_value: &str) -> SiteDeleteCall<'a, C> {
2770        self._site_url = new_value.to_string();
2771        self
2772    }
2773    /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
2774    /// while executing the actual API request.
2775    ///
2776    /// ````text
2777    ///                   It should be used to handle progress information, and to implement a certain level of resilience.
2778    /// ````
2779    ///
2780    /// Sets the *delegate* property to the given value.
2781    pub fn delegate(mut self, new_value: &'a mut dyn common::Delegate) -> SiteDeleteCall<'a, C> {
2782        self._delegate = Some(new_value);
2783        self
2784    }
2785
2786    /// Set any additional parameter of the query string used in the request.
2787    /// It should be used to set parameters which are not yet available through their own
2788    /// setters.
2789    ///
2790    /// Please note that this method must not be used to set any of the known parameters
2791    /// which have their own setter method. If done anyway, the request will fail.
2792    ///
2793    /// # Additional Parameters
2794    ///
2795    /// * *alt* (query-string) - Data format for the response.
2796    /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
2797    /// * *key* (query-string) - API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.
2798    /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
2799    /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
2800    /// * *quotaUser* (query-string) - An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
2801    /// * *userIp* (query-string) - Deprecated. Please use quotaUser instead.
2802    pub fn param<T>(mut self, name: T, value: T) -> SiteDeleteCall<'a, C>
2803    where
2804        T: AsRef<str>,
2805    {
2806        self._additional_params
2807            .insert(name.as_ref().to_string(), value.as_ref().to_string());
2808        self
2809    }
2810
2811    /// Identifies the authorization scope for the method you are building.
2812    ///
2813    /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
2814    /// [`Scope::Full`].
2815    ///
2816    /// The `scope` will be added to a set of scopes. This is important as one can maintain access
2817    /// tokens for more than one scope.
2818    ///
2819    /// Usually there is more than one suitable scope to authorize an operation, some of which may
2820    /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
2821    /// sufficient, a read-write scope will do as well.
2822    pub fn add_scope<St>(mut self, scope: St) -> SiteDeleteCall<'a, C>
2823    where
2824        St: AsRef<str>,
2825    {
2826        self._scopes.insert(String::from(scope.as_ref()));
2827        self
2828    }
2829    /// Identifies the authorization scope(s) for the method you are building.
2830    ///
2831    /// See [`Self::add_scope()`] for details.
2832    pub fn add_scopes<I, St>(mut self, scopes: I) -> SiteDeleteCall<'a, C>
2833    where
2834        I: IntoIterator<Item = St>,
2835        St: AsRef<str>,
2836    {
2837        self._scopes
2838            .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
2839        self
2840    }
2841
2842    /// Removes all scopes, and no default scope will be used either.
2843    /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
2844    /// for details).
2845    pub fn clear_scopes(mut self) -> SiteDeleteCall<'a, C> {
2846        self._scopes.clear();
2847        self
2848    }
2849}
2850
2851/// Retrieves information about specific site.
2852///
2853/// A builder for the *get* method supported by a *site* resource.
2854/// It is not used directly, but through a [`SiteMethods`] instance.
2855///
2856/// # Example
2857///
2858/// Instantiate a resource method builder
2859///
2860/// ```test_harness,no_run
2861/// # extern crate hyper;
2862/// # extern crate hyper_rustls;
2863/// # extern crate google_webmasters3 as webmasters3;
2864/// # async fn dox() {
2865/// # use webmasters3::{Webmasters, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
2866///
2867/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
2868/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
2869/// #     .with_native_roots()
2870/// #     .unwrap()
2871/// #     .https_only()
2872/// #     .enable_http2()
2873/// #     .build();
2874///
2875/// # let executor = hyper_util::rt::TokioExecutor::new();
2876/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
2877/// #     secret,
2878/// #     yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
2879/// #     yup_oauth2::client::CustomHyperClientBuilder::from(
2880/// #         hyper_util::client::legacy::Client::builder(executor).build(connector),
2881/// #     ),
2882/// # ).build().await.unwrap();
2883///
2884/// # let client = hyper_util::client::legacy::Client::builder(
2885/// #     hyper_util::rt::TokioExecutor::new()
2886/// # )
2887/// # .build(
2888/// #     hyper_rustls::HttpsConnectorBuilder::new()
2889/// #         .with_native_roots()
2890/// #         .unwrap()
2891/// #         .https_or_http()
2892/// #         .enable_http2()
2893/// #         .build()
2894/// # );
2895/// # let mut hub = Webmasters::new(client, auth);
2896/// // You can configure optional parameters by calling the respective setters at will, and
2897/// // execute the final call using `doit()`.
2898/// // Values shown here are possibly random and not representative !
2899/// let result = hub.sites().get("siteUrl")
2900///              .doit().await;
2901/// # }
2902/// ```
2903pub struct SiteGetCall<'a, C>
2904where
2905    C: 'a,
2906{
2907    hub: &'a Webmasters<C>,
2908    _site_url: String,
2909    _delegate: Option<&'a mut dyn common::Delegate>,
2910    _additional_params: HashMap<String, String>,
2911    _scopes: BTreeSet<String>,
2912}
2913
2914impl<'a, C> common::CallBuilder for SiteGetCall<'a, C> {}
2915
2916impl<'a, C> SiteGetCall<'a, C>
2917where
2918    C: common::Connector,
2919{
2920    /// Perform the operation you have build so far.
2921    pub async fn doit(mut self) -> common::Result<(common::Response, WmxSite)> {
2922        use std::borrow::Cow;
2923        use std::io::{Read, Seek};
2924
2925        use common::{url::Params, ToParts};
2926        use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
2927
2928        let mut dd = common::DefaultDelegate;
2929        let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
2930        dlg.begin(common::MethodInfo {
2931            id: "webmasters.sites.get",
2932            http_method: hyper::Method::GET,
2933        });
2934
2935        for &field in ["alt", "siteUrl"].iter() {
2936            if self._additional_params.contains_key(field) {
2937                dlg.finished(false);
2938                return Err(common::Error::FieldClash(field));
2939            }
2940        }
2941
2942        let mut params = Params::with_capacity(3 + self._additional_params.len());
2943        params.push("siteUrl", self._site_url);
2944
2945        params.extend(self._additional_params.iter());
2946
2947        params.push("alt", "json");
2948        let mut url = self.hub._base_url.clone() + "sites/{siteUrl}";
2949        if self._scopes.is_empty() {
2950            self._scopes.insert(Scope::Readonly.as_ref().to_string());
2951        }
2952
2953        #[allow(clippy::single_element_loop)]
2954        for &(find_this, param_name) in [("{siteUrl}", "siteUrl")].iter() {
2955            url = params.uri_replacement(url, param_name, find_this, false);
2956        }
2957        {
2958            let to_remove = ["siteUrl"];
2959            params.remove_params(&to_remove);
2960        }
2961
2962        let url = params.parse_with_url(&url);
2963
2964        loop {
2965            let token = match self
2966                .hub
2967                .auth
2968                .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
2969                .await
2970            {
2971                Ok(token) => token,
2972                Err(e) => match dlg.token(e) {
2973                    Ok(token) => token,
2974                    Err(e) => {
2975                        dlg.finished(false);
2976                        return Err(common::Error::MissingToken(e));
2977                    }
2978                },
2979            };
2980            let mut req_result = {
2981                let client = &self.hub.client;
2982                dlg.pre_request();
2983                let mut req_builder = hyper::Request::builder()
2984                    .method(hyper::Method::GET)
2985                    .uri(url.as_str())
2986                    .header(USER_AGENT, self.hub._user_agent.clone());
2987
2988                if let Some(token) = token.as_ref() {
2989                    req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
2990                }
2991
2992                let request = req_builder
2993                    .header(CONTENT_LENGTH, 0_u64)
2994                    .body(common::to_body::<String>(None));
2995
2996                client.request(request.unwrap()).await
2997            };
2998
2999            match req_result {
3000                Err(err) => {
3001                    if let common::Retry::After(d) = dlg.http_error(&err) {
3002                        sleep(d).await;
3003                        continue;
3004                    }
3005                    dlg.finished(false);
3006                    return Err(common::Error::HttpError(err));
3007                }
3008                Ok(res) => {
3009                    let (mut parts, body) = res.into_parts();
3010                    let mut body = common::Body::new(body);
3011                    if !parts.status.is_success() {
3012                        let bytes = common::to_bytes(body).await.unwrap_or_default();
3013                        let error = serde_json::from_str(&common::to_string(&bytes));
3014                        let response = common::to_response(parts, bytes.into());
3015
3016                        if let common::Retry::After(d) =
3017                            dlg.http_failure(&response, error.as_ref().ok())
3018                        {
3019                            sleep(d).await;
3020                            continue;
3021                        }
3022
3023                        dlg.finished(false);
3024
3025                        return Err(match error {
3026                            Ok(value) => common::Error::BadRequest(value),
3027                            _ => common::Error::Failure(response),
3028                        });
3029                    }
3030                    let response = {
3031                        let bytes = common::to_bytes(body).await.unwrap_or_default();
3032                        let encoded = common::to_string(&bytes);
3033                        match serde_json::from_str(&encoded) {
3034                            Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
3035                            Err(error) => {
3036                                dlg.response_json_decode_error(&encoded, &error);
3037                                return Err(common::Error::JsonDecodeError(
3038                                    encoded.to_string(),
3039                                    error,
3040                                ));
3041                            }
3042                        }
3043                    };
3044
3045                    dlg.finished(true);
3046                    return Ok(response);
3047                }
3048            }
3049        }
3050    }
3051
3052    /// The URI of the property as defined in Search Console. Examples: http://www.example.com/ or android-app://com.example/ Note: for property-sets, use the URI that starts with sc-set: which is used in Search Console URLs.
3053    ///
3054    /// Sets the *site url* path property to the given value.
3055    ///
3056    /// Even though the property as already been set when instantiating this call,
3057    /// we provide this method for API completeness.
3058    pub fn site_url(mut self, new_value: &str) -> SiteGetCall<'a, C> {
3059        self._site_url = new_value.to_string();
3060        self
3061    }
3062    /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
3063    /// while executing the actual API request.
3064    ///
3065    /// ````text
3066    ///                   It should be used to handle progress information, and to implement a certain level of resilience.
3067    /// ````
3068    ///
3069    /// Sets the *delegate* property to the given value.
3070    pub fn delegate(mut self, new_value: &'a mut dyn common::Delegate) -> SiteGetCall<'a, C> {
3071        self._delegate = Some(new_value);
3072        self
3073    }
3074
3075    /// Set any additional parameter of the query string used in the request.
3076    /// It should be used to set parameters which are not yet available through their own
3077    /// setters.
3078    ///
3079    /// Please note that this method must not be used to set any of the known parameters
3080    /// which have their own setter method. If done anyway, the request will fail.
3081    ///
3082    /// # Additional Parameters
3083    ///
3084    /// * *alt* (query-string) - Data format for the response.
3085    /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
3086    /// * *key* (query-string) - API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.
3087    /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
3088    /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
3089    /// * *quotaUser* (query-string) - An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
3090    /// * *userIp* (query-string) - Deprecated. Please use quotaUser instead.
3091    pub fn param<T>(mut self, name: T, value: T) -> SiteGetCall<'a, C>
3092    where
3093        T: AsRef<str>,
3094    {
3095        self._additional_params
3096            .insert(name.as_ref().to_string(), value.as_ref().to_string());
3097        self
3098    }
3099
3100    /// Identifies the authorization scope for the method you are building.
3101    ///
3102    /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
3103    /// [`Scope::Readonly`].
3104    ///
3105    /// The `scope` will be added to a set of scopes. This is important as one can maintain access
3106    /// tokens for more than one scope.
3107    ///
3108    /// Usually there is more than one suitable scope to authorize an operation, some of which may
3109    /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
3110    /// sufficient, a read-write scope will do as well.
3111    pub fn add_scope<St>(mut self, scope: St) -> SiteGetCall<'a, C>
3112    where
3113        St: AsRef<str>,
3114    {
3115        self._scopes.insert(String::from(scope.as_ref()));
3116        self
3117    }
3118    /// Identifies the authorization scope(s) for the method you are building.
3119    ///
3120    /// See [`Self::add_scope()`] for details.
3121    pub fn add_scopes<I, St>(mut self, scopes: I) -> SiteGetCall<'a, C>
3122    where
3123        I: IntoIterator<Item = St>,
3124        St: AsRef<str>,
3125    {
3126        self._scopes
3127            .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
3128        self
3129    }
3130
3131    /// Removes all scopes, and no default scope will be used either.
3132    /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
3133    /// for details).
3134    pub fn clear_scopes(mut self) -> SiteGetCall<'a, C> {
3135        self._scopes.clear();
3136        self
3137    }
3138}
3139
3140/// Lists the user's Search Console sites.
3141///
3142/// A builder for the *list* method supported by a *site* resource.
3143/// It is not used directly, but through a [`SiteMethods`] instance.
3144///
3145/// # Example
3146///
3147/// Instantiate a resource method builder
3148///
3149/// ```test_harness,no_run
3150/// # extern crate hyper;
3151/// # extern crate hyper_rustls;
3152/// # extern crate google_webmasters3 as webmasters3;
3153/// # async fn dox() {
3154/// # use webmasters3::{Webmasters, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
3155///
3156/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
3157/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
3158/// #     .with_native_roots()
3159/// #     .unwrap()
3160/// #     .https_only()
3161/// #     .enable_http2()
3162/// #     .build();
3163///
3164/// # let executor = hyper_util::rt::TokioExecutor::new();
3165/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
3166/// #     secret,
3167/// #     yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
3168/// #     yup_oauth2::client::CustomHyperClientBuilder::from(
3169/// #         hyper_util::client::legacy::Client::builder(executor).build(connector),
3170/// #     ),
3171/// # ).build().await.unwrap();
3172///
3173/// # let client = hyper_util::client::legacy::Client::builder(
3174/// #     hyper_util::rt::TokioExecutor::new()
3175/// # )
3176/// # .build(
3177/// #     hyper_rustls::HttpsConnectorBuilder::new()
3178/// #         .with_native_roots()
3179/// #         .unwrap()
3180/// #         .https_or_http()
3181/// #         .enable_http2()
3182/// #         .build()
3183/// # );
3184/// # let mut hub = Webmasters::new(client, auth);
3185/// // You can configure optional parameters by calling the respective setters at will, and
3186/// // execute the final call using `doit()`.
3187/// // Values shown here are possibly random and not representative !
3188/// let result = hub.sites().list()
3189///              .doit().await;
3190/// # }
3191/// ```
3192pub struct SiteListCall<'a, C>
3193where
3194    C: 'a,
3195{
3196    hub: &'a Webmasters<C>,
3197    _delegate: Option<&'a mut dyn common::Delegate>,
3198    _additional_params: HashMap<String, String>,
3199    _scopes: BTreeSet<String>,
3200}
3201
3202impl<'a, C> common::CallBuilder for SiteListCall<'a, C> {}
3203
3204impl<'a, C> SiteListCall<'a, C>
3205where
3206    C: common::Connector,
3207{
3208    /// Perform the operation you have build so far.
3209    pub async fn doit(mut self) -> common::Result<(common::Response, SitesListResponse)> {
3210        use std::borrow::Cow;
3211        use std::io::{Read, Seek};
3212
3213        use common::{url::Params, ToParts};
3214        use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
3215
3216        let mut dd = common::DefaultDelegate;
3217        let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
3218        dlg.begin(common::MethodInfo {
3219            id: "webmasters.sites.list",
3220            http_method: hyper::Method::GET,
3221        });
3222
3223        for &field in ["alt"].iter() {
3224            if self._additional_params.contains_key(field) {
3225                dlg.finished(false);
3226                return Err(common::Error::FieldClash(field));
3227            }
3228        }
3229
3230        let mut params = Params::with_capacity(2 + self._additional_params.len());
3231
3232        params.extend(self._additional_params.iter());
3233
3234        params.push("alt", "json");
3235        let mut url = self.hub._base_url.clone() + "sites";
3236        if self._scopes.is_empty() {
3237            self._scopes.insert(Scope::Readonly.as_ref().to_string());
3238        }
3239
3240        let url = params.parse_with_url(&url);
3241
3242        loop {
3243            let token = match self
3244                .hub
3245                .auth
3246                .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
3247                .await
3248            {
3249                Ok(token) => token,
3250                Err(e) => match dlg.token(e) {
3251                    Ok(token) => token,
3252                    Err(e) => {
3253                        dlg.finished(false);
3254                        return Err(common::Error::MissingToken(e));
3255                    }
3256                },
3257            };
3258            let mut req_result = {
3259                let client = &self.hub.client;
3260                dlg.pre_request();
3261                let mut req_builder = hyper::Request::builder()
3262                    .method(hyper::Method::GET)
3263                    .uri(url.as_str())
3264                    .header(USER_AGENT, self.hub._user_agent.clone());
3265
3266                if let Some(token) = token.as_ref() {
3267                    req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
3268                }
3269
3270                let request = req_builder
3271                    .header(CONTENT_LENGTH, 0_u64)
3272                    .body(common::to_body::<String>(None));
3273
3274                client.request(request.unwrap()).await
3275            };
3276
3277            match req_result {
3278                Err(err) => {
3279                    if let common::Retry::After(d) = dlg.http_error(&err) {
3280                        sleep(d).await;
3281                        continue;
3282                    }
3283                    dlg.finished(false);
3284                    return Err(common::Error::HttpError(err));
3285                }
3286                Ok(res) => {
3287                    let (mut parts, body) = res.into_parts();
3288                    let mut body = common::Body::new(body);
3289                    if !parts.status.is_success() {
3290                        let bytes = common::to_bytes(body).await.unwrap_or_default();
3291                        let error = serde_json::from_str(&common::to_string(&bytes));
3292                        let response = common::to_response(parts, bytes.into());
3293
3294                        if let common::Retry::After(d) =
3295                            dlg.http_failure(&response, error.as_ref().ok())
3296                        {
3297                            sleep(d).await;
3298                            continue;
3299                        }
3300
3301                        dlg.finished(false);
3302
3303                        return Err(match error {
3304                            Ok(value) => common::Error::BadRequest(value),
3305                            _ => common::Error::Failure(response),
3306                        });
3307                    }
3308                    let response = {
3309                        let bytes = common::to_bytes(body).await.unwrap_or_default();
3310                        let encoded = common::to_string(&bytes);
3311                        match serde_json::from_str(&encoded) {
3312                            Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
3313                            Err(error) => {
3314                                dlg.response_json_decode_error(&encoded, &error);
3315                                return Err(common::Error::JsonDecodeError(
3316                                    encoded.to_string(),
3317                                    error,
3318                                ));
3319                            }
3320                        }
3321                    };
3322
3323                    dlg.finished(true);
3324                    return Ok(response);
3325                }
3326            }
3327        }
3328    }
3329
3330    /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
3331    /// while executing the actual API request.
3332    ///
3333    /// ````text
3334    ///                   It should be used to handle progress information, and to implement a certain level of resilience.
3335    /// ````
3336    ///
3337    /// Sets the *delegate* property to the given value.
3338    pub fn delegate(mut self, new_value: &'a mut dyn common::Delegate) -> SiteListCall<'a, C> {
3339        self._delegate = Some(new_value);
3340        self
3341    }
3342
3343    /// Set any additional parameter of the query string used in the request.
3344    /// It should be used to set parameters which are not yet available through their own
3345    /// setters.
3346    ///
3347    /// Please note that this method must not be used to set any of the known parameters
3348    /// which have their own setter method. If done anyway, the request will fail.
3349    ///
3350    /// # Additional Parameters
3351    ///
3352    /// * *alt* (query-string) - Data format for the response.
3353    /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
3354    /// * *key* (query-string) - API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.
3355    /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
3356    /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
3357    /// * *quotaUser* (query-string) - An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
3358    /// * *userIp* (query-string) - Deprecated. Please use quotaUser instead.
3359    pub fn param<T>(mut self, name: T, value: T) -> SiteListCall<'a, C>
3360    where
3361        T: AsRef<str>,
3362    {
3363        self._additional_params
3364            .insert(name.as_ref().to_string(), value.as_ref().to_string());
3365        self
3366    }
3367
3368    /// Identifies the authorization scope for the method you are building.
3369    ///
3370    /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
3371    /// [`Scope::Readonly`].
3372    ///
3373    /// The `scope` will be added to a set of scopes. This is important as one can maintain access
3374    /// tokens for more than one scope.
3375    ///
3376    /// Usually there is more than one suitable scope to authorize an operation, some of which may
3377    /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
3378    /// sufficient, a read-write scope will do as well.
3379    pub fn add_scope<St>(mut self, scope: St) -> SiteListCall<'a, C>
3380    where
3381        St: AsRef<str>,
3382    {
3383        self._scopes.insert(String::from(scope.as_ref()));
3384        self
3385    }
3386    /// Identifies the authorization scope(s) for the method you are building.
3387    ///
3388    /// See [`Self::add_scope()`] for details.
3389    pub fn add_scopes<I, St>(mut self, scopes: I) -> SiteListCall<'a, C>
3390    where
3391        I: IntoIterator<Item = St>,
3392        St: AsRef<str>,
3393    {
3394        self._scopes
3395            .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
3396        self
3397    }
3398
3399    /// Removes all scopes, and no default scope will be used either.
3400    /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
3401    /// for details).
3402    pub fn clear_scopes(mut self) -> SiteListCall<'a, C> {
3403        self._scopes.clear();
3404        self
3405    }
3406}