google_licensing1/
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 Google Workspace licenses for your domain
17    AppLicensing,
18}
19
20impl AsRef<str> for Scope {
21    fn as_ref(&self) -> &str {
22        match *self {
23            Scope::AppLicensing => "https://www.googleapis.com/auth/apps.licensing",
24        }
25    }
26}
27
28#[allow(clippy::derivable_impls)]
29impl Default for Scope {
30    fn default() -> Scope {
31        Scope::AppLicensing
32    }
33}
34
35// ########
36// HUB ###
37// ######
38
39/// Central instance to access all Licensing 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_licensing1 as licensing1;
49/// use licensing1::{Result, Error};
50/// # async fn dox() {
51/// use licensing1::{Licensing, 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 = Licensing::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.license_assignments().list_for_product_and_sku("productId", "skuId", "customerId")
93///              .page_token("gubergren")
94///              .max_results(50)
95///              .doit().await;
96///
97/// match result {
98///     Err(e) => match e {
99///         // The Error enum provides details about what exactly happened.
100///         // You can also just use its `Debug`, `Display` or `Error` traits
101///          Error::HttpError(_)
102///         |Error::Io(_)
103///         |Error::MissingAPIKey
104///         |Error::MissingToken(_)
105///         |Error::Cancelled
106///         |Error::UploadSizeLimitExceeded(_, _)
107///         |Error::Failure(_)
108///         |Error::BadRequest(_)
109///         |Error::FieldClash(_)
110///         |Error::JsonDecodeError(_, _) => println!("{}", e),
111///     },
112///     Ok(res) => println!("Success: {:?}", res),
113/// }
114/// # }
115/// ```
116#[derive(Clone)]
117pub struct Licensing<C> {
118    pub client: common::Client<C>,
119    pub auth: Box<dyn common::GetToken>,
120    _user_agent: String,
121    _base_url: String,
122    _root_url: String,
123}
124
125impl<C> common::Hub for Licensing<C> {}
126
127impl<'a, C> Licensing<C> {
128    pub fn new<A: 'static + common::GetToken>(client: common::Client<C>, auth: A) -> Licensing<C> {
129        Licensing {
130            client,
131            auth: Box::new(auth),
132            _user_agent: "google-api-rust-client/7.0.0".to_string(),
133            _base_url: "https://licensing.googleapis.com/".to_string(),
134            _root_url: "https://licensing.googleapis.com/".to_string(),
135        }
136    }
137
138    pub fn license_assignments(&'a self) -> LicenseAssignmentMethods<'a, C> {
139        LicenseAssignmentMethods { hub: self }
140    }
141
142    /// Set the user-agent header field to use in all requests to the server.
143    /// It defaults to `google-api-rust-client/7.0.0`.
144    ///
145    /// Returns the previously set user-agent.
146    pub fn user_agent(&mut self, agent_name: String) -> String {
147        std::mem::replace(&mut self._user_agent, agent_name)
148    }
149
150    /// Set the base url to use in all requests to the server.
151    /// It defaults to `https://licensing.googleapis.com/`.
152    ///
153    /// Returns the previously set base url.
154    pub fn base_url(&mut self, new_base_url: String) -> String {
155        std::mem::replace(&mut self._base_url, new_base_url)
156    }
157
158    /// Set the root url to use in all requests to the server.
159    /// It defaults to `https://licensing.googleapis.com/`.
160    ///
161    /// Returns the previously set root url.
162    pub fn root_url(&mut self, new_root_url: String) -> String {
163        std::mem::replace(&mut self._root_url, new_root_url)
164    }
165}
166
167// ############
168// SCHEMAS ###
169// ##########
170/// A generic empty message that you can re-use to avoid defining duplicated empty messages in your APIs. A typical example is to use it as the request or the response type of an API method. For instance: service Foo { rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); }
171///
172/// # Activities
173///
174/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
175/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
176///
177/// * [delete license assignments](LicenseAssignmentDeleteCall) (response)
178#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
179#[serde_with::serde_as]
180#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
181pub struct Empty {
182    _never_set: Option<bool>,
183}
184
185impl common::ResponseResult for Empty {}
186
187/// Representation of a license assignment.
188///
189/// # Activities
190///
191/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
192/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
193///
194/// * [delete license assignments](LicenseAssignmentDeleteCall) (none)
195/// * [get license assignments](LicenseAssignmentGetCall) (response)
196/// * [insert license assignments](LicenseAssignmentInsertCall) (response)
197/// * [list for product license assignments](LicenseAssignmentListForProductCall) (none)
198/// * [list for product and sku license assignments](LicenseAssignmentListForProductAndSkuCall) (none)
199/// * [patch license assignments](LicenseAssignmentPatchCall) (request|response)
200/// * [update license assignments](LicenseAssignmentUpdateCall) (request|response)
201#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
202#[serde_with::serde_as]
203#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
204pub struct LicenseAssignment {
205    /// ETag of the resource.
206    pub etags: Option<String>,
207    /// Identifies the resource as a LicenseAssignment, which is `licensing#licenseAssignment`.
208    pub kind: Option<String>,
209    /// A product's unique identifier. For more information about products in this version of the API, see Product and SKU IDs.
210    #[serde(rename = "productId")]
211    pub product_id: Option<String>,
212    /// Display Name of the product.
213    #[serde(rename = "productName")]
214    pub product_name: Option<String>,
215    /// Link to this page.
216    #[serde(rename = "selfLink")]
217    pub self_link: Option<String>,
218    /// A product SKU's unique identifier. For more information about available SKUs in this version of the API, see Products and SKUs.
219    #[serde(rename = "skuId")]
220    pub sku_id: Option<String>,
221    /// Display Name of the sku of the product.
222    #[serde(rename = "skuName")]
223    pub sku_name: Option<String>,
224    /// The user's current primary email address. If the user's email address changes, use the new email address in your API requests. Since a `userId` is subject to change, do not use a `userId` value as a key for persistent data. This key could break if the current user's email address changes. If the `userId` is suspended, the license status changes.
225    #[serde(rename = "userId")]
226    pub user_id: Option<String>,
227}
228
229impl common::RequestValue for LicenseAssignment {}
230impl common::Resource for LicenseAssignment {}
231impl common::ResponseResult for LicenseAssignment {}
232
233/// Representation of a license assignment.
234///
235/// # Activities
236///
237/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
238/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
239///
240/// * [insert license assignments](LicenseAssignmentInsertCall) (request)
241#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
242#[serde_with::serde_as]
243#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
244pub struct LicenseAssignmentInsert {
245    /// Email id of the user
246    #[serde(rename = "userId")]
247    pub user_id: Option<String>,
248}
249
250impl common::RequestValue for LicenseAssignmentInsert {}
251
252/// There is no detailed description.
253///
254/// # Activities
255///
256/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
257/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
258///
259/// * [list for product license assignments](LicenseAssignmentListForProductCall) (response)
260/// * [list for product and sku license assignments](LicenseAssignmentListForProductAndSkuCall) (response)
261#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
262#[serde_with::serde_as]
263#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
264pub struct LicenseAssignmentList {
265    /// ETag of the resource.
266    pub etag: Option<String>,
267    /// The LicenseAssignments in this page of results.
268    pub items: Option<Vec<LicenseAssignment>>,
269    /// Identifies the resource as a collection of LicenseAssignments.
270    pub kind: Option<String>,
271    /// The token that you must submit in a subsequent request to retrieve additional license results matching your query parameters. The `maxResults` query string is related to the `nextPageToken` since `maxResults` determines how many entries are returned on each next page.
272    #[serde(rename = "nextPageToken")]
273    pub next_page_token: Option<String>,
274}
275
276impl common::ResponseResult for LicenseAssignmentList {}
277
278// ###################
279// MethodBuilders ###
280// #################
281
282/// A builder providing access to all methods supported on *licenseAssignment* resources.
283/// It is not used directly, but through the [`Licensing`] hub.
284///
285/// # Example
286///
287/// Instantiate a resource builder
288///
289/// ```test_harness,no_run
290/// extern crate hyper;
291/// extern crate hyper_rustls;
292/// extern crate google_licensing1 as licensing1;
293///
294/// # async fn dox() {
295/// use licensing1::{Licensing, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
296///
297/// let secret: yup_oauth2::ApplicationSecret = Default::default();
298/// let connector = hyper_rustls::HttpsConnectorBuilder::new()
299///     .with_native_roots()
300///     .unwrap()
301///     .https_only()
302///     .enable_http2()
303///     .build();
304///
305/// let executor = hyper_util::rt::TokioExecutor::new();
306/// let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
307///     secret,
308///     yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
309///     yup_oauth2::client::CustomHyperClientBuilder::from(
310///         hyper_util::client::legacy::Client::builder(executor).build(connector),
311///     ),
312/// ).build().await.unwrap();
313///
314/// let client = hyper_util::client::legacy::Client::builder(
315///     hyper_util::rt::TokioExecutor::new()
316/// )
317/// .build(
318///     hyper_rustls::HttpsConnectorBuilder::new()
319///         .with_native_roots()
320///         .unwrap()
321///         .https_or_http()
322///         .enable_http2()
323///         .build()
324/// );
325/// let mut hub = Licensing::new(client, auth);
326/// // Usually you wouldn't bind this to a variable, but keep calling *CallBuilders*
327/// // like `delete(...)`, `get(...)`, `insert(...)`, `list_for_product(...)`, `list_for_product_and_sku(...)`, `patch(...)` and `update(...)`
328/// // to build up your call.
329/// let rb = hub.license_assignments();
330/// # }
331/// ```
332pub struct LicenseAssignmentMethods<'a, C>
333where
334    C: 'a,
335{
336    hub: &'a Licensing<C>,
337}
338
339impl<'a, C> common::MethodsBuilder for LicenseAssignmentMethods<'a, C> {}
340
341impl<'a, C> LicenseAssignmentMethods<'a, C> {
342    /// Create a builder to help you perform the following task:
343    ///
344    /// Revoke a license.
345    ///
346    /// # Arguments
347    ///
348    /// * `productId` - A product's unique identifier. For more information about products in this version of the API, see Products and SKUs.
349    /// * `skuId` - A product SKU's unique identifier. For more information about available SKUs in this version of the API, see Products and SKUs.
350    /// * `userId` - The user's current primary email address. If the user's email address changes, use the new email address in your API requests. Since a `userId` is subject to change, do not use a `userId` value as a key for persistent data. This key could break if the current user's email address changes. If the `userId` is suspended, the license status changes.
351    pub fn delete(
352        &self,
353        product_id: &str,
354        sku_id: &str,
355        user_id: &str,
356    ) -> LicenseAssignmentDeleteCall<'a, C> {
357        LicenseAssignmentDeleteCall {
358            hub: self.hub,
359            _product_id: product_id.to_string(),
360            _sku_id: sku_id.to_string(),
361            _user_id: user_id.to_string(),
362            _delegate: Default::default(),
363            _additional_params: Default::default(),
364            _scopes: Default::default(),
365        }
366    }
367
368    /// Create a builder to help you perform the following task:
369    ///
370    /// Get a specific user's license by product SKU.
371    ///
372    /// # Arguments
373    ///
374    /// * `productId` - A product's unique identifier. For more information about products in this version of the API, see Products and SKUs.
375    /// * `skuId` - A product SKU's unique identifier. For more information about available SKUs in this version of the API, see Products and SKUs.
376    /// * `userId` - The user's current primary email address. If the user's email address changes, use the new email address in your API requests. Since a `userId` is subject to change, do not use a `userId` value as a key for persistent data. This key could break if the current user's email address changes. If the `userId` is suspended, the license status changes.
377    pub fn get(
378        &self,
379        product_id: &str,
380        sku_id: &str,
381        user_id: &str,
382    ) -> LicenseAssignmentGetCall<'a, C> {
383        LicenseAssignmentGetCall {
384            hub: self.hub,
385            _product_id: product_id.to_string(),
386            _sku_id: sku_id.to_string(),
387            _user_id: user_id.to_string(),
388            _delegate: Default::default(),
389            _additional_params: Default::default(),
390            _scopes: Default::default(),
391        }
392    }
393
394    /// Create a builder to help you perform the following task:
395    ///
396    /// Assign a license.
397    ///
398    /// # Arguments
399    ///
400    /// * `request` - No description provided.
401    /// * `productId` - A product's unique identifier. For more information about products in this version of the API, see Products and SKUs.
402    /// * `skuId` - A product SKU's unique identifier. For more information about available SKUs in this version of the API, see Products and SKUs.
403    pub fn insert(
404        &self,
405        request: LicenseAssignmentInsert,
406        product_id: &str,
407        sku_id: &str,
408    ) -> LicenseAssignmentInsertCall<'a, C> {
409        LicenseAssignmentInsertCall {
410            hub: self.hub,
411            _request: request,
412            _product_id: product_id.to_string(),
413            _sku_id: sku_id.to_string(),
414            _delegate: Default::default(),
415            _additional_params: Default::default(),
416            _scopes: Default::default(),
417        }
418    }
419
420    /// Create a builder to help you perform the following task:
421    ///
422    /// List all users assigned licenses for a specific product SKU.
423    ///
424    /// # Arguments
425    ///
426    /// * `productId` - A product's unique identifier. For more information about products in this version of the API, see Products and SKUs.
427    /// * `customerId` - The customer's unique ID as defined in the Admin console, such as `C00000000`. If the customer is suspended, the server returns an error.
428    pub fn list_for_product(
429        &self,
430        product_id: &str,
431        customer_id: &str,
432    ) -> LicenseAssignmentListForProductCall<'a, C> {
433        LicenseAssignmentListForProductCall {
434            hub: self.hub,
435            _product_id: product_id.to_string(),
436            _customer_id: customer_id.to_string(),
437            _page_token: Default::default(),
438            _max_results: Default::default(),
439            _delegate: Default::default(),
440            _additional_params: Default::default(),
441            _scopes: Default::default(),
442        }
443    }
444
445    /// Create a builder to help you perform the following task:
446    ///
447    /// List all users assigned licenses for a specific product SKU.
448    ///
449    /// # Arguments
450    ///
451    /// * `productId` - A product's unique identifier. For more information about products in this version of the API, see Products and SKUs.
452    /// * `skuId` - A product SKU's unique identifier. For more information about available SKUs in this version of the API, see Products and SKUs.
453    /// * `customerId` - The customer's unique ID as defined in the Admin console, such as `C00000000`. If the customer is suspended, the server returns an error.
454    pub fn list_for_product_and_sku(
455        &self,
456        product_id: &str,
457        sku_id: &str,
458        customer_id: &str,
459    ) -> LicenseAssignmentListForProductAndSkuCall<'a, C> {
460        LicenseAssignmentListForProductAndSkuCall {
461            hub: self.hub,
462            _product_id: product_id.to_string(),
463            _sku_id: sku_id.to_string(),
464            _customer_id: customer_id.to_string(),
465            _page_token: Default::default(),
466            _max_results: Default::default(),
467            _delegate: Default::default(),
468            _additional_params: Default::default(),
469            _scopes: Default::default(),
470        }
471    }
472
473    /// Create a builder to help you perform the following task:
474    ///
475    /// Reassign a user's product SKU with a different SKU in the same product. This method supports patch semantics.
476    ///
477    /// # Arguments
478    ///
479    /// * `request` - No description provided.
480    /// * `productId` - A product's unique identifier. For more information about products in this version of the API, see Products and SKUs.
481    /// * `skuId` - A product SKU's unique identifier. For more information about available SKUs in this version of the API, see Products and SKUs.
482    /// * `userId` - The user's current primary email address. If the user's email address changes, use the new email address in your API requests. Since a `userId` is subject to change, do not use a `userId` value as a key for persistent data. This key could break if the current user's email address changes. If the `userId` is suspended, the license status changes.
483    pub fn patch(
484        &self,
485        request: LicenseAssignment,
486        product_id: &str,
487        sku_id: &str,
488        user_id: &str,
489    ) -> LicenseAssignmentPatchCall<'a, C> {
490        LicenseAssignmentPatchCall {
491            hub: self.hub,
492            _request: request,
493            _product_id: product_id.to_string(),
494            _sku_id: sku_id.to_string(),
495            _user_id: user_id.to_string(),
496            _delegate: Default::default(),
497            _additional_params: Default::default(),
498            _scopes: Default::default(),
499        }
500    }
501
502    /// Create a builder to help you perform the following task:
503    ///
504    /// Reassign a user's product SKU with a different SKU in the same product.
505    ///
506    /// # Arguments
507    ///
508    /// * `request` - No description provided.
509    /// * `productId` - A product's unique identifier. For more information about products in this version of the API, see Products and SKUs.
510    /// * `skuId` - A product SKU's unique identifier. For more information about available SKUs in this version of the API, see Products and SKUs.
511    /// * `userId` - The user's current primary email address. If the user's email address changes, use the new email address in your API requests. Since a `userId` is subject to change, do not use a `userId` value as a key for persistent data. This key could break if the current user's email address changes. If the `userId` is suspended, the license status changes.
512    pub fn update(
513        &self,
514        request: LicenseAssignment,
515        product_id: &str,
516        sku_id: &str,
517        user_id: &str,
518    ) -> LicenseAssignmentUpdateCall<'a, C> {
519        LicenseAssignmentUpdateCall {
520            hub: self.hub,
521            _request: request,
522            _product_id: product_id.to_string(),
523            _sku_id: sku_id.to_string(),
524            _user_id: user_id.to_string(),
525            _delegate: Default::default(),
526            _additional_params: Default::default(),
527            _scopes: Default::default(),
528        }
529    }
530}
531
532// ###################
533// CallBuilders   ###
534// #################
535
536/// Revoke a license.
537///
538/// A builder for the *delete* method supported by a *licenseAssignment* resource.
539/// It is not used directly, but through a [`LicenseAssignmentMethods`] instance.
540///
541/// # Example
542///
543/// Instantiate a resource method builder
544///
545/// ```test_harness,no_run
546/// # extern crate hyper;
547/// # extern crate hyper_rustls;
548/// # extern crate google_licensing1 as licensing1;
549/// # async fn dox() {
550/// # use licensing1::{Licensing, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
551///
552/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
553/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
554/// #     .with_native_roots()
555/// #     .unwrap()
556/// #     .https_only()
557/// #     .enable_http2()
558/// #     .build();
559///
560/// # let executor = hyper_util::rt::TokioExecutor::new();
561/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
562/// #     secret,
563/// #     yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
564/// #     yup_oauth2::client::CustomHyperClientBuilder::from(
565/// #         hyper_util::client::legacy::Client::builder(executor).build(connector),
566/// #     ),
567/// # ).build().await.unwrap();
568///
569/// # let client = hyper_util::client::legacy::Client::builder(
570/// #     hyper_util::rt::TokioExecutor::new()
571/// # )
572/// # .build(
573/// #     hyper_rustls::HttpsConnectorBuilder::new()
574/// #         .with_native_roots()
575/// #         .unwrap()
576/// #         .https_or_http()
577/// #         .enable_http2()
578/// #         .build()
579/// # );
580/// # let mut hub = Licensing::new(client, auth);
581/// // You can configure optional parameters by calling the respective setters at will, and
582/// // execute the final call using `doit()`.
583/// // Values shown here are possibly random and not representative !
584/// let result = hub.license_assignments().delete("productId", "skuId", "userId")
585///              .doit().await;
586/// # }
587/// ```
588pub struct LicenseAssignmentDeleteCall<'a, C>
589where
590    C: 'a,
591{
592    hub: &'a Licensing<C>,
593    _product_id: String,
594    _sku_id: String,
595    _user_id: String,
596    _delegate: Option<&'a mut dyn common::Delegate>,
597    _additional_params: HashMap<String, String>,
598    _scopes: BTreeSet<String>,
599}
600
601impl<'a, C> common::CallBuilder for LicenseAssignmentDeleteCall<'a, C> {}
602
603impl<'a, C> LicenseAssignmentDeleteCall<'a, C>
604where
605    C: common::Connector,
606{
607    /// Perform the operation you have build so far.
608    pub async fn doit(mut self) -> common::Result<(common::Response, Empty)> {
609        use std::borrow::Cow;
610        use std::io::{Read, Seek};
611
612        use common::{url::Params, ToParts};
613        use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
614
615        let mut dd = common::DefaultDelegate;
616        let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
617        dlg.begin(common::MethodInfo {
618            id: "licensing.licenseAssignments.delete",
619            http_method: hyper::Method::DELETE,
620        });
621
622        for &field in ["alt", "productId", "skuId", "userId"].iter() {
623            if self._additional_params.contains_key(field) {
624                dlg.finished(false);
625                return Err(common::Error::FieldClash(field));
626            }
627        }
628
629        let mut params = Params::with_capacity(5 + self._additional_params.len());
630        params.push("productId", self._product_id);
631        params.push("skuId", self._sku_id);
632        params.push("userId", self._user_id);
633
634        params.extend(self._additional_params.iter());
635
636        params.push("alt", "json");
637        let mut url = self.hub._base_url.clone()
638            + "apps/licensing/v1/product/{productId}/sku/{skuId}/user/{userId}";
639        if self._scopes.is_empty() {
640            self._scopes
641                .insert(Scope::AppLicensing.as_ref().to_string());
642        }
643
644        #[allow(clippy::single_element_loop)]
645        for &(find_this, param_name) in [
646            ("{productId}", "productId"),
647            ("{skuId}", "skuId"),
648            ("{userId}", "userId"),
649        ]
650        .iter()
651        {
652            url = params.uri_replacement(url, param_name, find_this, false);
653        }
654        {
655            let to_remove = ["userId", "skuId", "productId"];
656            params.remove_params(&to_remove);
657        }
658
659        let url = params.parse_with_url(&url);
660
661        loop {
662            let token = match self
663                .hub
664                .auth
665                .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
666                .await
667            {
668                Ok(token) => token,
669                Err(e) => match dlg.token(e) {
670                    Ok(token) => token,
671                    Err(e) => {
672                        dlg.finished(false);
673                        return Err(common::Error::MissingToken(e));
674                    }
675                },
676            };
677            let mut req_result = {
678                let client = &self.hub.client;
679                dlg.pre_request();
680                let mut req_builder = hyper::Request::builder()
681                    .method(hyper::Method::DELETE)
682                    .uri(url.as_str())
683                    .header(USER_AGENT, self.hub._user_agent.clone());
684
685                if let Some(token) = token.as_ref() {
686                    req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
687                }
688
689                let request = req_builder
690                    .header(CONTENT_LENGTH, 0_u64)
691                    .body(common::to_body::<String>(None));
692
693                client.request(request.unwrap()).await
694            };
695
696            match req_result {
697                Err(err) => {
698                    if let common::Retry::After(d) = dlg.http_error(&err) {
699                        sleep(d).await;
700                        continue;
701                    }
702                    dlg.finished(false);
703                    return Err(common::Error::HttpError(err));
704                }
705                Ok(res) => {
706                    let (mut parts, body) = res.into_parts();
707                    let mut body = common::Body::new(body);
708                    if !parts.status.is_success() {
709                        let bytes = common::to_bytes(body).await.unwrap_or_default();
710                        let error = serde_json::from_str(&common::to_string(&bytes));
711                        let response = common::to_response(parts, bytes.into());
712
713                        if let common::Retry::After(d) =
714                            dlg.http_failure(&response, error.as_ref().ok())
715                        {
716                            sleep(d).await;
717                            continue;
718                        }
719
720                        dlg.finished(false);
721
722                        return Err(match error {
723                            Ok(value) => common::Error::BadRequest(value),
724                            _ => common::Error::Failure(response),
725                        });
726                    }
727                    let response = {
728                        let bytes = common::to_bytes(body).await.unwrap_or_default();
729                        let encoded = common::to_string(&bytes);
730                        match serde_json::from_str(&encoded) {
731                            Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
732                            Err(error) => {
733                                dlg.response_json_decode_error(&encoded, &error);
734                                return Err(common::Error::JsonDecodeError(
735                                    encoded.to_string(),
736                                    error,
737                                ));
738                            }
739                        }
740                    };
741
742                    dlg.finished(true);
743                    return Ok(response);
744                }
745            }
746        }
747    }
748
749    /// A product's unique identifier. For more information about products in this version of the API, see Products and SKUs.
750    ///
751    /// Sets the *product id* path property to the given value.
752    ///
753    /// Even though the property as already been set when instantiating this call,
754    /// we provide this method for API completeness.
755    pub fn product_id(mut self, new_value: &str) -> LicenseAssignmentDeleteCall<'a, C> {
756        self._product_id = new_value.to_string();
757        self
758    }
759    /// A product SKU's unique identifier. For more information about available SKUs in this version of the API, see Products and SKUs.
760    ///
761    /// Sets the *sku id* path property to the given value.
762    ///
763    /// Even though the property as already been set when instantiating this call,
764    /// we provide this method for API completeness.
765    pub fn sku_id(mut self, new_value: &str) -> LicenseAssignmentDeleteCall<'a, C> {
766        self._sku_id = new_value.to_string();
767        self
768    }
769    /// The user's current primary email address. If the user's email address changes, use the new email address in your API requests. Since a `userId` is subject to change, do not use a `userId` value as a key for persistent data. This key could break if the current user's email address changes. If the `userId` is suspended, the license status changes.
770    ///
771    /// Sets the *user id* path property to the given value.
772    ///
773    /// Even though the property as already been set when instantiating this call,
774    /// we provide this method for API completeness.
775    pub fn user_id(mut self, new_value: &str) -> LicenseAssignmentDeleteCall<'a, C> {
776        self._user_id = new_value.to_string();
777        self
778    }
779    /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
780    /// while executing the actual API request.
781    ///
782    /// ````text
783    ///                   It should be used to handle progress information, and to implement a certain level of resilience.
784    /// ````
785    ///
786    /// Sets the *delegate* property to the given value.
787    pub fn delegate(
788        mut self,
789        new_value: &'a mut dyn common::Delegate,
790    ) -> LicenseAssignmentDeleteCall<'a, C> {
791        self._delegate = Some(new_value);
792        self
793    }
794
795    /// Set any additional parameter of the query string used in the request.
796    /// It should be used to set parameters which are not yet available through their own
797    /// setters.
798    ///
799    /// Please note that this method must not be used to set any of the known parameters
800    /// which have their own setter method. If done anyway, the request will fail.
801    ///
802    /// # Additional Parameters
803    ///
804    /// * *$.xgafv* (query-string) - V1 error format.
805    /// * *access_token* (query-string) - OAuth access token.
806    /// * *alt* (query-string) - Data format for response.
807    /// * *callback* (query-string) - JSONP
808    /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
809    /// * *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.
810    /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
811    /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
812    /// * *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.
813    /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
814    /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
815    pub fn param<T>(mut self, name: T, value: T) -> LicenseAssignmentDeleteCall<'a, C>
816    where
817        T: AsRef<str>,
818    {
819        self._additional_params
820            .insert(name.as_ref().to_string(), value.as_ref().to_string());
821        self
822    }
823
824    /// Identifies the authorization scope for the method you are building.
825    ///
826    /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
827    /// [`Scope::AppLicensing`].
828    ///
829    /// The `scope` will be added to a set of scopes. This is important as one can maintain access
830    /// tokens for more than one scope.
831    ///
832    /// Usually there is more than one suitable scope to authorize an operation, some of which may
833    /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
834    /// sufficient, a read-write scope will do as well.
835    pub fn add_scope<St>(mut self, scope: St) -> LicenseAssignmentDeleteCall<'a, C>
836    where
837        St: AsRef<str>,
838    {
839        self._scopes.insert(String::from(scope.as_ref()));
840        self
841    }
842    /// Identifies the authorization scope(s) for the method you are building.
843    ///
844    /// See [`Self::add_scope()`] for details.
845    pub fn add_scopes<I, St>(mut self, scopes: I) -> LicenseAssignmentDeleteCall<'a, C>
846    where
847        I: IntoIterator<Item = St>,
848        St: AsRef<str>,
849    {
850        self._scopes
851            .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
852        self
853    }
854
855    /// Removes all scopes, and no default scope will be used either.
856    /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
857    /// for details).
858    pub fn clear_scopes(mut self) -> LicenseAssignmentDeleteCall<'a, C> {
859        self._scopes.clear();
860        self
861    }
862}
863
864/// Get a specific user's license by product SKU.
865///
866/// A builder for the *get* method supported by a *licenseAssignment* resource.
867/// It is not used directly, but through a [`LicenseAssignmentMethods`] instance.
868///
869/// # Example
870///
871/// Instantiate a resource method builder
872///
873/// ```test_harness,no_run
874/// # extern crate hyper;
875/// # extern crate hyper_rustls;
876/// # extern crate google_licensing1 as licensing1;
877/// # async fn dox() {
878/// # use licensing1::{Licensing, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
879///
880/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
881/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
882/// #     .with_native_roots()
883/// #     .unwrap()
884/// #     .https_only()
885/// #     .enable_http2()
886/// #     .build();
887///
888/// # let executor = hyper_util::rt::TokioExecutor::new();
889/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
890/// #     secret,
891/// #     yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
892/// #     yup_oauth2::client::CustomHyperClientBuilder::from(
893/// #         hyper_util::client::legacy::Client::builder(executor).build(connector),
894/// #     ),
895/// # ).build().await.unwrap();
896///
897/// # let client = hyper_util::client::legacy::Client::builder(
898/// #     hyper_util::rt::TokioExecutor::new()
899/// # )
900/// # .build(
901/// #     hyper_rustls::HttpsConnectorBuilder::new()
902/// #         .with_native_roots()
903/// #         .unwrap()
904/// #         .https_or_http()
905/// #         .enable_http2()
906/// #         .build()
907/// # );
908/// # let mut hub = Licensing::new(client, auth);
909/// // You can configure optional parameters by calling the respective setters at will, and
910/// // execute the final call using `doit()`.
911/// // Values shown here are possibly random and not representative !
912/// let result = hub.license_assignments().get("productId", "skuId", "userId")
913///              .doit().await;
914/// # }
915/// ```
916pub struct LicenseAssignmentGetCall<'a, C>
917where
918    C: 'a,
919{
920    hub: &'a Licensing<C>,
921    _product_id: String,
922    _sku_id: String,
923    _user_id: String,
924    _delegate: Option<&'a mut dyn common::Delegate>,
925    _additional_params: HashMap<String, String>,
926    _scopes: BTreeSet<String>,
927}
928
929impl<'a, C> common::CallBuilder for LicenseAssignmentGetCall<'a, C> {}
930
931impl<'a, C> LicenseAssignmentGetCall<'a, C>
932where
933    C: common::Connector,
934{
935    /// Perform the operation you have build so far.
936    pub async fn doit(mut self) -> common::Result<(common::Response, LicenseAssignment)> {
937        use std::borrow::Cow;
938        use std::io::{Read, Seek};
939
940        use common::{url::Params, ToParts};
941        use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
942
943        let mut dd = common::DefaultDelegate;
944        let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
945        dlg.begin(common::MethodInfo {
946            id: "licensing.licenseAssignments.get",
947            http_method: hyper::Method::GET,
948        });
949
950        for &field in ["alt", "productId", "skuId", "userId"].iter() {
951            if self._additional_params.contains_key(field) {
952                dlg.finished(false);
953                return Err(common::Error::FieldClash(field));
954            }
955        }
956
957        let mut params = Params::with_capacity(5 + self._additional_params.len());
958        params.push("productId", self._product_id);
959        params.push("skuId", self._sku_id);
960        params.push("userId", self._user_id);
961
962        params.extend(self._additional_params.iter());
963
964        params.push("alt", "json");
965        let mut url = self.hub._base_url.clone()
966            + "apps/licensing/v1/product/{productId}/sku/{skuId}/user/{userId}";
967        if self._scopes.is_empty() {
968            self._scopes
969                .insert(Scope::AppLicensing.as_ref().to_string());
970        }
971
972        #[allow(clippy::single_element_loop)]
973        for &(find_this, param_name) in [
974            ("{productId}", "productId"),
975            ("{skuId}", "skuId"),
976            ("{userId}", "userId"),
977        ]
978        .iter()
979        {
980            url = params.uri_replacement(url, param_name, find_this, false);
981        }
982        {
983            let to_remove = ["userId", "skuId", "productId"];
984            params.remove_params(&to_remove);
985        }
986
987        let url = params.parse_with_url(&url);
988
989        loop {
990            let token = match self
991                .hub
992                .auth
993                .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
994                .await
995            {
996                Ok(token) => token,
997                Err(e) => match dlg.token(e) {
998                    Ok(token) => token,
999                    Err(e) => {
1000                        dlg.finished(false);
1001                        return Err(common::Error::MissingToken(e));
1002                    }
1003                },
1004            };
1005            let mut req_result = {
1006                let client = &self.hub.client;
1007                dlg.pre_request();
1008                let mut req_builder = hyper::Request::builder()
1009                    .method(hyper::Method::GET)
1010                    .uri(url.as_str())
1011                    .header(USER_AGENT, self.hub._user_agent.clone());
1012
1013                if let Some(token) = token.as_ref() {
1014                    req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
1015                }
1016
1017                let request = req_builder
1018                    .header(CONTENT_LENGTH, 0_u64)
1019                    .body(common::to_body::<String>(None));
1020
1021                client.request(request.unwrap()).await
1022            };
1023
1024            match req_result {
1025                Err(err) => {
1026                    if let common::Retry::After(d) = dlg.http_error(&err) {
1027                        sleep(d).await;
1028                        continue;
1029                    }
1030                    dlg.finished(false);
1031                    return Err(common::Error::HttpError(err));
1032                }
1033                Ok(res) => {
1034                    let (mut parts, body) = res.into_parts();
1035                    let mut body = common::Body::new(body);
1036                    if !parts.status.is_success() {
1037                        let bytes = common::to_bytes(body).await.unwrap_or_default();
1038                        let error = serde_json::from_str(&common::to_string(&bytes));
1039                        let response = common::to_response(parts, bytes.into());
1040
1041                        if let common::Retry::After(d) =
1042                            dlg.http_failure(&response, error.as_ref().ok())
1043                        {
1044                            sleep(d).await;
1045                            continue;
1046                        }
1047
1048                        dlg.finished(false);
1049
1050                        return Err(match error {
1051                            Ok(value) => common::Error::BadRequest(value),
1052                            _ => common::Error::Failure(response),
1053                        });
1054                    }
1055                    let response = {
1056                        let bytes = common::to_bytes(body).await.unwrap_or_default();
1057                        let encoded = common::to_string(&bytes);
1058                        match serde_json::from_str(&encoded) {
1059                            Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
1060                            Err(error) => {
1061                                dlg.response_json_decode_error(&encoded, &error);
1062                                return Err(common::Error::JsonDecodeError(
1063                                    encoded.to_string(),
1064                                    error,
1065                                ));
1066                            }
1067                        }
1068                    };
1069
1070                    dlg.finished(true);
1071                    return Ok(response);
1072                }
1073            }
1074        }
1075    }
1076
1077    /// A product's unique identifier. For more information about products in this version of the API, see Products and SKUs.
1078    ///
1079    /// Sets the *product id* path property to the given value.
1080    ///
1081    /// Even though the property as already been set when instantiating this call,
1082    /// we provide this method for API completeness.
1083    pub fn product_id(mut self, new_value: &str) -> LicenseAssignmentGetCall<'a, C> {
1084        self._product_id = new_value.to_string();
1085        self
1086    }
1087    /// A product SKU's unique identifier. For more information about available SKUs in this version of the API, see Products and SKUs.
1088    ///
1089    /// Sets the *sku id* path property to the given value.
1090    ///
1091    /// Even though the property as already been set when instantiating this call,
1092    /// we provide this method for API completeness.
1093    pub fn sku_id(mut self, new_value: &str) -> LicenseAssignmentGetCall<'a, C> {
1094        self._sku_id = new_value.to_string();
1095        self
1096    }
1097    /// The user's current primary email address. If the user's email address changes, use the new email address in your API requests. Since a `userId` is subject to change, do not use a `userId` value as a key for persistent data. This key could break if the current user's email address changes. If the `userId` is suspended, the license status changes.
1098    ///
1099    /// Sets the *user id* path property to the given value.
1100    ///
1101    /// Even though the property as already been set when instantiating this call,
1102    /// we provide this method for API completeness.
1103    pub fn user_id(mut self, new_value: &str) -> LicenseAssignmentGetCall<'a, C> {
1104        self._user_id = new_value.to_string();
1105        self
1106    }
1107    /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
1108    /// while executing the actual API request.
1109    ///
1110    /// ````text
1111    ///                   It should be used to handle progress information, and to implement a certain level of resilience.
1112    /// ````
1113    ///
1114    /// Sets the *delegate* property to the given value.
1115    pub fn delegate(
1116        mut self,
1117        new_value: &'a mut dyn common::Delegate,
1118    ) -> LicenseAssignmentGetCall<'a, C> {
1119        self._delegate = Some(new_value);
1120        self
1121    }
1122
1123    /// Set any additional parameter of the query string used in the request.
1124    /// It should be used to set parameters which are not yet available through their own
1125    /// setters.
1126    ///
1127    /// Please note that this method must not be used to set any of the known parameters
1128    /// which have their own setter method. If done anyway, the request will fail.
1129    ///
1130    /// # Additional Parameters
1131    ///
1132    /// * *$.xgafv* (query-string) - V1 error format.
1133    /// * *access_token* (query-string) - OAuth access token.
1134    /// * *alt* (query-string) - Data format for response.
1135    /// * *callback* (query-string) - JSONP
1136    /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
1137    /// * *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.
1138    /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
1139    /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
1140    /// * *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.
1141    /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
1142    /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
1143    pub fn param<T>(mut self, name: T, value: T) -> LicenseAssignmentGetCall<'a, C>
1144    where
1145        T: AsRef<str>,
1146    {
1147        self._additional_params
1148            .insert(name.as_ref().to_string(), value.as_ref().to_string());
1149        self
1150    }
1151
1152    /// Identifies the authorization scope for the method you are building.
1153    ///
1154    /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
1155    /// [`Scope::AppLicensing`].
1156    ///
1157    /// The `scope` will be added to a set of scopes. This is important as one can maintain access
1158    /// tokens for more than one scope.
1159    ///
1160    /// Usually there is more than one suitable scope to authorize an operation, some of which may
1161    /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
1162    /// sufficient, a read-write scope will do as well.
1163    pub fn add_scope<St>(mut self, scope: St) -> LicenseAssignmentGetCall<'a, C>
1164    where
1165        St: AsRef<str>,
1166    {
1167        self._scopes.insert(String::from(scope.as_ref()));
1168        self
1169    }
1170    /// Identifies the authorization scope(s) for the method you are building.
1171    ///
1172    /// See [`Self::add_scope()`] for details.
1173    pub fn add_scopes<I, St>(mut self, scopes: I) -> LicenseAssignmentGetCall<'a, C>
1174    where
1175        I: IntoIterator<Item = St>,
1176        St: AsRef<str>,
1177    {
1178        self._scopes
1179            .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
1180        self
1181    }
1182
1183    /// Removes all scopes, and no default scope will be used either.
1184    /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
1185    /// for details).
1186    pub fn clear_scopes(mut self) -> LicenseAssignmentGetCall<'a, C> {
1187        self._scopes.clear();
1188        self
1189    }
1190}
1191
1192/// Assign a license.
1193///
1194/// A builder for the *insert* method supported by a *licenseAssignment* resource.
1195/// It is not used directly, but through a [`LicenseAssignmentMethods`] instance.
1196///
1197/// # Example
1198///
1199/// Instantiate a resource method builder
1200///
1201/// ```test_harness,no_run
1202/// # extern crate hyper;
1203/// # extern crate hyper_rustls;
1204/// # extern crate google_licensing1 as licensing1;
1205/// use licensing1::api::LicenseAssignmentInsert;
1206/// # async fn dox() {
1207/// # use licensing1::{Licensing, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
1208///
1209/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
1210/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
1211/// #     .with_native_roots()
1212/// #     .unwrap()
1213/// #     .https_only()
1214/// #     .enable_http2()
1215/// #     .build();
1216///
1217/// # let executor = hyper_util::rt::TokioExecutor::new();
1218/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
1219/// #     secret,
1220/// #     yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
1221/// #     yup_oauth2::client::CustomHyperClientBuilder::from(
1222/// #         hyper_util::client::legacy::Client::builder(executor).build(connector),
1223/// #     ),
1224/// # ).build().await.unwrap();
1225///
1226/// # let client = hyper_util::client::legacy::Client::builder(
1227/// #     hyper_util::rt::TokioExecutor::new()
1228/// # )
1229/// # .build(
1230/// #     hyper_rustls::HttpsConnectorBuilder::new()
1231/// #         .with_native_roots()
1232/// #         .unwrap()
1233/// #         .https_or_http()
1234/// #         .enable_http2()
1235/// #         .build()
1236/// # );
1237/// # let mut hub = Licensing::new(client, auth);
1238/// // As the method needs a request, you would usually fill it with the desired information
1239/// // into the respective structure. Some of the parts shown here might not be applicable !
1240/// // Values shown here are possibly random and not representative !
1241/// let mut req = LicenseAssignmentInsert::default();
1242///
1243/// // You can configure optional parameters by calling the respective setters at will, and
1244/// // execute the final call using `doit()`.
1245/// // Values shown here are possibly random and not representative !
1246/// let result = hub.license_assignments().insert(req, "productId", "skuId")
1247///              .doit().await;
1248/// # }
1249/// ```
1250pub struct LicenseAssignmentInsertCall<'a, C>
1251where
1252    C: 'a,
1253{
1254    hub: &'a Licensing<C>,
1255    _request: LicenseAssignmentInsert,
1256    _product_id: String,
1257    _sku_id: String,
1258    _delegate: Option<&'a mut dyn common::Delegate>,
1259    _additional_params: HashMap<String, String>,
1260    _scopes: BTreeSet<String>,
1261}
1262
1263impl<'a, C> common::CallBuilder for LicenseAssignmentInsertCall<'a, C> {}
1264
1265impl<'a, C> LicenseAssignmentInsertCall<'a, C>
1266where
1267    C: common::Connector,
1268{
1269    /// Perform the operation you have build so far.
1270    pub async fn doit(mut self) -> common::Result<(common::Response, LicenseAssignment)> {
1271        use std::borrow::Cow;
1272        use std::io::{Read, Seek};
1273
1274        use common::{url::Params, ToParts};
1275        use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
1276
1277        let mut dd = common::DefaultDelegate;
1278        let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
1279        dlg.begin(common::MethodInfo {
1280            id: "licensing.licenseAssignments.insert",
1281            http_method: hyper::Method::POST,
1282        });
1283
1284        for &field in ["alt", "productId", "skuId"].iter() {
1285            if self._additional_params.contains_key(field) {
1286                dlg.finished(false);
1287                return Err(common::Error::FieldClash(field));
1288            }
1289        }
1290
1291        let mut params = Params::with_capacity(5 + self._additional_params.len());
1292        params.push("productId", self._product_id);
1293        params.push("skuId", self._sku_id);
1294
1295        params.extend(self._additional_params.iter());
1296
1297        params.push("alt", "json");
1298        let mut url =
1299            self.hub._base_url.clone() + "apps/licensing/v1/product/{productId}/sku/{skuId}/user";
1300        if self._scopes.is_empty() {
1301            self._scopes
1302                .insert(Scope::AppLicensing.as_ref().to_string());
1303        }
1304
1305        #[allow(clippy::single_element_loop)]
1306        for &(find_this, param_name) in [("{productId}", "productId"), ("{skuId}", "skuId")].iter()
1307        {
1308            url = params.uri_replacement(url, param_name, find_this, false);
1309        }
1310        {
1311            let to_remove = ["skuId", "productId"];
1312            params.remove_params(&to_remove);
1313        }
1314
1315        let url = params.parse_with_url(&url);
1316
1317        let mut json_mime_type = mime::APPLICATION_JSON;
1318        let mut request_value_reader = {
1319            let mut value = serde_json::value::to_value(&self._request).expect("serde to work");
1320            common::remove_json_null_values(&mut value);
1321            let mut dst = std::io::Cursor::new(Vec::with_capacity(128));
1322            serde_json::to_writer(&mut dst, &value).unwrap();
1323            dst
1324        };
1325        let request_size = request_value_reader
1326            .seek(std::io::SeekFrom::End(0))
1327            .unwrap();
1328        request_value_reader
1329            .seek(std::io::SeekFrom::Start(0))
1330            .unwrap();
1331
1332        loop {
1333            let token = match self
1334                .hub
1335                .auth
1336                .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
1337                .await
1338            {
1339                Ok(token) => token,
1340                Err(e) => match dlg.token(e) {
1341                    Ok(token) => token,
1342                    Err(e) => {
1343                        dlg.finished(false);
1344                        return Err(common::Error::MissingToken(e));
1345                    }
1346                },
1347            };
1348            request_value_reader
1349                .seek(std::io::SeekFrom::Start(0))
1350                .unwrap();
1351            let mut req_result = {
1352                let client = &self.hub.client;
1353                dlg.pre_request();
1354                let mut req_builder = hyper::Request::builder()
1355                    .method(hyper::Method::POST)
1356                    .uri(url.as_str())
1357                    .header(USER_AGENT, self.hub._user_agent.clone());
1358
1359                if let Some(token) = token.as_ref() {
1360                    req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
1361                }
1362
1363                let request = req_builder
1364                    .header(CONTENT_TYPE, json_mime_type.to_string())
1365                    .header(CONTENT_LENGTH, request_size as u64)
1366                    .body(common::to_body(
1367                        request_value_reader.get_ref().clone().into(),
1368                    ));
1369
1370                client.request(request.unwrap()).await
1371            };
1372
1373            match req_result {
1374                Err(err) => {
1375                    if let common::Retry::After(d) = dlg.http_error(&err) {
1376                        sleep(d).await;
1377                        continue;
1378                    }
1379                    dlg.finished(false);
1380                    return Err(common::Error::HttpError(err));
1381                }
1382                Ok(res) => {
1383                    let (mut parts, body) = res.into_parts();
1384                    let mut body = common::Body::new(body);
1385                    if !parts.status.is_success() {
1386                        let bytes = common::to_bytes(body).await.unwrap_or_default();
1387                        let error = serde_json::from_str(&common::to_string(&bytes));
1388                        let response = common::to_response(parts, bytes.into());
1389
1390                        if let common::Retry::After(d) =
1391                            dlg.http_failure(&response, error.as_ref().ok())
1392                        {
1393                            sleep(d).await;
1394                            continue;
1395                        }
1396
1397                        dlg.finished(false);
1398
1399                        return Err(match error {
1400                            Ok(value) => common::Error::BadRequest(value),
1401                            _ => common::Error::Failure(response),
1402                        });
1403                    }
1404                    let response = {
1405                        let bytes = common::to_bytes(body).await.unwrap_or_default();
1406                        let encoded = common::to_string(&bytes);
1407                        match serde_json::from_str(&encoded) {
1408                            Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
1409                            Err(error) => {
1410                                dlg.response_json_decode_error(&encoded, &error);
1411                                return Err(common::Error::JsonDecodeError(
1412                                    encoded.to_string(),
1413                                    error,
1414                                ));
1415                            }
1416                        }
1417                    };
1418
1419                    dlg.finished(true);
1420                    return Ok(response);
1421                }
1422            }
1423        }
1424    }
1425
1426    ///
1427    /// Sets the *request* property to the given value.
1428    ///
1429    /// Even though the property as already been set when instantiating this call,
1430    /// we provide this method for API completeness.
1431    pub fn request(
1432        mut self,
1433        new_value: LicenseAssignmentInsert,
1434    ) -> LicenseAssignmentInsertCall<'a, C> {
1435        self._request = new_value;
1436        self
1437    }
1438    /// A product's unique identifier. For more information about products in this version of the API, see Products and SKUs.
1439    ///
1440    /// Sets the *product id* path property to the given value.
1441    ///
1442    /// Even though the property as already been set when instantiating this call,
1443    /// we provide this method for API completeness.
1444    pub fn product_id(mut self, new_value: &str) -> LicenseAssignmentInsertCall<'a, C> {
1445        self._product_id = new_value.to_string();
1446        self
1447    }
1448    /// A product SKU's unique identifier. For more information about available SKUs in this version of the API, see Products and SKUs.
1449    ///
1450    /// Sets the *sku id* path property to the given value.
1451    ///
1452    /// Even though the property as already been set when instantiating this call,
1453    /// we provide this method for API completeness.
1454    pub fn sku_id(mut self, new_value: &str) -> LicenseAssignmentInsertCall<'a, C> {
1455        self._sku_id = new_value.to_string();
1456        self
1457    }
1458    /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
1459    /// while executing the actual API request.
1460    ///
1461    /// ````text
1462    ///                   It should be used to handle progress information, and to implement a certain level of resilience.
1463    /// ````
1464    ///
1465    /// Sets the *delegate* property to the given value.
1466    pub fn delegate(
1467        mut self,
1468        new_value: &'a mut dyn common::Delegate,
1469    ) -> LicenseAssignmentInsertCall<'a, C> {
1470        self._delegate = Some(new_value);
1471        self
1472    }
1473
1474    /// Set any additional parameter of the query string used in the request.
1475    /// It should be used to set parameters which are not yet available through their own
1476    /// setters.
1477    ///
1478    /// Please note that this method must not be used to set any of the known parameters
1479    /// which have their own setter method. If done anyway, the request will fail.
1480    ///
1481    /// # Additional Parameters
1482    ///
1483    /// * *$.xgafv* (query-string) - V1 error format.
1484    /// * *access_token* (query-string) - OAuth access token.
1485    /// * *alt* (query-string) - Data format for response.
1486    /// * *callback* (query-string) - JSONP
1487    /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
1488    /// * *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.
1489    /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
1490    /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
1491    /// * *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.
1492    /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
1493    /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
1494    pub fn param<T>(mut self, name: T, value: T) -> LicenseAssignmentInsertCall<'a, C>
1495    where
1496        T: AsRef<str>,
1497    {
1498        self._additional_params
1499            .insert(name.as_ref().to_string(), value.as_ref().to_string());
1500        self
1501    }
1502
1503    /// Identifies the authorization scope for the method you are building.
1504    ///
1505    /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
1506    /// [`Scope::AppLicensing`].
1507    ///
1508    /// The `scope` will be added to a set of scopes. This is important as one can maintain access
1509    /// tokens for more than one scope.
1510    ///
1511    /// Usually there is more than one suitable scope to authorize an operation, some of which may
1512    /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
1513    /// sufficient, a read-write scope will do as well.
1514    pub fn add_scope<St>(mut self, scope: St) -> LicenseAssignmentInsertCall<'a, C>
1515    where
1516        St: AsRef<str>,
1517    {
1518        self._scopes.insert(String::from(scope.as_ref()));
1519        self
1520    }
1521    /// Identifies the authorization scope(s) for the method you are building.
1522    ///
1523    /// See [`Self::add_scope()`] for details.
1524    pub fn add_scopes<I, St>(mut self, scopes: I) -> LicenseAssignmentInsertCall<'a, C>
1525    where
1526        I: IntoIterator<Item = St>,
1527        St: AsRef<str>,
1528    {
1529        self._scopes
1530            .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
1531        self
1532    }
1533
1534    /// Removes all scopes, and no default scope will be used either.
1535    /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
1536    /// for details).
1537    pub fn clear_scopes(mut self) -> LicenseAssignmentInsertCall<'a, C> {
1538        self._scopes.clear();
1539        self
1540    }
1541}
1542
1543/// List all users assigned licenses for a specific product SKU.
1544///
1545/// A builder for the *listForProduct* method supported by a *licenseAssignment* resource.
1546/// It is not used directly, but through a [`LicenseAssignmentMethods`] instance.
1547///
1548/// # Example
1549///
1550/// Instantiate a resource method builder
1551///
1552/// ```test_harness,no_run
1553/// # extern crate hyper;
1554/// # extern crate hyper_rustls;
1555/// # extern crate google_licensing1 as licensing1;
1556/// # async fn dox() {
1557/// # use licensing1::{Licensing, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
1558///
1559/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
1560/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
1561/// #     .with_native_roots()
1562/// #     .unwrap()
1563/// #     .https_only()
1564/// #     .enable_http2()
1565/// #     .build();
1566///
1567/// # let executor = hyper_util::rt::TokioExecutor::new();
1568/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
1569/// #     secret,
1570/// #     yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
1571/// #     yup_oauth2::client::CustomHyperClientBuilder::from(
1572/// #         hyper_util::client::legacy::Client::builder(executor).build(connector),
1573/// #     ),
1574/// # ).build().await.unwrap();
1575///
1576/// # let client = hyper_util::client::legacy::Client::builder(
1577/// #     hyper_util::rt::TokioExecutor::new()
1578/// # )
1579/// # .build(
1580/// #     hyper_rustls::HttpsConnectorBuilder::new()
1581/// #         .with_native_roots()
1582/// #         .unwrap()
1583/// #         .https_or_http()
1584/// #         .enable_http2()
1585/// #         .build()
1586/// # );
1587/// # let mut hub = Licensing::new(client, auth);
1588/// // You can configure optional parameters by calling the respective setters at will, and
1589/// // execute the final call using `doit()`.
1590/// // Values shown here are possibly random and not representative !
1591/// let result = hub.license_assignments().list_for_product("productId", "customerId")
1592///              .page_token("ut")
1593///              .max_results(89)
1594///              .doit().await;
1595/// # }
1596/// ```
1597pub struct LicenseAssignmentListForProductCall<'a, C>
1598where
1599    C: 'a,
1600{
1601    hub: &'a Licensing<C>,
1602    _product_id: String,
1603    _customer_id: String,
1604    _page_token: Option<String>,
1605    _max_results: Option<u32>,
1606    _delegate: Option<&'a mut dyn common::Delegate>,
1607    _additional_params: HashMap<String, String>,
1608    _scopes: BTreeSet<String>,
1609}
1610
1611impl<'a, C> common::CallBuilder for LicenseAssignmentListForProductCall<'a, C> {}
1612
1613impl<'a, C> LicenseAssignmentListForProductCall<'a, C>
1614where
1615    C: common::Connector,
1616{
1617    /// Perform the operation you have build so far.
1618    pub async fn doit(mut self) -> common::Result<(common::Response, LicenseAssignmentList)> {
1619        use std::borrow::Cow;
1620        use std::io::{Read, Seek};
1621
1622        use common::{url::Params, ToParts};
1623        use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
1624
1625        let mut dd = common::DefaultDelegate;
1626        let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
1627        dlg.begin(common::MethodInfo {
1628            id: "licensing.licenseAssignments.listForProduct",
1629            http_method: hyper::Method::GET,
1630        });
1631
1632        for &field in ["alt", "productId", "customerId", "pageToken", "maxResults"].iter() {
1633            if self._additional_params.contains_key(field) {
1634                dlg.finished(false);
1635                return Err(common::Error::FieldClash(field));
1636            }
1637        }
1638
1639        let mut params = Params::with_capacity(6 + self._additional_params.len());
1640        params.push("productId", self._product_id);
1641        params.push("customerId", self._customer_id);
1642        if let Some(value) = self._page_token.as_ref() {
1643            params.push("pageToken", value);
1644        }
1645        if let Some(value) = self._max_results.as_ref() {
1646            params.push("maxResults", value.to_string());
1647        }
1648
1649        params.extend(self._additional_params.iter());
1650
1651        params.push("alt", "json");
1652        let mut url = self.hub._base_url.clone() + "apps/licensing/v1/product/{productId}/users";
1653        if self._scopes.is_empty() {
1654            self._scopes
1655                .insert(Scope::AppLicensing.as_ref().to_string());
1656        }
1657
1658        #[allow(clippy::single_element_loop)]
1659        for &(find_this, param_name) in [("{productId}", "productId")].iter() {
1660            url = params.uri_replacement(url, param_name, find_this, false);
1661        }
1662        {
1663            let to_remove = ["productId"];
1664            params.remove_params(&to_remove);
1665        }
1666
1667        let url = params.parse_with_url(&url);
1668
1669        loop {
1670            let token = match self
1671                .hub
1672                .auth
1673                .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
1674                .await
1675            {
1676                Ok(token) => token,
1677                Err(e) => match dlg.token(e) {
1678                    Ok(token) => token,
1679                    Err(e) => {
1680                        dlg.finished(false);
1681                        return Err(common::Error::MissingToken(e));
1682                    }
1683                },
1684            };
1685            let mut req_result = {
1686                let client = &self.hub.client;
1687                dlg.pre_request();
1688                let mut req_builder = hyper::Request::builder()
1689                    .method(hyper::Method::GET)
1690                    .uri(url.as_str())
1691                    .header(USER_AGENT, self.hub._user_agent.clone());
1692
1693                if let Some(token) = token.as_ref() {
1694                    req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
1695                }
1696
1697                let request = req_builder
1698                    .header(CONTENT_LENGTH, 0_u64)
1699                    .body(common::to_body::<String>(None));
1700
1701                client.request(request.unwrap()).await
1702            };
1703
1704            match req_result {
1705                Err(err) => {
1706                    if let common::Retry::After(d) = dlg.http_error(&err) {
1707                        sleep(d).await;
1708                        continue;
1709                    }
1710                    dlg.finished(false);
1711                    return Err(common::Error::HttpError(err));
1712                }
1713                Ok(res) => {
1714                    let (mut parts, body) = res.into_parts();
1715                    let mut body = common::Body::new(body);
1716                    if !parts.status.is_success() {
1717                        let bytes = common::to_bytes(body).await.unwrap_or_default();
1718                        let error = serde_json::from_str(&common::to_string(&bytes));
1719                        let response = common::to_response(parts, bytes.into());
1720
1721                        if let common::Retry::After(d) =
1722                            dlg.http_failure(&response, error.as_ref().ok())
1723                        {
1724                            sleep(d).await;
1725                            continue;
1726                        }
1727
1728                        dlg.finished(false);
1729
1730                        return Err(match error {
1731                            Ok(value) => common::Error::BadRequest(value),
1732                            _ => common::Error::Failure(response),
1733                        });
1734                    }
1735                    let response = {
1736                        let bytes = common::to_bytes(body).await.unwrap_or_default();
1737                        let encoded = common::to_string(&bytes);
1738                        match serde_json::from_str(&encoded) {
1739                            Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
1740                            Err(error) => {
1741                                dlg.response_json_decode_error(&encoded, &error);
1742                                return Err(common::Error::JsonDecodeError(
1743                                    encoded.to_string(),
1744                                    error,
1745                                ));
1746                            }
1747                        }
1748                    };
1749
1750                    dlg.finished(true);
1751                    return Ok(response);
1752                }
1753            }
1754        }
1755    }
1756
1757    /// A product's unique identifier. For more information about products in this version of the API, see Products and SKUs.
1758    ///
1759    /// Sets the *product id* path property to the given value.
1760    ///
1761    /// Even though the property as already been set when instantiating this call,
1762    /// we provide this method for API completeness.
1763    pub fn product_id(mut self, new_value: &str) -> LicenseAssignmentListForProductCall<'a, C> {
1764        self._product_id = new_value.to_string();
1765        self
1766    }
1767    /// The customer's unique ID as defined in the Admin console, such as `C00000000`. If the customer is suspended, the server returns an error.
1768    ///
1769    /// Sets the *customer id* query property to the given value.
1770    ///
1771    /// Even though the property as already been set when instantiating this call,
1772    /// we provide this method for API completeness.
1773    pub fn customer_id(mut self, new_value: &str) -> LicenseAssignmentListForProductCall<'a, C> {
1774        self._customer_id = new_value.to_string();
1775        self
1776    }
1777    /// Token to fetch the next page of data. The `maxResults` query string is related to the `pageToken` since `maxResults` determines how many entries are returned on each page. This is an optional query string. If not specified, the server returns the first page.
1778    ///
1779    /// Sets the *page token* query property to the given value.
1780    pub fn page_token(mut self, new_value: &str) -> LicenseAssignmentListForProductCall<'a, C> {
1781        self._page_token = Some(new_value.to_string());
1782        self
1783    }
1784    /// The `maxResults` query string determines how many entries are returned on each page of a large response. This is an optional parameter. The value must be a positive number.
1785    ///
1786    /// Sets the *max results* query property to the given value.
1787    pub fn max_results(mut self, new_value: u32) -> LicenseAssignmentListForProductCall<'a, C> {
1788        self._max_results = Some(new_value);
1789        self
1790    }
1791    /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
1792    /// while executing the actual API request.
1793    ///
1794    /// ````text
1795    ///                   It should be used to handle progress information, and to implement a certain level of resilience.
1796    /// ````
1797    ///
1798    /// Sets the *delegate* property to the given value.
1799    pub fn delegate(
1800        mut self,
1801        new_value: &'a mut dyn common::Delegate,
1802    ) -> LicenseAssignmentListForProductCall<'a, C> {
1803        self._delegate = Some(new_value);
1804        self
1805    }
1806
1807    /// Set any additional parameter of the query string used in the request.
1808    /// It should be used to set parameters which are not yet available through their own
1809    /// setters.
1810    ///
1811    /// Please note that this method must not be used to set any of the known parameters
1812    /// which have their own setter method. If done anyway, the request will fail.
1813    ///
1814    /// # Additional Parameters
1815    ///
1816    /// * *$.xgafv* (query-string) - V1 error format.
1817    /// * *access_token* (query-string) - OAuth access token.
1818    /// * *alt* (query-string) - Data format for response.
1819    /// * *callback* (query-string) - JSONP
1820    /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
1821    /// * *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.
1822    /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
1823    /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
1824    /// * *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.
1825    /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
1826    /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
1827    pub fn param<T>(mut self, name: T, value: T) -> LicenseAssignmentListForProductCall<'a, C>
1828    where
1829        T: AsRef<str>,
1830    {
1831        self._additional_params
1832            .insert(name.as_ref().to_string(), value.as_ref().to_string());
1833        self
1834    }
1835
1836    /// Identifies the authorization scope for the method you are building.
1837    ///
1838    /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
1839    /// [`Scope::AppLicensing`].
1840    ///
1841    /// The `scope` will be added to a set of scopes. This is important as one can maintain access
1842    /// tokens for more than one scope.
1843    ///
1844    /// Usually there is more than one suitable scope to authorize an operation, some of which may
1845    /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
1846    /// sufficient, a read-write scope will do as well.
1847    pub fn add_scope<St>(mut self, scope: St) -> LicenseAssignmentListForProductCall<'a, C>
1848    where
1849        St: AsRef<str>,
1850    {
1851        self._scopes.insert(String::from(scope.as_ref()));
1852        self
1853    }
1854    /// Identifies the authorization scope(s) for the method you are building.
1855    ///
1856    /// See [`Self::add_scope()`] for details.
1857    pub fn add_scopes<I, St>(mut self, scopes: I) -> LicenseAssignmentListForProductCall<'a, C>
1858    where
1859        I: IntoIterator<Item = St>,
1860        St: AsRef<str>,
1861    {
1862        self._scopes
1863            .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
1864        self
1865    }
1866
1867    /// Removes all scopes, and no default scope will be used either.
1868    /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
1869    /// for details).
1870    pub fn clear_scopes(mut self) -> LicenseAssignmentListForProductCall<'a, C> {
1871        self._scopes.clear();
1872        self
1873    }
1874}
1875
1876/// List all users assigned licenses for a specific product SKU.
1877///
1878/// A builder for the *listForProductAndSku* method supported by a *licenseAssignment* resource.
1879/// It is not used directly, but through a [`LicenseAssignmentMethods`] instance.
1880///
1881/// # Example
1882///
1883/// Instantiate a resource method builder
1884///
1885/// ```test_harness,no_run
1886/// # extern crate hyper;
1887/// # extern crate hyper_rustls;
1888/// # extern crate google_licensing1 as licensing1;
1889/// # async fn dox() {
1890/// # use licensing1::{Licensing, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
1891///
1892/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
1893/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
1894/// #     .with_native_roots()
1895/// #     .unwrap()
1896/// #     .https_only()
1897/// #     .enable_http2()
1898/// #     .build();
1899///
1900/// # let executor = hyper_util::rt::TokioExecutor::new();
1901/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
1902/// #     secret,
1903/// #     yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
1904/// #     yup_oauth2::client::CustomHyperClientBuilder::from(
1905/// #         hyper_util::client::legacy::Client::builder(executor).build(connector),
1906/// #     ),
1907/// # ).build().await.unwrap();
1908///
1909/// # let client = hyper_util::client::legacy::Client::builder(
1910/// #     hyper_util::rt::TokioExecutor::new()
1911/// # )
1912/// # .build(
1913/// #     hyper_rustls::HttpsConnectorBuilder::new()
1914/// #         .with_native_roots()
1915/// #         .unwrap()
1916/// #         .https_or_http()
1917/// #         .enable_http2()
1918/// #         .build()
1919/// # );
1920/// # let mut hub = Licensing::new(client, auth);
1921/// // You can configure optional parameters by calling the respective setters at will, and
1922/// // execute the final call using `doit()`.
1923/// // Values shown here are possibly random and not representative !
1924/// let result = hub.license_assignments().list_for_product_and_sku("productId", "skuId", "customerId")
1925///              .page_token("ipsum")
1926///              .max_results(94)
1927///              .doit().await;
1928/// # }
1929/// ```
1930pub struct LicenseAssignmentListForProductAndSkuCall<'a, C>
1931where
1932    C: 'a,
1933{
1934    hub: &'a Licensing<C>,
1935    _product_id: String,
1936    _sku_id: String,
1937    _customer_id: String,
1938    _page_token: Option<String>,
1939    _max_results: Option<u32>,
1940    _delegate: Option<&'a mut dyn common::Delegate>,
1941    _additional_params: HashMap<String, String>,
1942    _scopes: BTreeSet<String>,
1943}
1944
1945impl<'a, C> common::CallBuilder for LicenseAssignmentListForProductAndSkuCall<'a, C> {}
1946
1947impl<'a, C> LicenseAssignmentListForProductAndSkuCall<'a, C>
1948where
1949    C: common::Connector,
1950{
1951    /// Perform the operation you have build so far.
1952    pub async fn doit(mut self) -> common::Result<(common::Response, LicenseAssignmentList)> {
1953        use std::borrow::Cow;
1954        use std::io::{Read, Seek};
1955
1956        use common::{url::Params, ToParts};
1957        use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
1958
1959        let mut dd = common::DefaultDelegate;
1960        let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
1961        dlg.begin(common::MethodInfo {
1962            id: "licensing.licenseAssignments.listForProductAndSku",
1963            http_method: hyper::Method::GET,
1964        });
1965
1966        for &field in [
1967            "alt",
1968            "productId",
1969            "skuId",
1970            "customerId",
1971            "pageToken",
1972            "maxResults",
1973        ]
1974        .iter()
1975        {
1976            if self._additional_params.contains_key(field) {
1977                dlg.finished(false);
1978                return Err(common::Error::FieldClash(field));
1979            }
1980        }
1981
1982        let mut params = Params::with_capacity(7 + self._additional_params.len());
1983        params.push("productId", self._product_id);
1984        params.push("skuId", self._sku_id);
1985        params.push("customerId", self._customer_id);
1986        if let Some(value) = self._page_token.as_ref() {
1987            params.push("pageToken", value);
1988        }
1989        if let Some(value) = self._max_results.as_ref() {
1990            params.push("maxResults", value.to_string());
1991        }
1992
1993        params.extend(self._additional_params.iter());
1994
1995        params.push("alt", "json");
1996        let mut url =
1997            self.hub._base_url.clone() + "apps/licensing/v1/product/{productId}/sku/{skuId}/users";
1998        if self._scopes.is_empty() {
1999            self._scopes
2000                .insert(Scope::AppLicensing.as_ref().to_string());
2001        }
2002
2003        #[allow(clippy::single_element_loop)]
2004        for &(find_this, param_name) in [("{productId}", "productId"), ("{skuId}", "skuId")].iter()
2005        {
2006            url = params.uri_replacement(url, param_name, find_this, false);
2007        }
2008        {
2009            let to_remove = ["skuId", "productId"];
2010            params.remove_params(&to_remove);
2011        }
2012
2013        let url = params.parse_with_url(&url);
2014
2015        loop {
2016            let token = match self
2017                .hub
2018                .auth
2019                .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
2020                .await
2021            {
2022                Ok(token) => token,
2023                Err(e) => match dlg.token(e) {
2024                    Ok(token) => token,
2025                    Err(e) => {
2026                        dlg.finished(false);
2027                        return Err(common::Error::MissingToken(e));
2028                    }
2029                },
2030            };
2031            let mut req_result = {
2032                let client = &self.hub.client;
2033                dlg.pre_request();
2034                let mut req_builder = hyper::Request::builder()
2035                    .method(hyper::Method::GET)
2036                    .uri(url.as_str())
2037                    .header(USER_AGENT, self.hub._user_agent.clone());
2038
2039                if let Some(token) = token.as_ref() {
2040                    req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
2041                }
2042
2043                let request = req_builder
2044                    .header(CONTENT_LENGTH, 0_u64)
2045                    .body(common::to_body::<String>(None));
2046
2047                client.request(request.unwrap()).await
2048            };
2049
2050            match req_result {
2051                Err(err) => {
2052                    if let common::Retry::After(d) = dlg.http_error(&err) {
2053                        sleep(d).await;
2054                        continue;
2055                    }
2056                    dlg.finished(false);
2057                    return Err(common::Error::HttpError(err));
2058                }
2059                Ok(res) => {
2060                    let (mut parts, body) = res.into_parts();
2061                    let mut body = common::Body::new(body);
2062                    if !parts.status.is_success() {
2063                        let bytes = common::to_bytes(body).await.unwrap_or_default();
2064                        let error = serde_json::from_str(&common::to_string(&bytes));
2065                        let response = common::to_response(parts, bytes.into());
2066
2067                        if let common::Retry::After(d) =
2068                            dlg.http_failure(&response, error.as_ref().ok())
2069                        {
2070                            sleep(d).await;
2071                            continue;
2072                        }
2073
2074                        dlg.finished(false);
2075
2076                        return Err(match error {
2077                            Ok(value) => common::Error::BadRequest(value),
2078                            _ => common::Error::Failure(response),
2079                        });
2080                    }
2081                    let response = {
2082                        let bytes = common::to_bytes(body).await.unwrap_or_default();
2083                        let encoded = common::to_string(&bytes);
2084                        match serde_json::from_str(&encoded) {
2085                            Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
2086                            Err(error) => {
2087                                dlg.response_json_decode_error(&encoded, &error);
2088                                return Err(common::Error::JsonDecodeError(
2089                                    encoded.to_string(),
2090                                    error,
2091                                ));
2092                            }
2093                        }
2094                    };
2095
2096                    dlg.finished(true);
2097                    return Ok(response);
2098                }
2099            }
2100        }
2101    }
2102
2103    /// A product's unique identifier. For more information about products in this version of the API, see Products and SKUs.
2104    ///
2105    /// Sets the *product id* path property to the given value.
2106    ///
2107    /// Even though the property as already been set when instantiating this call,
2108    /// we provide this method for API completeness.
2109    pub fn product_id(
2110        mut self,
2111        new_value: &str,
2112    ) -> LicenseAssignmentListForProductAndSkuCall<'a, C> {
2113        self._product_id = new_value.to_string();
2114        self
2115    }
2116    /// A product SKU's unique identifier. For more information about available SKUs in this version of the API, see Products and SKUs.
2117    ///
2118    /// Sets the *sku id* path property to the given value.
2119    ///
2120    /// Even though the property as already been set when instantiating this call,
2121    /// we provide this method for API completeness.
2122    pub fn sku_id(mut self, new_value: &str) -> LicenseAssignmentListForProductAndSkuCall<'a, C> {
2123        self._sku_id = new_value.to_string();
2124        self
2125    }
2126    /// The customer's unique ID as defined in the Admin console, such as `C00000000`. If the customer is suspended, the server returns an error.
2127    ///
2128    /// Sets the *customer id* query property to the given value.
2129    ///
2130    /// Even though the property as already been set when instantiating this call,
2131    /// we provide this method for API completeness.
2132    pub fn customer_id(
2133        mut self,
2134        new_value: &str,
2135    ) -> LicenseAssignmentListForProductAndSkuCall<'a, C> {
2136        self._customer_id = new_value.to_string();
2137        self
2138    }
2139    /// Token to fetch the next page of data. The `maxResults` query string is related to the `pageToken` since `maxResults` determines how many entries are returned on each page. This is an optional query string. If not specified, the server returns the first page.
2140    ///
2141    /// Sets the *page token* query property to the given value.
2142    pub fn page_token(
2143        mut self,
2144        new_value: &str,
2145    ) -> LicenseAssignmentListForProductAndSkuCall<'a, C> {
2146        self._page_token = Some(new_value.to_string());
2147        self
2148    }
2149    /// The `maxResults` query string determines how many entries are returned on each page of a large response. This is an optional parameter. The value must be a positive number.
2150    ///
2151    /// Sets the *max results* query property to the given value.
2152    pub fn max_results(
2153        mut self,
2154        new_value: u32,
2155    ) -> LicenseAssignmentListForProductAndSkuCall<'a, C> {
2156        self._max_results = Some(new_value);
2157        self
2158    }
2159    /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
2160    /// while executing the actual API request.
2161    ///
2162    /// ````text
2163    ///                   It should be used to handle progress information, and to implement a certain level of resilience.
2164    /// ````
2165    ///
2166    /// Sets the *delegate* property to the given value.
2167    pub fn delegate(
2168        mut self,
2169        new_value: &'a mut dyn common::Delegate,
2170    ) -> LicenseAssignmentListForProductAndSkuCall<'a, C> {
2171        self._delegate = Some(new_value);
2172        self
2173    }
2174
2175    /// Set any additional parameter of the query string used in the request.
2176    /// It should be used to set parameters which are not yet available through their own
2177    /// setters.
2178    ///
2179    /// Please note that this method must not be used to set any of the known parameters
2180    /// which have their own setter method. If done anyway, the request will fail.
2181    ///
2182    /// # Additional Parameters
2183    ///
2184    /// * *$.xgafv* (query-string) - V1 error format.
2185    /// * *access_token* (query-string) - OAuth access token.
2186    /// * *alt* (query-string) - Data format for response.
2187    /// * *callback* (query-string) - JSONP
2188    /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
2189    /// * *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.
2190    /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
2191    /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
2192    /// * *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.
2193    /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
2194    /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
2195    pub fn param<T>(mut self, name: T, value: T) -> LicenseAssignmentListForProductAndSkuCall<'a, C>
2196    where
2197        T: AsRef<str>,
2198    {
2199        self._additional_params
2200            .insert(name.as_ref().to_string(), value.as_ref().to_string());
2201        self
2202    }
2203
2204    /// Identifies the authorization scope for the method you are building.
2205    ///
2206    /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
2207    /// [`Scope::AppLicensing`].
2208    ///
2209    /// The `scope` will be added to a set of scopes. This is important as one can maintain access
2210    /// tokens for more than one scope.
2211    ///
2212    /// Usually there is more than one suitable scope to authorize an operation, some of which may
2213    /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
2214    /// sufficient, a read-write scope will do as well.
2215    pub fn add_scope<St>(mut self, scope: St) -> LicenseAssignmentListForProductAndSkuCall<'a, C>
2216    where
2217        St: AsRef<str>,
2218    {
2219        self._scopes.insert(String::from(scope.as_ref()));
2220        self
2221    }
2222    /// Identifies the authorization scope(s) for the method you are building.
2223    ///
2224    /// See [`Self::add_scope()`] for details.
2225    pub fn add_scopes<I, St>(
2226        mut self,
2227        scopes: I,
2228    ) -> LicenseAssignmentListForProductAndSkuCall<'a, C>
2229    where
2230        I: IntoIterator<Item = St>,
2231        St: AsRef<str>,
2232    {
2233        self._scopes
2234            .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
2235        self
2236    }
2237
2238    /// Removes all scopes, and no default scope will be used either.
2239    /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
2240    /// for details).
2241    pub fn clear_scopes(mut self) -> LicenseAssignmentListForProductAndSkuCall<'a, C> {
2242        self._scopes.clear();
2243        self
2244    }
2245}
2246
2247/// Reassign a user's product SKU with a different SKU in the same product. This method supports patch semantics.
2248///
2249/// A builder for the *patch* method supported by a *licenseAssignment* resource.
2250/// It is not used directly, but through a [`LicenseAssignmentMethods`] instance.
2251///
2252/// # Example
2253///
2254/// Instantiate a resource method builder
2255///
2256/// ```test_harness,no_run
2257/// # extern crate hyper;
2258/// # extern crate hyper_rustls;
2259/// # extern crate google_licensing1 as licensing1;
2260/// use licensing1::api::LicenseAssignment;
2261/// # async fn dox() {
2262/// # use licensing1::{Licensing, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
2263///
2264/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
2265/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
2266/// #     .with_native_roots()
2267/// #     .unwrap()
2268/// #     .https_only()
2269/// #     .enable_http2()
2270/// #     .build();
2271///
2272/// # let executor = hyper_util::rt::TokioExecutor::new();
2273/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
2274/// #     secret,
2275/// #     yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
2276/// #     yup_oauth2::client::CustomHyperClientBuilder::from(
2277/// #         hyper_util::client::legacy::Client::builder(executor).build(connector),
2278/// #     ),
2279/// # ).build().await.unwrap();
2280///
2281/// # let client = hyper_util::client::legacy::Client::builder(
2282/// #     hyper_util::rt::TokioExecutor::new()
2283/// # )
2284/// # .build(
2285/// #     hyper_rustls::HttpsConnectorBuilder::new()
2286/// #         .with_native_roots()
2287/// #         .unwrap()
2288/// #         .https_or_http()
2289/// #         .enable_http2()
2290/// #         .build()
2291/// # );
2292/// # let mut hub = Licensing::new(client, auth);
2293/// // As the method needs a request, you would usually fill it with the desired information
2294/// // into the respective structure. Some of the parts shown here might not be applicable !
2295/// // Values shown here are possibly random and not representative !
2296/// let mut req = LicenseAssignment::default();
2297///
2298/// // You can configure optional parameters by calling the respective setters at will, and
2299/// // execute the final call using `doit()`.
2300/// // Values shown here are possibly random and not representative !
2301/// let result = hub.license_assignments().patch(req, "productId", "skuId", "userId")
2302///              .doit().await;
2303/// # }
2304/// ```
2305pub struct LicenseAssignmentPatchCall<'a, C>
2306where
2307    C: 'a,
2308{
2309    hub: &'a Licensing<C>,
2310    _request: LicenseAssignment,
2311    _product_id: String,
2312    _sku_id: String,
2313    _user_id: String,
2314    _delegate: Option<&'a mut dyn common::Delegate>,
2315    _additional_params: HashMap<String, String>,
2316    _scopes: BTreeSet<String>,
2317}
2318
2319impl<'a, C> common::CallBuilder for LicenseAssignmentPatchCall<'a, C> {}
2320
2321impl<'a, C> LicenseAssignmentPatchCall<'a, C>
2322where
2323    C: common::Connector,
2324{
2325    /// Perform the operation you have build so far.
2326    pub async fn doit(mut self) -> common::Result<(common::Response, LicenseAssignment)> {
2327        use std::borrow::Cow;
2328        use std::io::{Read, Seek};
2329
2330        use common::{url::Params, ToParts};
2331        use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
2332
2333        let mut dd = common::DefaultDelegate;
2334        let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
2335        dlg.begin(common::MethodInfo {
2336            id: "licensing.licenseAssignments.patch",
2337            http_method: hyper::Method::PATCH,
2338        });
2339
2340        for &field in ["alt", "productId", "skuId", "userId"].iter() {
2341            if self._additional_params.contains_key(field) {
2342                dlg.finished(false);
2343                return Err(common::Error::FieldClash(field));
2344            }
2345        }
2346
2347        let mut params = Params::with_capacity(6 + self._additional_params.len());
2348        params.push("productId", self._product_id);
2349        params.push("skuId", self._sku_id);
2350        params.push("userId", self._user_id);
2351
2352        params.extend(self._additional_params.iter());
2353
2354        params.push("alt", "json");
2355        let mut url = self.hub._base_url.clone()
2356            + "apps/licensing/v1/product/{productId}/sku/{skuId}/user/{userId}";
2357        if self._scopes.is_empty() {
2358            self._scopes
2359                .insert(Scope::AppLicensing.as_ref().to_string());
2360        }
2361
2362        #[allow(clippy::single_element_loop)]
2363        for &(find_this, param_name) in [
2364            ("{productId}", "productId"),
2365            ("{skuId}", "skuId"),
2366            ("{userId}", "userId"),
2367        ]
2368        .iter()
2369        {
2370            url = params.uri_replacement(url, param_name, find_this, false);
2371        }
2372        {
2373            let to_remove = ["userId", "skuId", "productId"];
2374            params.remove_params(&to_remove);
2375        }
2376
2377        let url = params.parse_with_url(&url);
2378
2379        let mut json_mime_type = mime::APPLICATION_JSON;
2380        let mut request_value_reader = {
2381            let mut value = serde_json::value::to_value(&self._request).expect("serde to work");
2382            common::remove_json_null_values(&mut value);
2383            let mut dst = std::io::Cursor::new(Vec::with_capacity(128));
2384            serde_json::to_writer(&mut dst, &value).unwrap();
2385            dst
2386        };
2387        let request_size = request_value_reader
2388            .seek(std::io::SeekFrom::End(0))
2389            .unwrap();
2390        request_value_reader
2391            .seek(std::io::SeekFrom::Start(0))
2392            .unwrap();
2393
2394        loop {
2395            let token = match self
2396                .hub
2397                .auth
2398                .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
2399                .await
2400            {
2401                Ok(token) => token,
2402                Err(e) => match dlg.token(e) {
2403                    Ok(token) => token,
2404                    Err(e) => {
2405                        dlg.finished(false);
2406                        return Err(common::Error::MissingToken(e));
2407                    }
2408                },
2409            };
2410            request_value_reader
2411                .seek(std::io::SeekFrom::Start(0))
2412                .unwrap();
2413            let mut req_result = {
2414                let client = &self.hub.client;
2415                dlg.pre_request();
2416                let mut req_builder = hyper::Request::builder()
2417                    .method(hyper::Method::PATCH)
2418                    .uri(url.as_str())
2419                    .header(USER_AGENT, self.hub._user_agent.clone());
2420
2421                if let Some(token) = token.as_ref() {
2422                    req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
2423                }
2424
2425                let request = req_builder
2426                    .header(CONTENT_TYPE, json_mime_type.to_string())
2427                    .header(CONTENT_LENGTH, request_size as u64)
2428                    .body(common::to_body(
2429                        request_value_reader.get_ref().clone().into(),
2430                    ));
2431
2432                client.request(request.unwrap()).await
2433            };
2434
2435            match req_result {
2436                Err(err) => {
2437                    if let common::Retry::After(d) = dlg.http_error(&err) {
2438                        sleep(d).await;
2439                        continue;
2440                    }
2441                    dlg.finished(false);
2442                    return Err(common::Error::HttpError(err));
2443                }
2444                Ok(res) => {
2445                    let (mut parts, body) = res.into_parts();
2446                    let mut body = common::Body::new(body);
2447                    if !parts.status.is_success() {
2448                        let bytes = common::to_bytes(body).await.unwrap_or_default();
2449                        let error = serde_json::from_str(&common::to_string(&bytes));
2450                        let response = common::to_response(parts, bytes.into());
2451
2452                        if let common::Retry::After(d) =
2453                            dlg.http_failure(&response, error.as_ref().ok())
2454                        {
2455                            sleep(d).await;
2456                            continue;
2457                        }
2458
2459                        dlg.finished(false);
2460
2461                        return Err(match error {
2462                            Ok(value) => common::Error::BadRequest(value),
2463                            _ => common::Error::Failure(response),
2464                        });
2465                    }
2466                    let response = {
2467                        let bytes = common::to_bytes(body).await.unwrap_or_default();
2468                        let encoded = common::to_string(&bytes);
2469                        match serde_json::from_str(&encoded) {
2470                            Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
2471                            Err(error) => {
2472                                dlg.response_json_decode_error(&encoded, &error);
2473                                return Err(common::Error::JsonDecodeError(
2474                                    encoded.to_string(),
2475                                    error,
2476                                ));
2477                            }
2478                        }
2479                    };
2480
2481                    dlg.finished(true);
2482                    return Ok(response);
2483                }
2484            }
2485        }
2486    }
2487
2488    ///
2489    /// Sets the *request* property to the given value.
2490    ///
2491    /// Even though the property as already been set when instantiating this call,
2492    /// we provide this method for API completeness.
2493    pub fn request(mut self, new_value: LicenseAssignment) -> LicenseAssignmentPatchCall<'a, C> {
2494        self._request = new_value;
2495        self
2496    }
2497    /// A product's unique identifier. For more information about products in this version of the API, see Products and SKUs.
2498    ///
2499    /// Sets the *product id* path property to the given value.
2500    ///
2501    /// Even though the property as already been set when instantiating this call,
2502    /// we provide this method for API completeness.
2503    pub fn product_id(mut self, new_value: &str) -> LicenseAssignmentPatchCall<'a, C> {
2504        self._product_id = new_value.to_string();
2505        self
2506    }
2507    /// A product SKU's unique identifier. For more information about available SKUs in this version of the API, see Products and SKUs.
2508    ///
2509    /// Sets the *sku id* path property to the given value.
2510    ///
2511    /// Even though the property as already been set when instantiating this call,
2512    /// we provide this method for API completeness.
2513    pub fn sku_id(mut self, new_value: &str) -> LicenseAssignmentPatchCall<'a, C> {
2514        self._sku_id = new_value.to_string();
2515        self
2516    }
2517    /// The user's current primary email address. If the user's email address changes, use the new email address in your API requests. Since a `userId` is subject to change, do not use a `userId` value as a key for persistent data. This key could break if the current user's email address changes. If the `userId` is suspended, the license status changes.
2518    ///
2519    /// Sets the *user id* path property to the given value.
2520    ///
2521    /// Even though the property as already been set when instantiating this call,
2522    /// we provide this method for API completeness.
2523    pub fn user_id(mut self, new_value: &str) -> LicenseAssignmentPatchCall<'a, C> {
2524        self._user_id = new_value.to_string();
2525        self
2526    }
2527    /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
2528    /// while executing the actual API request.
2529    ///
2530    /// ````text
2531    ///                   It should be used to handle progress information, and to implement a certain level of resilience.
2532    /// ````
2533    ///
2534    /// Sets the *delegate* property to the given value.
2535    pub fn delegate(
2536        mut self,
2537        new_value: &'a mut dyn common::Delegate,
2538    ) -> LicenseAssignmentPatchCall<'a, C> {
2539        self._delegate = Some(new_value);
2540        self
2541    }
2542
2543    /// Set any additional parameter of the query string used in the request.
2544    /// It should be used to set parameters which are not yet available through their own
2545    /// setters.
2546    ///
2547    /// Please note that this method must not be used to set any of the known parameters
2548    /// which have their own setter method. If done anyway, the request will fail.
2549    ///
2550    /// # Additional Parameters
2551    ///
2552    /// * *$.xgafv* (query-string) - V1 error format.
2553    /// * *access_token* (query-string) - OAuth access token.
2554    /// * *alt* (query-string) - Data format for response.
2555    /// * *callback* (query-string) - JSONP
2556    /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
2557    /// * *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.
2558    /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
2559    /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
2560    /// * *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.
2561    /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
2562    /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
2563    pub fn param<T>(mut self, name: T, value: T) -> LicenseAssignmentPatchCall<'a, C>
2564    where
2565        T: AsRef<str>,
2566    {
2567        self._additional_params
2568            .insert(name.as_ref().to_string(), value.as_ref().to_string());
2569        self
2570    }
2571
2572    /// Identifies the authorization scope for the method you are building.
2573    ///
2574    /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
2575    /// [`Scope::AppLicensing`].
2576    ///
2577    /// The `scope` will be added to a set of scopes. This is important as one can maintain access
2578    /// tokens for more than one scope.
2579    ///
2580    /// Usually there is more than one suitable scope to authorize an operation, some of which may
2581    /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
2582    /// sufficient, a read-write scope will do as well.
2583    pub fn add_scope<St>(mut self, scope: St) -> LicenseAssignmentPatchCall<'a, C>
2584    where
2585        St: AsRef<str>,
2586    {
2587        self._scopes.insert(String::from(scope.as_ref()));
2588        self
2589    }
2590    /// Identifies the authorization scope(s) for the method you are building.
2591    ///
2592    /// See [`Self::add_scope()`] for details.
2593    pub fn add_scopes<I, St>(mut self, scopes: I) -> LicenseAssignmentPatchCall<'a, C>
2594    where
2595        I: IntoIterator<Item = St>,
2596        St: AsRef<str>,
2597    {
2598        self._scopes
2599            .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
2600        self
2601    }
2602
2603    /// Removes all scopes, and no default scope will be used either.
2604    /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
2605    /// for details).
2606    pub fn clear_scopes(mut self) -> LicenseAssignmentPatchCall<'a, C> {
2607        self._scopes.clear();
2608        self
2609    }
2610}
2611
2612/// Reassign a user's product SKU with a different SKU in the same product.
2613///
2614/// A builder for the *update* method supported by a *licenseAssignment* resource.
2615/// It is not used directly, but through a [`LicenseAssignmentMethods`] instance.
2616///
2617/// # Example
2618///
2619/// Instantiate a resource method builder
2620///
2621/// ```test_harness,no_run
2622/// # extern crate hyper;
2623/// # extern crate hyper_rustls;
2624/// # extern crate google_licensing1 as licensing1;
2625/// use licensing1::api::LicenseAssignment;
2626/// # async fn dox() {
2627/// # use licensing1::{Licensing, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
2628///
2629/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
2630/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
2631/// #     .with_native_roots()
2632/// #     .unwrap()
2633/// #     .https_only()
2634/// #     .enable_http2()
2635/// #     .build();
2636///
2637/// # let executor = hyper_util::rt::TokioExecutor::new();
2638/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
2639/// #     secret,
2640/// #     yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
2641/// #     yup_oauth2::client::CustomHyperClientBuilder::from(
2642/// #         hyper_util::client::legacy::Client::builder(executor).build(connector),
2643/// #     ),
2644/// # ).build().await.unwrap();
2645///
2646/// # let client = hyper_util::client::legacy::Client::builder(
2647/// #     hyper_util::rt::TokioExecutor::new()
2648/// # )
2649/// # .build(
2650/// #     hyper_rustls::HttpsConnectorBuilder::new()
2651/// #         .with_native_roots()
2652/// #         .unwrap()
2653/// #         .https_or_http()
2654/// #         .enable_http2()
2655/// #         .build()
2656/// # );
2657/// # let mut hub = Licensing::new(client, auth);
2658/// // As the method needs a request, you would usually fill it with the desired information
2659/// // into the respective structure. Some of the parts shown here might not be applicable !
2660/// // Values shown here are possibly random and not representative !
2661/// let mut req = LicenseAssignment::default();
2662///
2663/// // You can configure optional parameters by calling the respective setters at will, and
2664/// // execute the final call using `doit()`.
2665/// // Values shown here are possibly random and not representative !
2666/// let result = hub.license_assignments().update(req, "productId", "skuId", "userId")
2667///              .doit().await;
2668/// # }
2669/// ```
2670pub struct LicenseAssignmentUpdateCall<'a, C>
2671where
2672    C: 'a,
2673{
2674    hub: &'a Licensing<C>,
2675    _request: LicenseAssignment,
2676    _product_id: String,
2677    _sku_id: String,
2678    _user_id: String,
2679    _delegate: Option<&'a mut dyn common::Delegate>,
2680    _additional_params: HashMap<String, String>,
2681    _scopes: BTreeSet<String>,
2682}
2683
2684impl<'a, C> common::CallBuilder for LicenseAssignmentUpdateCall<'a, C> {}
2685
2686impl<'a, C> LicenseAssignmentUpdateCall<'a, C>
2687where
2688    C: common::Connector,
2689{
2690    /// Perform the operation you have build so far.
2691    pub async fn doit(mut self) -> common::Result<(common::Response, LicenseAssignment)> {
2692        use std::borrow::Cow;
2693        use std::io::{Read, Seek};
2694
2695        use common::{url::Params, ToParts};
2696        use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
2697
2698        let mut dd = common::DefaultDelegate;
2699        let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
2700        dlg.begin(common::MethodInfo {
2701            id: "licensing.licenseAssignments.update",
2702            http_method: hyper::Method::PUT,
2703        });
2704
2705        for &field in ["alt", "productId", "skuId", "userId"].iter() {
2706            if self._additional_params.contains_key(field) {
2707                dlg.finished(false);
2708                return Err(common::Error::FieldClash(field));
2709            }
2710        }
2711
2712        let mut params = Params::with_capacity(6 + self._additional_params.len());
2713        params.push("productId", self._product_id);
2714        params.push("skuId", self._sku_id);
2715        params.push("userId", self._user_id);
2716
2717        params.extend(self._additional_params.iter());
2718
2719        params.push("alt", "json");
2720        let mut url = self.hub._base_url.clone()
2721            + "apps/licensing/v1/product/{productId}/sku/{skuId}/user/{userId}";
2722        if self._scopes.is_empty() {
2723            self._scopes
2724                .insert(Scope::AppLicensing.as_ref().to_string());
2725        }
2726
2727        #[allow(clippy::single_element_loop)]
2728        for &(find_this, param_name) in [
2729            ("{productId}", "productId"),
2730            ("{skuId}", "skuId"),
2731            ("{userId}", "userId"),
2732        ]
2733        .iter()
2734        {
2735            url = params.uri_replacement(url, param_name, find_this, false);
2736        }
2737        {
2738            let to_remove = ["userId", "skuId", "productId"];
2739            params.remove_params(&to_remove);
2740        }
2741
2742        let url = params.parse_with_url(&url);
2743
2744        let mut json_mime_type = mime::APPLICATION_JSON;
2745        let mut request_value_reader = {
2746            let mut value = serde_json::value::to_value(&self._request).expect("serde to work");
2747            common::remove_json_null_values(&mut value);
2748            let mut dst = std::io::Cursor::new(Vec::with_capacity(128));
2749            serde_json::to_writer(&mut dst, &value).unwrap();
2750            dst
2751        };
2752        let request_size = request_value_reader
2753            .seek(std::io::SeekFrom::End(0))
2754            .unwrap();
2755        request_value_reader
2756            .seek(std::io::SeekFrom::Start(0))
2757            .unwrap();
2758
2759        loop {
2760            let token = match self
2761                .hub
2762                .auth
2763                .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
2764                .await
2765            {
2766                Ok(token) => token,
2767                Err(e) => match dlg.token(e) {
2768                    Ok(token) => token,
2769                    Err(e) => {
2770                        dlg.finished(false);
2771                        return Err(common::Error::MissingToken(e));
2772                    }
2773                },
2774            };
2775            request_value_reader
2776                .seek(std::io::SeekFrom::Start(0))
2777                .unwrap();
2778            let mut req_result = {
2779                let client = &self.hub.client;
2780                dlg.pre_request();
2781                let mut req_builder = hyper::Request::builder()
2782                    .method(hyper::Method::PUT)
2783                    .uri(url.as_str())
2784                    .header(USER_AGENT, self.hub._user_agent.clone());
2785
2786                if let Some(token) = token.as_ref() {
2787                    req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
2788                }
2789
2790                let request = req_builder
2791                    .header(CONTENT_TYPE, json_mime_type.to_string())
2792                    .header(CONTENT_LENGTH, request_size as u64)
2793                    .body(common::to_body(
2794                        request_value_reader.get_ref().clone().into(),
2795                    ));
2796
2797                client.request(request.unwrap()).await
2798            };
2799
2800            match req_result {
2801                Err(err) => {
2802                    if let common::Retry::After(d) = dlg.http_error(&err) {
2803                        sleep(d).await;
2804                        continue;
2805                    }
2806                    dlg.finished(false);
2807                    return Err(common::Error::HttpError(err));
2808                }
2809                Ok(res) => {
2810                    let (mut parts, body) = res.into_parts();
2811                    let mut body = common::Body::new(body);
2812                    if !parts.status.is_success() {
2813                        let bytes = common::to_bytes(body).await.unwrap_or_default();
2814                        let error = serde_json::from_str(&common::to_string(&bytes));
2815                        let response = common::to_response(parts, bytes.into());
2816
2817                        if let common::Retry::After(d) =
2818                            dlg.http_failure(&response, error.as_ref().ok())
2819                        {
2820                            sleep(d).await;
2821                            continue;
2822                        }
2823
2824                        dlg.finished(false);
2825
2826                        return Err(match error {
2827                            Ok(value) => common::Error::BadRequest(value),
2828                            _ => common::Error::Failure(response),
2829                        });
2830                    }
2831                    let response = {
2832                        let bytes = common::to_bytes(body).await.unwrap_or_default();
2833                        let encoded = common::to_string(&bytes);
2834                        match serde_json::from_str(&encoded) {
2835                            Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
2836                            Err(error) => {
2837                                dlg.response_json_decode_error(&encoded, &error);
2838                                return Err(common::Error::JsonDecodeError(
2839                                    encoded.to_string(),
2840                                    error,
2841                                ));
2842                            }
2843                        }
2844                    };
2845
2846                    dlg.finished(true);
2847                    return Ok(response);
2848                }
2849            }
2850        }
2851    }
2852
2853    ///
2854    /// Sets the *request* property to the given value.
2855    ///
2856    /// Even though the property as already been set when instantiating this call,
2857    /// we provide this method for API completeness.
2858    pub fn request(mut self, new_value: LicenseAssignment) -> LicenseAssignmentUpdateCall<'a, C> {
2859        self._request = new_value;
2860        self
2861    }
2862    /// A product's unique identifier. For more information about products in this version of the API, see Products and SKUs.
2863    ///
2864    /// Sets the *product id* path property to the given value.
2865    ///
2866    /// Even though the property as already been set when instantiating this call,
2867    /// we provide this method for API completeness.
2868    pub fn product_id(mut self, new_value: &str) -> LicenseAssignmentUpdateCall<'a, C> {
2869        self._product_id = new_value.to_string();
2870        self
2871    }
2872    /// A product SKU's unique identifier. For more information about available SKUs in this version of the API, see Products and SKUs.
2873    ///
2874    /// Sets the *sku id* path property to the given value.
2875    ///
2876    /// Even though the property as already been set when instantiating this call,
2877    /// we provide this method for API completeness.
2878    pub fn sku_id(mut self, new_value: &str) -> LicenseAssignmentUpdateCall<'a, C> {
2879        self._sku_id = new_value.to_string();
2880        self
2881    }
2882    /// The user's current primary email address. If the user's email address changes, use the new email address in your API requests. Since a `userId` is subject to change, do not use a `userId` value as a key for persistent data. This key could break if the current user's email address changes. If the `userId` is suspended, the license status changes.
2883    ///
2884    /// Sets the *user id* path property to the given value.
2885    ///
2886    /// Even though the property as already been set when instantiating this call,
2887    /// we provide this method for API completeness.
2888    pub fn user_id(mut self, new_value: &str) -> LicenseAssignmentUpdateCall<'a, C> {
2889        self._user_id = new_value.to_string();
2890        self
2891    }
2892    /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
2893    /// while executing the actual API request.
2894    ///
2895    /// ````text
2896    ///                   It should be used to handle progress information, and to implement a certain level of resilience.
2897    /// ````
2898    ///
2899    /// Sets the *delegate* property to the given value.
2900    pub fn delegate(
2901        mut self,
2902        new_value: &'a mut dyn common::Delegate,
2903    ) -> LicenseAssignmentUpdateCall<'a, C> {
2904        self._delegate = Some(new_value);
2905        self
2906    }
2907
2908    /// Set any additional parameter of the query string used in the request.
2909    /// It should be used to set parameters which are not yet available through their own
2910    /// setters.
2911    ///
2912    /// Please note that this method must not be used to set any of the known parameters
2913    /// which have their own setter method. If done anyway, the request will fail.
2914    ///
2915    /// # Additional Parameters
2916    ///
2917    /// * *$.xgafv* (query-string) - V1 error format.
2918    /// * *access_token* (query-string) - OAuth access token.
2919    /// * *alt* (query-string) - Data format for response.
2920    /// * *callback* (query-string) - JSONP
2921    /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
2922    /// * *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.
2923    /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
2924    /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
2925    /// * *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.
2926    /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
2927    /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
2928    pub fn param<T>(mut self, name: T, value: T) -> LicenseAssignmentUpdateCall<'a, C>
2929    where
2930        T: AsRef<str>,
2931    {
2932        self._additional_params
2933            .insert(name.as_ref().to_string(), value.as_ref().to_string());
2934        self
2935    }
2936
2937    /// Identifies the authorization scope for the method you are building.
2938    ///
2939    /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
2940    /// [`Scope::AppLicensing`].
2941    ///
2942    /// The `scope` will be added to a set of scopes. This is important as one can maintain access
2943    /// tokens for more than one scope.
2944    ///
2945    /// Usually there is more than one suitable scope to authorize an operation, some of which may
2946    /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
2947    /// sufficient, a read-write scope will do as well.
2948    pub fn add_scope<St>(mut self, scope: St) -> LicenseAssignmentUpdateCall<'a, C>
2949    where
2950        St: AsRef<str>,
2951    {
2952        self._scopes.insert(String::from(scope.as_ref()));
2953        self
2954    }
2955    /// Identifies the authorization scope(s) for the method you are building.
2956    ///
2957    /// See [`Self::add_scope()`] for details.
2958    pub fn add_scopes<I, St>(mut self, scopes: I) -> LicenseAssignmentUpdateCall<'a, C>
2959    where
2960        I: IntoIterator<Item = St>,
2961        St: AsRef<str>,
2962    {
2963        self._scopes
2964            .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
2965        self
2966    }
2967
2968    /// Removes all scopes, and no default scope will be used either.
2969    /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
2970    /// for details).
2971    pub fn clear_scopes(mut self) -> LicenseAssignmentUpdateCall<'a, C> {
2972        self._scopes.clear();
2973        self
2974    }
2975}