google_gmailpostmastertools1_beta1/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 /// See email traffic metrics for the domains you have registered in Gmail Postmaster Tools
17 PostmasterReadonly,
18}
19
20impl AsRef<str> for Scope {
21 fn as_ref(&self) -> &str {
22 match *self {
23 Scope::PostmasterReadonly => "https://www.googleapis.com/auth/postmaster.readonly",
24 }
25 }
26}
27
28#[allow(clippy::derivable_impls)]
29impl Default for Scope {
30 fn default() -> Scope {
31 Scope::PostmasterReadonly
32 }
33}
34
35// ########
36// HUB ###
37// ######
38
39/// Central instance to access all PostmasterTools related resource activities
40///
41/// # Examples
42///
43/// Instantiate a new hub
44///
45/// ```test_harness,no_run
46/// extern crate hyper;
47/// extern crate hyper_rustls;
48/// extern crate google_gmailpostmastertools1_beta1 as gmailpostmastertools1_beta1;
49/// use gmailpostmastertools1_beta1::{Result, Error};
50/// # async fn dox() {
51/// use gmailpostmastertools1_beta1::{PostmasterTools, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
52///
53/// // Get an ApplicationSecret instance by some means. It contains the `client_id` and
54/// // `client_secret`, among other things.
55/// let secret: yup_oauth2::ApplicationSecret = Default::default();
56/// // Instantiate the authenticator. It will choose a suitable authentication flow for you,
57/// // unless you replace `None` with the desired Flow.
58/// // Provide your own `AuthenticatorDelegate` to adjust the way it operates and get feedback about
59/// // what's going on. You probably want to bring in your own `TokenStorage` to persist tokens and
60/// // retrieve them from storage.
61/// let connector = hyper_rustls::HttpsConnectorBuilder::new()
62/// .with_native_roots()
63/// .unwrap()
64/// .https_only()
65/// .enable_http2()
66/// .build();
67///
68/// let executor = hyper_util::rt::TokioExecutor::new();
69/// let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
70/// secret,
71/// yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
72/// yup_oauth2::client::CustomHyperClientBuilder::from(
73/// hyper_util::client::legacy::Client::builder(executor).build(connector),
74/// ),
75/// ).build().await.unwrap();
76///
77/// let client = hyper_util::client::legacy::Client::builder(
78/// hyper_util::rt::TokioExecutor::new()
79/// )
80/// .build(
81/// hyper_rustls::HttpsConnectorBuilder::new()
82/// .with_native_roots()
83/// .unwrap()
84/// .https_or_http()
85/// .enable_http2()
86/// .build()
87/// );
88/// let mut hub = PostmasterTools::new(client, auth);
89/// // You can configure optional parameters by calling the respective setters at will, and
90/// // execute the final call using `doit()`.
91/// // Values shown here are possibly random and not representative !
92/// let result = hub.domains().traffic_stats_list("parent")
93/// .start_date_year(-55)
94/// .start_date_month(-88)
95/// .start_date_day(-47)
96/// .page_token("duo")
97/// .page_size(-50)
98/// .end_date_year(-93)
99/// .end_date_month(-37)
100/// .end_date_day(-12)
101/// .doit().await;
102///
103/// match result {
104/// Err(e) => match e {
105/// // The Error enum provides details about what exactly happened.
106/// // You can also just use its `Debug`, `Display` or `Error` traits
107/// Error::HttpError(_)
108/// |Error::Io(_)
109/// |Error::MissingAPIKey
110/// |Error::MissingToken(_)
111/// |Error::Cancelled
112/// |Error::UploadSizeLimitExceeded(_, _)
113/// |Error::Failure(_)
114/// |Error::BadRequest(_)
115/// |Error::FieldClash(_)
116/// |Error::JsonDecodeError(_, _) => println!("{}", e),
117/// },
118/// Ok(res) => println!("Success: {:?}", res),
119/// }
120/// # }
121/// ```
122#[derive(Clone)]
123pub struct PostmasterTools<C> {
124 pub client: common::Client<C>,
125 pub auth: Box<dyn common::GetToken>,
126 _user_agent: String,
127 _base_url: String,
128 _root_url: String,
129}
130
131impl<C> common::Hub for PostmasterTools<C> {}
132
133impl<'a, C> PostmasterTools<C> {
134 pub fn new<A: 'static + common::GetToken>(
135 client: common::Client<C>,
136 auth: A,
137 ) -> PostmasterTools<C> {
138 PostmasterTools {
139 client,
140 auth: Box::new(auth),
141 _user_agent: "google-api-rust-client/7.0.0".to_string(),
142 _base_url: "https://gmailpostmastertools.googleapis.com/".to_string(),
143 _root_url: "https://gmailpostmastertools.googleapis.com/".to_string(),
144 }
145 }
146
147 pub fn domains(&'a self) -> DomainMethods<'a, C> {
148 DomainMethods { hub: self }
149 }
150
151 /// Set the user-agent header field to use in all requests to the server.
152 /// It defaults to `google-api-rust-client/7.0.0`.
153 ///
154 /// Returns the previously set user-agent.
155 pub fn user_agent(&mut self, agent_name: String) -> String {
156 std::mem::replace(&mut self._user_agent, agent_name)
157 }
158
159 /// Set the base url to use in all requests to the server.
160 /// It defaults to `https://gmailpostmastertools.googleapis.com/`.
161 ///
162 /// Returns the previously set base url.
163 pub fn base_url(&mut self, new_base_url: String) -> String {
164 std::mem::replace(&mut self._base_url, new_base_url)
165 }
166
167 /// Set the root url to use in all requests to the server.
168 /// It defaults to `https://gmailpostmastertools.googleapis.com/`.
169 ///
170 /// Returns the previously set root url.
171 pub fn root_url(&mut self, new_root_url: String) -> String {
172 std::mem::replace(&mut self._root_url, new_root_url)
173 }
174}
175
176// ############
177// SCHEMAS ###
178// ##########
179/// Metric on a particular delivery error type.
180///
181/// This type is not used in any activity, and only used as *part* of another schema.
182///
183#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
184#[serde_with::serde_as]
185#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
186pub struct DeliveryError {
187 /// The class of delivery error.
188 #[serde(rename = "errorClass")]
189 pub error_class: Option<String>,
190 /// The ratio of messages where the error occurred vs all authenticated traffic.
191 #[serde(rename = "errorRatio")]
192 pub error_ratio: Option<f64>,
193 /// The type of delivery error.
194 #[serde(rename = "errorType")]
195 pub error_type: Option<String>,
196}
197
198impl common::Part for DeliveryError {}
199
200/// A registered domain resource in the Postmaster API.
201///
202/// # Activities
203///
204/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
205/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
206///
207/// * [traffic stats get domains](DomainTrafficStatGetCall) (none)
208/// * [traffic stats list domains](DomainTrafficStatListCall) (none)
209/// * [get domains](DomainGetCall) (response)
210/// * [list domains](DomainListCall) (none)
211#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
212#[serde_with::serde_as]
213#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
214pub struct Domain {
215 /// Timestamp when the user registered this domain. Assigned by the server.
216 #[serde(rename = "createTime")]
217 pub create_time: Option<chrono::DateTime<chrono::offset::Utc>>,
218 /// The resource name of the Domain. Domain names have the form `domains/{domain_name}`, where domain_name is the fully qualified domain name (i.e., mymail.mydomain.com).
219 pub name: Option<String>,
220 /// User’s permission for this domain. Assigned by the server.
221 pub permission: Option<String>,
222}
223
224impl common::Resource for Domain {}
225impl common::ResponseResult for Domain {}
226
227/// [Feedback loop](https://support.google.com/mail/answer/6254652) identifier information.
228///
229/// This type is not used in any activity, and only used as *part* of another schema.
230///
231#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
232#[serde_with::serde_as]
233#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
234pub struct FeedbackLoop {
235 /// Feedback loop identifier that uniquely identifies individual campaigns.
236 pub id: Option<String>,
237 /// The ratio of user marked spam messages with the identifier vs the total number of inboxed messages with that identifier.
238 #[serde(rename = "spamRatio")]
239 pub spam_ratio: Option<f64>,
240}
241
242impl common::Part for FeedbackLoop {}
243
244/// IP Reputation information for a set of IPs in a specific reputation category.
245///
246/// This type is not used in any activity, and only used as *part* of another schema.
247///
248#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
249#[serde_with::serde_as]
250#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
251pub struct IpReputation {
252 /// Total number of unique IPs in this reputation category. This metric only pertains to traffic that passed [SPF](http://www.openspf.org/) or [DKIM](http://www.dkim.org/).
253 #[serde(rename = "ipCount")]
254 #[serde_as(as = "Option<serde_with::DisplayFromStr>")]
255 pub ip_count: Option<i64>,
256 /// Total number of unique IPs in this reputation category. This metric only pertains to traffic that passed [SPF](http://www.openspf.org/) or [DKIM](http://www.dkim.org/). Deprecated to be complied with ApiLinter for Quantities. Use ip_count instead.
257 #[serde(rename = "numIps")]
258 #[serde_as(as = "Option<serde_with::DisplayFromStr>")]
259 pub num_ips: Option<i64>,
260 /// The reputation category this IP reputation represents.
261 pub reputation: Option<String>,
262 /// A sample of IPs in this reputation category.
263 #[serde(rename = "sampleIps")]
264 pub sample_ips: Option<Vec<String>>,
265}
266
267impl common::Part for IpReputation {}
268
269/// Response message for ListDomains.
270///
271/// # Activities
272///
273/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
274/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
275///
276/// * [list domains](DomainListCall) (response)
277#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
278#[serde_with::serde_as]
279#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
280pub struct ListDomainsResponse {
281 /// The list of domains.
282 pub domains: Option<Vec<Domain>>,
283 /// Token to retrieve the next page of results, or empty if there are no more results in the list.
284 #[serde(rename = "nextPageToken")]
285 pub next_page_token: Option<String>,
286}
287
288impl common::ResponseResult for ListDomainsResponse {}
289
290/// Response message for ListTrafficStats.
291///
292/// # Activities
293///
294/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
295/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
296///
297/// * [traffic stats list domains](DomainTrafficStatListCall) (response)
298#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
299#[serde_with::serde_as]
300#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
301pub struct ListTrafficStatsResponse {
302 /// Token to retrieve the next page of results, or empty if there are no more results in the list.
303 #[serde(rename = "nextPageToken")]
304 pub next_page_token: Option<String>,
305 /// The list of TrafficStats.
306 #[serde(rename = "trafficStats")]
307 pub traffic_stats: Option<Vec<TrafficStats>>,
308}
309
310impl common::ResponseResult for ListTrafficStatsResponse {}
311
312/// Email traffic statistics pertaining to a specific date.
313///
314/// # Activities
315///
316/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
317/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
318///
319/// * [traffic stats get domains](DomainTrafficStatGetCall) (response)
320#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
321#[serde_with::serde_as]
322#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
323pub struct TrafficStats {
324 /// Delivery errors for the domain. This metric only pertains to traffic that passed [SPF](http://www.openspf.org/) or [DKIM](http://www.dkim.org/).
325 #[serde(rename = "deliveryErrors")]
326 pub delivery_errors: Option<Vec<DeliveryError>>,
327 /// The ratio of mail that successfully authenticated with DKIM vs. all mail that attempted to authenticate with [DKIM](http://www.dkim.org/). Spoofed mail is excluded.
328 #[serde(rename = "dkimSuccessRatio")]
329 pub dkim_success_ratio: Option<f64>,
330 /// The ratio of mail that passed [DMARC](https://dmarc.org/) alignment checks vs all mail received from the domain that successfully authenticated with either of [SPF](http://www.openspf.org/) or [DKIM](http://www.dkim.org/).
331 #[serde(rename = "dmarcSuccessRatio")]
332 pub dmarc_success_ratio: Option<f64>,
333 /// Reputation of the domain.
334 #[serde(rename = "domainReputation")]
335 pub domain_reputation: Option<String>,
336 /// The ratio of incoming mail (to Gmail), that passed secure transport (TLS) vs all mail received from that domain. This metric only pertains to traffic that passed [SPF](http://www.openspf.org/) or [DKIM](http://www.dkim.org/).
337 #[serde(rename = "inboundEncryptionRatio")]
338 pub inbound_encryption_ratio: Option<f64>,
339 /// Reputation information pertaining to the IP addresses of the email servers for the domain. There is exactly one entry for each reputation category except REPUTATION_CATEGORY_UNSPECIFIED.
340 #[serde(rename = "ipReputations")]
341 pub ip_reputations: Option<Vec<IpReputation>>,
342 /// The resource name of the traffic statistics. Traffic statistic names have the form `domains/{domain}/trafficStats/{date}`, where domain_name is the fully qualified domain name (i.e., mymail.mydomain.com) of the domain this traffic statistics pertains to and date is the date in yyyymmdd format that these statistics corresponds to. For example: domains/mymail.mydomain.com/trafficStats/20160807
343 pub name: Option<String>,
344 /// The ratio of outgoing mail (from Gmail) that was accepted over secure transport (TLS).
345 #[serde(rename = "outboundEncryptionRatio")]
346 pub outbound_encryption_ratio: Option<f64>,
347 /// Spammy [Feedback loop identifiers] (https://support.google.com/mail/answer/6254652) with their individual spam rates. This metric only pertains to traffic that is authenticated by [DKIM](http://www.dkim.org/).
348 #[serde(rename = "spammyFeedbackLoops")]
349 pub spammy_feedback_loops: Option<Vec<FeedbackLoop>>,
350 /// The ratio of mail that successfully authenticated with SPF vs. all mail that attempted to authenticate with [SPF](http://www.openspf.org/). Spoofed mail is excluded.
351 #[serde(rename = "spfSuccessRatio")]
352 pub spf_success_ratio: Option<f64>,
353 /// The ratio of user-report spam vs. email that was sent to the inbox. This is potentially inexact -- users may want to refer to the description of the interval fields userReportedSpamRatioLowerBound and userReportedSpamRatioUpperBound for more explicit accuracy guarantees. This metric only pertains to emails authenticated by [DKIM](http://www.dkim.org/).
354 #[serde(rename = "userReportedSpamRatio")]
355 pub user_reported_spam_ratio: Option<f64>,
356 /// The lower bound of the confidence interval for the user reported spam ratio. If this field is set, then the value of userReportedSpamRatio is set to the midpoint of this interval and is thus inexact. However, the true ratio is guaranteed to be in between this lower bound and the corresponding upper bound 95% of the time. This metric only pertains to emails authenticated by [DKIM](http://www.dkim.org/).
357 #[serde(rename = "userReportedSpamRatioLowerBound")]
358 pub user_reported_spam_ratio_lower_bound: Option<f64>,
359 /// The upper bound of the confidence interval for the user reported spam ratio. If this field is set, then the value of userReportedSpamRatio is set to the midpoint of this interval and is thus inexact. However, the true ratio is guaranteed to be in between this upper bound and the corresponding lower bound 95% of the time. This metric only pertains to emails authenticated by [DKIM](http://www.dkim.org/).
360 #[serde(rename = "userReportedSpamRatioUpperBound")]
361 pub user_reported_spam_ratio_upper_bound: Option<f64>,
362}
363
364impl common::ResponseResult for TrafficStats {}
365
366// ###################
367// MethodBuilders ###
368// #################
369
370/// A builder providing access to all methods supported on *domain* resources.
371/// It is not used directly, but through the [`PostmasterTools`] hub.
372///
373/// # Example
374///
375/// Instantiate a resource builder
376///
377/// ```test_harness,no_run
378/// extern crate hyper;
379/// extern crate hyper_rustls;
380/// extern crate google_gmailpostmastertools1_beta1 as gmailpostmastertools1_beta1;
381///
382/// # async fn dox() {
383/// use gmailpostmastertools1_beta1::{PostmasterTools, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
384///
385/// let secret: yup_oauth2::ApplicationSecret = Default::default();
386/// let connector = hyper_rustls::HttpsConnectorBuilder::new()
387/// .with_native_roots()
388/// .unwrap()
389/// .https_only()
390/// .enable_http2()
391/// .build();
392///
393/// let executor = hyper_util::rt::TokioExecutor::new();
394/// let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
395/// secret,
396/// yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
397/// yup_oauth2::client::CustomHyperClientBuilder::from(
398/// hyper_util::client::legacy::Client::builder(executor).build(connector),
399/// ),
400/// ).build().await.unwrap();
401///
402/// let client = hyper_util::client::legacy::Client::builder(
403/// hyper_util::rt::TokioExecutor::new()
404/// )
405/// .build(
406/// hyper_rustls::HttpsConnectorBuilder::new()
407/// .with_native_roots()
408/// .unwrap()
409/// .https_or_http()
410/// .enable_http2()
411/// .build()
412/// );
413/// let mut hub = PostmasterTools::new(client, auth);
414/// // Usually you wouldn't bind this to a variable, but keep calling *CallBuilders*
415/// // like `get(...)`, `list(...)`, `traffic_stats_get(...)` and `traffic_stats_list(...)`
416/// // to build up your call.
417/// let rb = hub.domains();
418/// # }
419/// ```
420pub struct DomainMethods<'a, C>
421where
422 C: 'a,
423{
424 hub: &'a PostmasterTools<C>,
425}
426
427impl<'a, C> common::MethodsBuilder for DomainMethods<'a, C> {}
428
429impl<'a, C> DomainMethods<'a, C> {
430 /// Create a builder to help you perform the following task:
431 ///
432 /// Get traffic statistics for a domain on a specific date. Returns PERMISSION_DENIED if user does not have permission to access TrafficStats for the domain.
433 ///
434 /// # Arguments
435 ///
436 /// * `name` - The resource name of the traffic statistics to get. E.g., domains/mymail.mydomain.com/trafficStats/20160807.
437 pub fn traffic_stats_get(&self, name: &str) -> DomainTrafficStatGetCall<'a, C> {
438 DomainTrafficStatGetCall {
439 hub: self.hub,
440 _name: name.to_string(),
441 _delegate: Default::default(),
442 _additional_params: Default::default(),
443 _scopes: Default::default(),
444 }
445 }
446
447 /// Create a builder to help you perform the following task:
448 ///
449 /// List traffic statistics for all available days. Returns PERMISSION_DENIED if user does not have permission to access TrafficStats for the domain.
450 ///
451 /// # Arguments
452 ///
453 /// * `parent` - The resource name of the domain whose traffic statistics we'd like to list. It should have the form `domains/{domain_name}`, where domain_name is the fully qualified domain name.
454 pub fn traffic_stats_list(&self, parent: &str) -> DomainTrafficStatListCall<'a, C> {
455 DomainTrafficStatListCall {
456 hub: self.hub,
457 _parent: parent.to_string(),
458 _start_date_year: Default::default(),
459 _start_date_month: Default::default(),
460 _start_date_day: Default::default(),
461 _page_token: Default::default(),
462 _page_size: Default::default(),
463 _end_date_year: Default::default(),
464 _end_date_month: Default::default(),
465 _end_date_day: Default::default(),
466 _delegate: Default::default(),
467 _additional_params: Default::default(),
468 _scopes: Default::default(),
469 }
470 }
471
472 /// Create a builder to help you perform the following task:
473 ///
474 /// Gets a specific domain registered by the client. Returns NOT_FOUND if the domain does not exist.
475 ///
476 /// # Arguments
477 ///
478 /// * `name` - The resource name of the domain. It should have the form `domains/{domain_name}`, where domain_name is the fully qualified domain name.
479 pub fn get(&self, name: &str) -> DomainGetCall<'a, C> {
480 DomainGetCall {
481 hub: self.hub,
482 _name: name.to_string(),
483 _delegate: Default::default(),
484 _additional_params: Default::default(),
485 _scopes: Default::default(),
486 }
487 }
488
489 /// Create a builder to help you perform the following task:
490 ///
491 /// Lists the domains that have been registered by the client. The order of domains in the response is unspecified and non-deterministic. Newly created domains will not necessarily be added to the end of this list.
492 pub fn list(&self) -> DomainListCall<'a, C> {
493 DomainListCall {
494 hub: self.hub,
495 _page_token: Default::default(),
496 _page_size: Default::default(),
497 _delegate: Default::default(),
498 _additional_params: Default::default(),
499 _scopes: Default::default(),
500 }
501 }
502}
503
504// ###################
505// CallBuilders ###
506// #################
507
508/// Get traffic statistics for a domain on a specific date. Returns PERMISSION_DENIED if user does not have permission to access TrafficStats for the domain.
509///
510/// A builder for the *trafficStats.get* method supported by a *domain* resource.
511/// It is not used directly, but through a [`DomainMethods`] instance.
512///
513/// # Example
514///
515/// Instantiate a resource method builder
516///
517/// ```test_harness,no_run
518/// # extern crate hyper;
519/// # extern crate hyper_rustls;
520/// # extern crate google_gmailpostmastertools1_beta1 as gmailpostmastertools1_beta1;
521/// # async fn dox() {
522/// # use gmailpostmastertools1_beta1::{PostmasterTools, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
523///
524/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
525/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
526/// # .with_native_roots()
527/// # .unwrap()
528/// # .https_only()
529/// # .enable_http2()
530/// # .build();
531///
532/// # let executor = hyper_util::rt::TokioExecutor::new();
533/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
534/// # secret,
535/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
536/// # yup_oauth2::client::CustomHyperClientBuilder::from(
537/// # hyper_util::client::legacy::Client::builder(executor).build(connector),
538/// # ),
539/// # ).build().await.unwrap();
540///
541/// # let client = hyper_util::client::legacy::Client::builder(
542/// # hyper_util::rt::TokioExecutor::new()
543/// # )
544/// # .build(
545/// # hyper_rustls::HttpsConnectorBuilder::new()
546/// # .with_native_roots()
547/// # .unwrap()
548/// # .https_or_http()
549/// # .enable_http2()
550/// # .build()
551/// # );
552/// # let mut hub = PostmasterTools::new(client, auth);
553/// // You can configure optional parameters by calling the respective setters at will, and
554/// // execute the final call using `doit()`.
555/// // Values shown here are possibly random and not representative !
556/// let result = hub.domains().traffic_stats_get("name")
557/// .doit().await;
558/// # }
559/// ```
560pub struct DomainTrafficStatGetCall<'a, C>
561where
562 C: 'a,
563{
564 hub: &'a PostmasterTools<C>,
565 _name: String,
566 _delegate: Option<&'a mut dyn common::Delegate>,
567 _additional_params: HashMap<String, String>,
568 _scopes: BTreeSet<String>,
569}
570
571impl<'a, C> common::CallBuilder for DomainTrafficStatGetCall<'a, C> {}
572
573impl<'a, C> DomainTrafficStatGetCall<'a, C>
574where
575 C: common::Connector,
576{
577 /// Perform the operation you have build so far.
578 pub async fn doit(mut self) -> common::Result<(common::Response, TrafficStats)> {
579 use std::borrow::Cow;
580 use std::io::{Read, Seek};
581
582 use common::{url::Params, ToParts};
583 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
584
585 let mut dd = common::DefaultDelegate;
586 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
587 dlg.begin(common::MethodInfo {
588 id: "gmailpostmastertools.domains.trafficStats.get",
589 http_method: hyper::Method::GET,
590 });
591
592 for &field in ["alt", "name"].iter() {
593 if self._additional_params.contains_key(field) {
594 dlg.finished(false);
595 return Err(common::Error::FieldClash(field));
596 }
597 }
598
599 let mut params = Params::with_capacity(3 + self._additional_params.len());
600 params.push("name", self._name);
601
602 params.extend(self._additional_params.iter());
603
604 params.push("alt", "json");
605 let mut url = self.hub._base_url.clone() + "v1beta1/{+name}";
606 if self._scopes.is_empty() {
607 self._scopes
608 .insert(Scope::PostmasterReadonly.as_ref().to_string());
609 }
610
611 #[allow(clippy::single_element_loop)]
612 for &(find_this, param_name) in [("{+name}", "name")].iter() {
613 url = params.uri_replacement(url, param_name, find_this, true);
614 }
615 {
616 let to_remove = ["name"];
617 params.remove_params(&to_remove);
618 }
619
620 let url = params.parse_with_url(&url);
621
622 loop {
623 let token = match self
624 .hub
625 .auth
626 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
627 .await
628 {
629 Ok(token) => token,
630 Err(e) => match dlg.token(e) {
631 Ok(token) => token,
632 Err(e) => {
633 dlg.finished(false);
634 return Err(common::Error::MissingToken(e));
635 }
636 },
637 };
638 let mut req_result = {
639 let client = &self.hub.client;
640 dlg.pre_request();
641 let mut req_builder = hyper::Request::builder()
642 .method(hyper::Method::GET)
643 .uri(url.as_str())
644 .header(USER_AGENT, self.hub._user_agent.clone());
645
646 if let Some(token) = token.as_ref() {
647 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
648 }
649
650 let request = req_builder
651 .header(CONTENT_LENGTH, 0_u64)
652 .body(common::to_body::<String>(None));
653
654 client.request(request.unwrap()).await
655 };
656
657 match req_result {
658 Err(err) => {
659 if let common::Retry::After(d) = dlg.http_error(&err) {
660 sleep(d).await;
661 continue;
662 }
663 dlg.finished(false);
664 return Err(common::Error::HttpError(err));
665 }
666 Ok(res) => {
667 let (mut parts, body) = res.into_parts();
668 let mut body = common::Body::new(body);
669 if !parts.status.is_success() {
670 let bytes = common::to_bytes(body).await.unwrap_or_default();
671 let error = serde_json::from_str(&common::to_string(&bytes));
672 let response = common::to_response(parts, bytes.into());
673
674 if let common::Retry::After(d) =
675 dlg.http_failure(&response, error.as_ref().ok())
676 {
677 sleep(d).await;
678 continue;
679 }
680
681 dlg.finished(false);
682
683 return Err(match error {
684 Ok(value) => common::Error::BadRequest(value),
685 _ => common::Error::Failure(response),
686 });
687 }
688 let response = {
689 let bytes = common::to_bytes(body).await.unwrap_or_default();
690 let encoded = common::to_string(&bytes);
691 match serde_json::from_str(&encoded) {
692 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
693 Err(error) => {
694 dlg.response_json_decode_error(&encoded, &error);
695 return Err(common::Error::JsonDecodeError(
696 encoded.to_string(),
697 error,
698 ));
699 }
700 }
701 };
702
703 dlg.finished(true);
704 return Ok(response);
705 }
706 }
707 }
708 }
709
710 /// The resource name of the traffic statistics to get. E.g., domains/mymail.mydomain.com/trafficStats/20160807.
711 ///
712 /// Sets the *name* path property to the given value.
713 ///
714 /// Even though the property as already been set when instantiating this call,
715 /// we provide this method for API completeness.
716 pub fn name(mut self, new_value: &str) -> DomainTrafficStatGetCall<'a, C> {
717 self._name = new_value.to_string();
718 self
719 }
720 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
721 /// while executing the actual API request.
722 ///
723 /// ````text
724 /// It should be used to handle progress information, and to implement a certain level of resilience.
725 /// ````
726 ///
727 /// Sets the *delegate* property to the given value.
728 pub fn delegate(
729 mut self,
730 new_value: &'a mut dyn common::Delegate,
731 ) -> DomainTrafficStatGetCall<'a, C> {
732 self._delegate = Some(new_value);
733 self
734 }
735
736 /// Set any additional parameter of the query string used in the request.
737 /// It should be used to set parameters which are not yet available through their own
738 /// setters.
739 ///
740 /// Please note that this method must not be used to set any of the known parameters
741 /// which have their own setter method. If done anyway, the request will fail.
742 ///
743 /// # Additional Parameters
744 ///
745 /// * *$.xgafv* (query-string) - V1 error format.
746 /// * *access_token* (query-string) - OAuth access token.
747 /// * *alt* (query-string) - Data format for response.
748 /// * *callback* (query-string) - JSONP
749 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
750 /// * *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.
751 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
752 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
753 /// * *quotaUser* (query-string) - Available to use for quota purposes for server-side applications. Can be any arbitrary string assigned to a user, but should not exceed 40 characters.
754 /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
755 /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
756 pub fn param<T>(mut self, name: T, value: T) -> DomainTrafficStatGetCall<'a, C>
757 where
758 T: AsRef<str>,
759 {
760 self._additional_params
761 .insert(name.as_ref().to_string(), value.as_ref().to_string());
762 self
763 }
764
765 /// Identifies the authorization scope for the method you are building.
766 ///
767 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
768 /// [`Scope::PostmasterReadonly`].
769 ///
770 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
771 /// tokens for more than one scope.
772 ///
773 /// Usually there is more than one suitable scope to authorize an operation, some of which may
774 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
775 /// sufficient, a read-write scope will do as well.
776 pub fn add_scope<St>(mut self, scope: St) -> DomainTrafficStatGetCall<'a, C>
777 where
778 St: AsRef<str>,
779 {
780 self._scopes.insert(String::from(scope.as_ref()));
781 self
782 }
783 /// Identifies the authorization scope(s) for the method you are building.
784 ///
785 /// See [`Self::add_scope()`] for details.
786 pub fn add_scopes<I, St>(mut self, scopes: I) -> DomainTrafficStatGetCall<'a, C>
787 where
788 I: IntoIterator<Item = St>,
789 St: AsRef<str>,
790 {
791 self._scopes
792 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
793 self
794 }
795
796 /// Removes all scopes, and no default scope will be used either.
797 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
798 /// for details).
799 pub fn clear_scopes(mut self) -> DomainTrafficStatGetCall<'a, C> {
800 self._scopes.clear();
801 self
802 }
803}
804
805/// List traffic statistics for all available days. Returns PERMISSION_DENIED if user does not have permission to access TrafficStats for the domain.
806///
807/// A builder for the *trafficStats.list* method supported by a *domain* resource.
808/// It is not used directly, but through a [`DomainMethods`] instance.
809///
810/// # Example
811///
812/// Instantiate a resource method builder
813///
814/// ```test_harness,no_run
815/// # extern crate hyper;
816/// # extern crate hyper_rustls;
817/// # extern crate google_gmailpostmastertools1_beta1 as gmailpostmastertools1_beta1;
818/// # async fn dox() {
819/// # use gmailpostmastertools1_beta1::{PostmasterTools, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
820///
821/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
822/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
823/// # .with_native_roots()
824/// # .unwrap()
825/// # .https_only()
826/// # .enable_http2()
827/// # .build();
828///
829/// # let executor = hyper_util::rt::TokioExecutor::new();
830/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
831/// # secret,
832/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
833/// # yup_oauth2::client::CustomHyperClientBuilder::from(
834/// # hyper_util::client::legacy::Client::builder(executor).build(connector),
835/// # ),
836/// # ).build().await.unwrap();
837///
838/// # let client = hyper_util::client::legacy::Client::builder(
839/// # hyper_util::rt::TokioExecutor::new()
840/// # )
841/// # .build(
842/// # hyper_rustls::HttpsConnectorBuilder::new()
843/// # .with_native_roots()
844/// # .unwrap()
845/// # .https_or_http()
846/// # .enable_http2()
847/// # .build()
848/// # );
849/// # let mut hub = PostmasterTools::new(client, auth);
850/// // You can configure optional parameters by calling the respective setters at will, and
851/// // execute the final call using `doit()`.
852/// // Values shown here are possibly random and not representative !
853/// let result = hub.domains().traffic_stats_list("parent")
854/// .start_date_year(-50)
855/// .start_date_month(-50)
856/// .start_date_day(-7)
857/// .page_token("gubergren")
858/// .page_size(-17)
859/// .end_date_year(-99)
860/// .end_date_month(-56)
861/// .end_date_day(-25)
862/// .doit().await;
863/// # }
864/// ```
865pub struct DomainTrafficStatListCall<'a, C>
866where
867 C: 'a,
868{
869 hub: &'a PostmasterTools<C>,
870 _parent: String,
871 _start_date_year: Option<i32>,
872 _start_date_month: Option<i32>,
873 _start_date_day: Option<i32>,
874 _page_token: Option<String>,
875 _page_size: Option<i32>,
876 _end_date_year: Option<i32>,
877 _end_date_month: Option<i32>,
878 _end_date_day: Option<i32>,
879 _delegate: Option<&'a mut dyn common::Delegate>,
880 _additional_params: HashMap<String, String>,
881 _scopes: BTreeSet<String>,
882}
883
884impl<'a, C> common::CallBuilder for DomainTrafficStatListCall<'a, C> {}
885
886impl<'a, C> DomainTrafficStatListCall<'a, C>
887where
888 C: common::Connector,
889{
890 /// Perform the operation you have build so far.
891 pub async fn doit(mut self) -> common::Result<(common::Response, ListTrafficStatsResponse)> {
892 use std::borrow::Cow;
893 use std::io::{Read, Seek};
894
895 use common::{url::Params, ToParts};
896 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
897
898 let mut dd = common::DefaultDelegate;
899 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
900 dlg.begin(common::MethodInfo {
901 id: "gmailpostmastertools.domains.trafficStats.list",
902 http_method: hyper::Method::GET,
903 });
904
905 for &field in [
906 "alt",
907 "parent",
908 "startDate.year",
909 "startDate.month",
910 "startDate.day",
911 "pageToken",
912 "pageSize",
913 "endDate.year",
914 "endDate.month",
915 "endDate.day",
916 ]
917 .iter()
918 {
919 if self._additional_params.contains_key(field) {
920 dlg.finished(false);
921 return Err(common::Error::FieldClash(field));
922 }
923 }
924
925 let mut params = Params::with_capacity(11 + self._additional_params.len());
926 params.push("parent", self._parent);
927 if let Some(value) = self._start_date_year.as_ref() {
928 params.push("startDate.year", value.to_string());
929 }
930 if let Some(value) = self._start_date_month.as_ref() {
931 params.push("startDate.month", value.to_string());
932 }
933 if let Some(value) = self._start_date_day.as_ref() {
934 params.push("startDate.day", value.to_string());
935 }
936 if let Some(value) = self._page_token.as_ref() {
937 params.push("pageToken", value);
938 }
939 if let Some(value) = self._page_size.as_ref() {
940 params.push("pageSize", value.to_string());
941 }
942 if let Some(value) = self._end_date_year.as_ref() {
943 params.push("endDate.year", value.to_string());
944 }
945 if let Some(value) = self._end_date_month.as_ref() {
946 params.push("endDate.month", value.to_string());
947 }
948 if let Some(value) = self._end_date_day.as_ref() {
949 params.push("endDate.day", value.to_string());
950 }
951
952 params.extend(self._additional_params.iter());
953
954 params.push("alt", "json");
955 let mut url = self.hub._base_url.clone() + "v1beta1/{+parent}/trafficStats";
956 if self._scopes.is_empty() {
957 self._scopes
958 .insert(Scope::PostmasterReadonly.as_ref().to_string());
959 }
960
961 #[allow(clippy::single_element_loop)]
962 for &(find_this, param_name) in [("{+parent}", "parent")].iter() {
963 url = params.uri_replacement(url, param_name, find_this, true);
964 }
965 {
966 let to_remove = ["parent"];
967 params.remove_params(&to_remove);
968 }
969
970 let url = params.parse_with_url(&url);
971
972 loop {
973 let token = match self
974 .hub
975 .auth
976 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
977 .await
978 {
979 Ok(token) => token,
980 Err(e) => match dlg.token(e) {
981 Ok(token) => token,
982 Err(e) => {
983 dlg.finished(false);
984 return Err(common::Error::MissingToken(e));
985 }
986 },
987 };
988 let mut req_result = {
989 let client = &self.hub.client;
990 dlg.pre_request();
991 let mut req_builder = hyper::Request::builder()
992 .method(hyper::Method::GET)
993 .uri(url.as_str())
994 .header(USER_AGENT, self.hub._user_agent.clone());
995
996 if let Some(token) = token.as_ref() {
997 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
998 }
999
1000 let request = req_builder
1001 .header(CONTENT_LENGTH, 0_u64)
1002 .body(common::to_body::<String>(None));
1003
1004 client.request(request.unwrap()).await
1005 };
1006
1007 match req_result {
1008 Err(err) => {
1009 if let common::Retry::After(d) = dlg.http_error(&err) {
1010 sleep(d).await;
1011 continue;
1012 }
1013 dlg.finished(false);
1014 return Err(common::Error::HttpError(err));
1015 }
1016 Ok(res) => {
1017 let (mut parts, body) = res.into_parts();
1018 let mut body = common::Body::new(body);
1019 if !parts.status.is_success() {
1020 let bytes = common::to_bytes(body).await.unwrap_or_default();
1021 let error = serde_json::from_str(&common::to_string(&bytes));
1022 let response = common::to_response(parts, bytes.into());
1023
1024 if let common::Retry::After(d) =
1025 dlg.http_failure(&response, error.as_ref().ok())
1026 {
1027 sleep(d).await;
1028 continue;
1029 }
1030
1031 dlg.finished(false);
1032
1033 return Err(match error {
1034 Ok(value) => common::Error::BadRequest(value),
1035 _ => common::Error::Failure(response),
1036 });
1037 }
1038 let response = {
1039 let bytes = common::to_bytes(body).await.unwrap_or_default();
1040 let encoded = common::to_string(&bytes);
1041 match serde_json::from_str(&encoded) {
1042 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
1043 Err(error) => {
1044 dlg.response_json_decode_error(&encoded, &error);
1045 return Err(common::Error::JsonDecodeError(
1046 encoded.to_string(),
1047 error,
1048 ));
1049 }
1050 }
1051 };
1052
1053 dlg.finished(true);
1054 return Ok(response);
1055 }
1056 }
1057 }
1058 }
1059
1060 /// The resource name of the domain whose traffic statistics we'd like to list. It should have the form `domains/{domain_name}`, where domain_name is the fully qualified domain name.
1061 ///
1062 /// Sets the *parent* path property to the given value.
1063 ///
1064 /// Even though the property as already been set when instantiating this call,
1065 /// we provide this method for API completeness.
1066 pub fn parent(mut self, new_value: &str) -> DomainTrafficStatListCall<'a, C> {
1067 self._parent = new_value.to_string();
1068 self
1069 }
1070 /// Year of the date. Must be from 1 to 9999, or 0 to specify a date without a year.
1071 ///
1072 /// Sets the *start date.year* query property to the given value.
1073 pub fn start_date_year(mut self, new_value: i32) -> DomainTrafficStatListCall<'a, C> {
1074 self._start_date_year = Some(new_value);
1075 self
1076 }
1077 /// Month of a year. Must be from 1 to 12, or 0 to specify a year without a month and day.
1078 ///
1079 /// Sets the *start date.month* query property to the given value.
1080 pub fn start_date_month(mut self, new_value: i32) -> DomainTrafficStatListCall<'a, C> {
1081 self._start_date_month = Some(new_value);
1082 self
1083 }
1084 /// Day of a month. Must be from 1 to 31 and valid for the year and month, or 0 to specify a year by itself or a year and month where the day isn't significant.
1085 ///
1086 /// Sets the *start date.day* query property to the given value.
1087 pub fn start_date_day(mut self, new_value: i32) -> DomainTrafficStatListCall<'a, C> {
1088 self._start_date_day = Some(new_value);
1089 self
1090 }
1091 /// The next_page_token value returned from a previous List request, if any. This is the value of ListTrafficStatsResponse.next_page_token returned from the previous call to `ListTrafficStats` method.
1092 ///
1093 /// Sets the *page token* query property to the given value.
1094 pub fn page_token(mut self, new_value: &str) -> DomainTrafficStatListCall<'a, C> {
1095 self._page_token = Some(new_value.to_string());
1096 self
1097 }
1098 /// Requested page size. Server may return fewer TrafficStats than requested. If unspecified, server will pick an appropriate default.
1099 ///
1100 /// Sets the *page size* query property to the given value.
1101 pub fn page_size(mut self, new_value: i32) -> DomainTrafficStatListCall<'a, C> {
1102 self._page_size = Some(new_value);
1103 self
1104 }
1105 /// Year of the date. Must be from 1 to 9999, or 0 to specify a date without a year.
1106 ///
1107 /// Sets the *end date.year* query property to the given value.
1108 pub fn end_date_year(mut self, new_value: i32) -> DomainTrafficStatListCall<'a, C> {
1109 self._end_date_year = Some(new_value);
1110 self
1111 }
1112 /// Month of a year. Must be from 1 to 12, or 0 to specify a year without a month and day.
1113 ///
1114 /// Sets the *end date.month* query property to the given value.
1115 pub fn end_date_month(mut self, new_value: i32) -> DomainTrafficStatListCall<'a, C> {
1116 self._end_date_month = Some(new_value);
1117 self
1118 }
1119 /// Day of a month. Must be from 1 to 31 and valid for the year and month, or 0 to specify a year by itself or a year and month where the day isn't significant.
1120 ///
1121 /// Sets the *end date.day* query property to the given value.
1122 pub fn end_date_day(mut self, new_value: i32) -> DomainTrafficStatListCall<'a, C> {
1123 self._end_date_day = Some(new_value);
1124 self
1125 }
1126 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
1127 /// while executing the actual API request.
1128 ///
1129 /// ````text
1130 /// It should be used to handle progress information, and to implement a certain level of resilience.
1131 /// ````
1132 ///
1133 /// Sets the *delegate* property to the given value.
1134 pub fn delegate(
1135 mut self,
1136 new_value: &'a mut dyn common::Delegate,
1137 ) -> DomainTrafficStatListCall<'a, C> {
1138 self._delegate = Some(new_value);
1139 self
1140 }
1141
1142 /// Set any additional parameter of the query string used in the request.
1143 /// It should be used to set parameters which are not yet available through their own
1144 /// setters.
1145 ///
1146 /// Please note that this method must not be used to set any of the known parameters
1147 /// which have their own setter method. If done anyway, the request will fail.
1148 ///
1149 /// # Additional Parameters
1150 ///
1151 /// * *$.xgafv* (query-string) - V1 error format.
1152 /// * *access_token* (query-string) - OAuth access token.
1153 /// * *alt* (query-string) - Data format for response.
1154 /// * *callback* (query-string) - JSONP
1155 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
1156 /// * *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.
1157 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
1158 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
1159 /// * *quotaUser* (query-string) - Available to use for quota purposes for server-side applications. Can be any arbitrary string assigned to a user, but should not exceed 40 characters.
1160 /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
1161 /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
1162 pub fn param<T>(mut self, name: T, value: T) -> DomainTrafficStatListCall<'a, C>
1163 where
1164 T: AsRef<str>,
1165 {
1166 self._additional_params
1167 .insert(name.as_ref().to_string(), value.as_ref().to_string());
1168 self
1169 }
1170
1171 /// Identifies the authorization scope for the method you are building.
1172 ///
1173 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
1174 /// [`Scope::PostmasterReadonly`].
1175 ///
1176 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
1177 /// tokens for more than one scope.
1178 ///
1179 /// Usually there is more than one suitable scope to authorize an operation, some of which may
1180 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
1181 /// sufficient, a read-write scope will do as well.
1182 pub fn add_scope<St>(mut self, scope: St) -> DomainTrafficStatListCall<'a, C>
1183 where
1184 St: AsRef<str>,
1185 {
1186 self._scopes.insert(String::from(scope.as_ref()));
1187 self
1188 }
1189 /// Identifies the authorization scope(s) for the method you are building.
1190 ///
1191 /// See [`Self::add_scope()`] for details.
1192 pub fn add_scopes<I, St>(mut self, scopes: I) -> DomainTrafficStatListCall<'a, C>
1193 where
1194 I: IntoIterator<Item = St>,
1195 St: AsRef<str>,
1196 {
1197 self._scopes
1198 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
1199 self
1200 }
1201
1202 /// Removes all scopes, and no default scope will be used either.
1203 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
1204 /// for details).
1205 pub fn clear_scopes(mut self) -> DomainTrafficStatListCall<'a, C> {
1206 self._scopes.clear();
1207 self
1208 }
1209}
1210
1211/// Gets a specific domain registered by the client. Returns NOT_FOUND if the domain does not exist.
1212///
1213/// A builder for the *get* method supported by a *domain* resource.
1214/// It is not used directly, but through a [`DomainMethods`] instance.
1215///
1216/// # Example
1217///
1218/// Instantiate a resource method builder
1219///
1220/// ```test_harness,no_run
1221/// # extern crate hyper;
1222/// # extern crate hyper_rustls;
1223/// # extern crate google_gmailpostmastertools1_beta1 as gmailpostmastertools1_beta1;
1224/// # async fn dox() {
1225/// # use gmailpostmastertools1_beta1::{PostmasterTools, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
1226///
1227/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
1228/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
1229/// # .with_native_roots()
1230/// # .unwrap()
1231/// # .https_only()
1232/// # .enable_http2()
1233/// # .build();
1234///
1235/// # let executor = hyper_util::rt::TokioExecutor::new();
1236/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
1237/// # secret,
1238/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
1239/// # yup_oauth2::client::CustomHyperClientBuilder::from(
1240/// # hyper_util::client::legacy::Client::builder(executor).build(connector),
1241/// # ),
1242/// # ).build().await.unwrap();
1243///
1244/// # let client = hyper_util::client::legacy::Client::builder(
1245/// # hyper_util::rt::TokioExecutor::new()
1246/// # )
1247/// # .build(
1248/// # hyper_rustls::HttpsConnectorBuilder::new()
1249/// # .with_native_roots()
1250/// # .unwrap()
1251/// # .https_or_http()
1252/// # .enable_http2()
1253/// # .build()
1254/// # );
1255/// # let mut hub = PostmasterTools::new(client, auth);
1256/// // You can configure optional parameters by calling the respective setters at will, and
1257/// // execute the final call using `doit()`.
1258/// // Values shown here are possibly random and not representative !
1259/// let result = hub.domains().get("name")
1260/// .doit().await;
1261/// # }
1262/// ```
1263pub struct DomainGetCall<'a, C>
1264where
1265 C: 'a,
1266{
1267 hub: &'a PostmasterTools<C>,
1268 _name: String,
1269 _delegate: Option<&'a mut dyn common::Delegate>,
1270 _additional_params: HashMap<String, String>,
1271 _scopes: BTreeSet<String>,
1272}
1273
1274impl<'a, C> common::CallBuilder for DomainGetCall<'a, C> {}
1275
1276impl<'a, C> DomainGetCall<'a, C>
1277where
1278 C: common::Connector,
1279{
1280 /// Perform the operation you have build so far.
1281 pub async fn doit(mut self) -> common::Result<(common::Response, Domain)> {
1282 use std::borrow::Cow;
1283 use std::io::{Read, Seek};
1284
1285 use common::{url::Params, ToParts};
1286 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
1287
1288 let mut dd = common::DefaultDelegate;
1289 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
1290 dlg.begin(common::MethodInfo {
1291 id: "gmailpostmastertools.domains.get",
1292 http_method: hyper::Method::GET,
1293 });
1294
1295 for &field in ["alt", "name"].iter() {
1296 if self._additional_params.contains_key(field) {
1297 dlg.finished(false);
1298 return Err(common::Error::FieldClash(field));
1299 }
1300 }
1301
1302 let mut params = Params::with_capacity(3 + self._additional_params.len());
1303 params.push("name", self._name);
1304
1305 params.extend(self._additional_params.iter());
1306
1307 params.push("alt", "json");
1308 let mut url = self.hub._base_url.clone() + "v1beta1/{+name}";
1309 if self._scopes.is_empty() {
1310 self._scopes
1311 .insert(Scope::PostmasterReadonly.as_ref().to_string());
1312 }
1313
1314 #[allow(clippy::single_element_loop)]
1315 for &(find_this, param_name) in [("{+name}", "name")].iter() {
1316 url = params.uri_replacement(url, param_name, find_this, true);
1317 }
1318 {
1319 let to_remove = ["name"];
1320 params.remove_params(&to_remove);
1321 }
1322
1323 let url = params.parse_with_url(&url);
1324
1325 loop {
1326 let token = match self
1327 .hub
1328 .auth
1329 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
1330 .await
1331 {
1332 Ok(token) => token,
1333 Err(e) => match dlg.token(e) {
1334 Ok(token) => token,
1335 Err(e) => {
1336 dlg.finished(false);
1337 return Err(common::Error::MissingToken(e));
1338 }
1339 },
1340 };
1341 let mut req_result = {
1342 let client = &self.hub.client;
1343 dlg.pre_request();
1344 let mut req_builder = hyper::Request::builder()
1345 .method(hyper::Method::GET)
1346 .uri(url.as_str())
1347 .header(USER_AGENT, self.hub._user_agent.clone());
1348
1349 if let Some(token) = token.as_ref() {
1350 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
1351 }
1352
1353 let request = req_builder
1354 .header(CONTENT_LENGTH, 0_u64)
1355 .body(common::to_body::<String>(None));
1356
1357 client.request(request.unwrap()).await
1358 };
1359
1360 match req_result {
1361 Err(err) => {
1362 if let common::Retry::After(d) = dlg.http_error(&err) {
1363 sleep(d).await;
1364 continue;
1365 }
1366 dlg.finished(false);
1367 return Err(common::Error::HttpError(err));
1368 }
1369 Ok(res) => {
1370 let (mut parts, body) = res.into_parts();
1371 let mut body = common::Body::new(body);
1372 if !parts.status.is_success() {
1373 let bytes = common::to_bytes(body).await.unwrap_or_default();
1374 let error = serde_json::from_str(&common::to_string(&bytes));
1375 let response = common::to_response(parts, bytes.into());
1376
1377 if let common::Retry::After(d) =
1378 dlg.http_failure(&response, error.as_ref().ok())
1379 {
1380 sleep(d).await;
1381 continue;
1382 }
1383
1384 dlg.finished(false);
1385
1386 return Err(match error {
1387 Ok(value) => common::Error::BadRequest(value),
1388 _ => common::Error::Failure(response),
1389 });
1390 }
1391 let response = {
1392 let bytes = common::to_bytes(body).await.unwrap_or_default();
1393 let encoded = common::to_string(&bytes);
1394 match serde_json::from_str(&encoded) {
1395 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
1396 Err(error) => {
1397 dlg.response_json_decode_error(&encoded, &error);
1398 return Err(common::Error::JsonDecodeError(
1399 encoded.to_string(),
1400 error,
1401 ));
1402 }
1403 }
1404 };
1405
1406 dlg.finished(true);
1407 return Ok(response);
1408 }
1409 }
1410 }
1411 }
1412
1413 /// The resource name of the domain. It should have the form `domains/{domain_name}`, where domain_name is the fully qualified domain name.
1414 ///
1415 /// Sets the *name* path property to the given value.
1416 ///
1417 /// Even though the property as already been set when instantiating this call,
1418 /// we provide this method for API completeness.
1419 pub fn name(mut self, new_value: &str) -> DomainGetCall<'a, C> {
1420 self._name = new_value.to_string();
1421 self
1422 }
1423 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
1424 /// while executing the actual API request.
1425 ///
1426 /// ````text
1427 /// It should be used to handle progress information, and to implement a certain level of resilience.
1428 /// ````
1429 ///
1430 /// Sets the *delegate* property to the given value.
1431 pub fn delegate(mut self, new_value: &'a mut dyn common::Delegate) -> DomainGetCall<'a, C> {
1432 self._delegate = Some(new_value);
1433 self
1434 }
1435
1436 /// Set any additional parameter of the query string used in the request.
1437 /// It should be used to set parameters which are not yet available through their own
1438 /// setters.
1439 ///
1440 /// Please note that this method must not be used to set any of the known parameters
1441 /// which have their own setter method. If done anyway, the request will fail.
1442 ///
1443 /// # Additional Parameters
1444 ///
1445 /// * *$.xgafv* (query-string) - V1 error format.
1446 /// * *access_token* (query-string) - OAuth access token.
1447 /// * *alt* (query-string) - Data format for response.
1448 /// * *callback* (query-string) - JSONP
1449 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
1450 /// * *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.
1451 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
1452 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
1453 /// * *quotaUser* (query-string) - Available to use for quota purposes for server-side applications. Can be any arbitrary string assigned to a user, but should not exceed 40 characters.
1454 /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
1455 /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
1456 pub fn param<T>(mut self, name: T, value: T) -> DomainGetCall<'a, C>
1457 where
1458 T: AsRef<str>,
1459 {
1460 self._additional_params
1461 .insert(name.as_ref().to_string(), value.as_ref().to_string());
1462 self
1463 }
1464
1465 /// Identifies the authorization scope for the method you are building.
1466 ///
1467 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
1468 /// [`Scope::PostmasterReadonly`].
1469 ///
1470 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
1471 /// tokens for more than one scope.
1472 ///
1473 /// Usually there is more than one suitable scope to authorize an operation, some of which may
1474 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
1475 /// sufficient, a read-write scope will do as well.
1476 pub fn add_scope<St>(mut self, scope: St) -> DomainGetCall<'a, C>
1477 where
1478 St: AsRef<str>,
1479 {
1480 self._scopes.insert(String::from(scope.as_ref()));
1481 self
1482 }
1483 /// Identifies the authorization scope(s) for the method you are building.
1484 ///
1485 /// See [`Self::add_scope()`] for details.
1486 pub fn add_scopes<I, St>(mut self, scopes: I) -> DomainGetCall<'a, C>
1487 where
1488 I: IntoIterator<Item = St>,
1489 St: AsRef<str>,
1490 {
1491 self._scopes
1492 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
1493 self
1494 }
1495
1496 /// Removes all scopes, and no default scope will be used either.
1497 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
1498 /// for details).
1499 pub fn clear_scopes(mut self) -> DomainGetCall<'a, C> {
1500 self._scopes.clear();
1501 self
1502 }
1503}
1504
1505/// Lists the domains that have been registered by the client. The order of domains in the response is unspecified and non-deterministic. Newly created domains will not necessarily be added to the end of this list.
1506///
1507/// A builder for the *list* method supported by a *domain* resource.
1508/// It is not used directly, but through a [`DomainMethods`] instance.
1509///
1510/// # Example
1511///
1512/// Instantiate a resource method builder
1513///
1514/// ```test_harness,no_run
1515/// # extern crate hyper;
1516/// # extern crate hyper_rustls;
1517/// # extern crate google_gmailpostmastertools1_beta1 as gmailpostmastertools1_beta1;
1518/// # async fn dox() {
1519/// # use gmailpostmastertools1_beta1::{PostmasterTools, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
1520///
1521/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
1522/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
1523/// # .with_native_roots()
1524/// # .unwrap()
1525/// # .https_only()
1526/// # .enable_http2()
1527/// # .build();
1528///
1529/// # let executor = hyper_util::rt::TokioExecutor::new();
1530/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
1531/// # secret,
1532/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
1533/// # yup_oauth2::client::CustomHyperClientBuilder::from(
1534/// # hyper_util::client::legacy::Client::builder(executor).build(connector),
1535/// # ),
1536/// # ).build().await.unwrap();
1537///
1538/// # let client = hyper_util::client::legacy::Client::builder(
1539/// # hyper_util::rt::TokioExecutor::new()
1540/// # )
1541/// # .build(
1542/// # hyper_rustls::HttpsConnectorBuilder::new()
1543/// # .with_native_roots()
1544/// # .unwrap()
1545/// # .https_or_http()
1546/// # .enable_http2()
1547/// # .build()
1548/// # );
1549/// # let mut hub = PostmasterTools::new(client, auth);
1550/// // You can configure optional parameters by calling the respective setters at will, and
1551/// // execute the final call using `doit()`.
1552/// // Values shown here are possibly random and not representative !
1553/// let result = hub.domains().list()
1554/// .page_token("sed")
1555/// .page_size(-70)
1556/// .doit().await;
1557/// # }
1558/// ```
1559pub struct DomainListCall<'a, C>
1560where
1561 C: 'a,
1562{
1563 hub: &'a PostmasterTools<C>,
1564 _page_token: Option<String>,
1565 _page_size: Option<i32>,
1566 _delegate: Option<&'a mut dyn common::Delegate>,
1567 _additional_params: HashMap<String, String>,
1568 _scopes: BTreeSet<String>,
1569}
1570
1571impl<'a, C> common::CallBuilder for DomainListCall<'a, C> {}
1572
1573impl<'a, C> DomainListCall<'a, C>
1574where
1575 C: common::Connector,
1576{
1577 /// Perform the operation you have build so far.
1578 pub async fn doit(mut self) -> common::Result<(common::Response, ListDomainsResponse)> {
1579 use std::borrow::Cow;
1580 use std::io::{Read, Seek};
1581
1582 use common::{url::Params, ToParts};
1583 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
1584
1585 let mut dd = common::DefaultDelegate;
1586 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
1587 dlg.begin(common::MethodInfo {
1588 id: "gmailpostmastertools.domains.list",
1589 http_method: hyper::Method::GET,
1590 });
1591
1592 for &field in ["alt", "pageToken", "pageSize"].iter() {
1593 if self._additional_params.contains_key(field) {
1594 dlg.finished(false);
1595 return Err(common::Error::FieldClash(field));
1596 }
1597 }
1598
1599 let mut params = Params::with_capacity(4 + self._additional_params.len());
1600 if let Some(value) = self._page_token.as_ref() {
1601 params.push("pageToken", value);
1602 }
1603 if let Some(value) = self._page_size.as_ref() {
1604 params.push("pageSize", value.to_string());
1605 }
1606
1607 params.extend(self._additional_params.iter());
1608
1609 params.push("alt", "json");
1610 let mut url = self.hub._base_url.clone() + "v1beta1/domains";
1611 if self._scopes.is_empty() {
1612 self._scopes
1613 .insert(Scope::PostmasterReadonly.as_ref().to_string());
1614 }
1615
1616 let url = params.parse_with_url(&url);
1617
1618 loop {
1619 let token = match self
1620 .hub
1621 .auth
1622 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
1623 .await
1624 {
1625 Ok(token) => token,
1626 Err(e) => match dlg.token(e) {
1627 Ok(token) => token,
1628 Err(e) => {
1629 dlg.finished(false);
1630 return Err(common::Error::MissingToken(e));
1631 }
1632 },
1633 };
1634 let mut req_result = {
1635 let client = &self.hub.client;
1636 dlg.pre_request();
1637 let mut req_builder = hyper::Request::builder()
1638 .method(hyper::Method::GET)
1639 .uri(url.as_str())
1640 .header(USER_AGENT, self.hub._user_agent.clone());
1641
1642 if let Some(token) = token.as_ref() {
1643 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
1644 }
1645
1646 let request = req_builder
1647 .header(CONTENT_LENGTH, 0_u64)
1648 .body(common::to_body::<String>(None));
1649
1650 client.request(request.unwrap()).await
1651 };
1652
1653 match req_result {
1654 Err(err) => {
1655 if let common::Retry::After(d) = dlg.http_error(&err) {
1656 sleep(d).await;
1657 continue;
1658 }
1659 dlg.finished(false);
1660 return Err(common::Error::HttpError(err));
1661 }
1662 Ok(res) => {
1663 let (mut parts, body) = res.into_parts();
1664 let mut body = common::Body::new(body);
1665 if !parts.status.is_success() {
1666 let bytes = common::to_bytes(body).await.unwrap_or_default();
1667 let error = serde_json::from_str(&common::to_string(&bytes));
1668 let response = common::to_response(parts, bytes.into());
1669
1670 if let common::Retry::After(d) =
1671 dlg.http_failure(&response, error.as_ref().ok())
1672 {
1673 sleep(d).await;
1674 continue;
1675 }
1676
1677 dlg.finished(false);
1678
1679 return Err(match error {
1680 Ok(value) => common::Error::BadRequest(value),
1681 _ => common::Error::Failure(response),
1682 });
1683 }
1684 let response = {
1685 let bytes = common::to_bytes(body).await.unwrap_or_default();
1686 let encoded = common::to_string(&bytes);
1687 match serde_json::from_str(&encoded) {
1688 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
1689 Err(error) => {
1690 dlg.response_json_decode_error(&encoded, &error);
1691 return Err(common::Error::JsonDecodeError(
1692 encoded.to_string(),
1693 error,
1694 ));
1695 }
1696 }
1697 };
1698
1699 dlg.finished(true);
1700 return Ok(response);
1701 }
1702 }
1703 }
1704 }
1705
1706 /// The next_page_token value returned from a previous List request, if any. This is the value of ListDomainsResponse.next_page_token returned from the previous call to `ListDomains` method.
1707 ///
1708 /// Sets the *page token* query property to the given value.
1709 pub fn page_token(mut self, new_value: &str) -> DomainListCall<'a, C> {
1710 self._page_token = Some(new_value.to_string());
1711 self
1712 }
1713 /// Requested page size. Server may return fewer domains than requested. If unspecified, server will pick an appropriate default.
1714 ///
1715 /// Sets the *page size* query property to the given value.
1716 pub fn page_size(mut self, new_value: i32) -> DomainListCall<'a, C> {
1717 self._page_size = Some(new_value);
1718 self
1719 }
1720 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
1721 /// while executing the actual API request.
1722 ///
1723 /// ````text
1724 /// It should be used to handle progress information, and to implement a certain level of resilience.
1725 /// ````
1726 ///
1727 /// Sets the *delegate* property to the given value.
1728 pub fn delegate(mut self, new_value: &'a mut dyn common::Delegate) -> DomainListCall<'a, C> {
1729 self._delegate = Some(new_value);
1730 self
1731 }
1732
1733 /// Set any additional parameter of the query string used in the request.
1734 /// It should be used to set parameters which are not yet available through their own
1735 /// setters.
1736 ///
1737 /// Please note that this method must not be used to set any of the known parameters
1738 /// which have their own setter method. If done anyway, the request will fail.
1739 ///
1740 /// # Additional Parameters
1741 ///
1742 /// * *$.xgafv* (query-string) - V1 error format.
1743 /// * *access_token* (query-string) - OAuth access token.
1744 /// * *alt* (query-string) - Data format for response.
1745 /// * *callback* (query-string) - JSONP
1746 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
1747 /// * *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.
1748 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
1749 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
1750 /// * *quotaUser* (query-string) - Available to use for quota purposes for server-side applications. Can be any arbitrary string assigned to a user, but should not exceed 40 characters.
1751 /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
1752 /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
1753 pub fn param<T>(mut self, name: T, value: T) -> DomainListCall<'a, C>
1754 where
1755 T: AsRef<str>,
1756 {
1757 self._additional_params
1758 .insert(name.as_ref().to_string(), value.as_ref().to_string());
1759 self
1760 }
1761
1762 /// Identifies the authorization scope for the method you are building.
1763 ///
1764 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
1765 /// [`Scope::PostmasterReadonly`].
1766 ///
1767 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
1768 /// tokens for more than one scope.
1769 ///
1770 /// Usually there is more than one suitable scope to authorize an operation, some of which may
1771 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
1772 /// sufficient, a read-write scope will do as well.
1773 pub fn add_scope<St>(mut self, scope: St) -> DomainListCall<'a, C>
1774 where
1775 St: AsRef<str>,
1776 {
1777 self._scopes.insert(String::from(scope.as_ref()));
1778 self
1779 }
1780 /// Identifies the authorization scope(s) for the method you are building.
1781 ///
1782 /// See [`Self::add_scope()`] for details.
1783 pub fn add_scopes<I, St>(mut self, scopes: I) -> DomainListCall<'a, C>
1784 where
1785 I: IntoIterator<Item = St>,
1786 St: AsRef<str>,
1787 {
1788 self._scopes
1789 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
1790 self
1791 }
1792
1793 /// Removes all scopes, and no default scope will be used either.
1794 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
1795 /// for details).
1796 pub fn clear_scopes(mut self) -> DomainListCall<'a, C> {
1797 self._scopes.clear();
1798 self
1799 }
1800}