google_libraryagent1/
api.rs

1#![allow(clippy::ptr_arg)]
2
3use std::collections::{BTreeSet, HashMap};
4
5use tokio::time::sleep;
6
7// ##############
8// UTILITIES ###
9// ############
10
11/// Identifies the an OAuth2 authorization scope.
12/// A scope is needed when requesting an
13/// [authorization token](https://developers.google.com/youtube/v3/guides/authentication).
14#[derive(PartialEq, Eq, Ord, PartialOrd, Hash, Debug, Clone, Copy)]
15pub enum Scope {
16    /// See, edit, configure, and delete your Google Cloud data and see the email address for your Google Account.
17    CloudPlatform,
18}
19
20impl AsRef<str> for Scope {
21    fn as_ref(&self) -> &str {
22        match *self {
23            Scope::CloudPlatform => "https://www.googleapis.com/auth/cloud-platform",
24        }
25    }
26}
27
28#[allow(clippy::derivable_impls)]
29impl Default for Scope {
30    fn default() -> Scope {
31        Scope::CloudPlatform
32    }
33}
34
35// ########
36// HUB ###
37// ######
38
39/// Central instance to access all Libraryagent 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_libraryagent1 as libraryagent1;
49/// use libraryagent1::{Result, Error};
50/// # async fn dox() {
51/// use libraryagent1::{Libraryagent, 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 auth = yup_oauth2::InstalledFlowAuthenticator::builder(
62///     secret,
63///     yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
64/// ).build().await.unwrap();
65///
66/// let client = hyper_util::client::legacy::Client::builder(
67///     hyper_util::rt::TokioExecutor::new()
68/// )
69/// .build(
70///     hyper_rustls::HttpsConnectorBuilder::new()
71///         .with_native_roots()
72///         .unwrap()
73///         .https_or_http()
74///         .enable_http1()
75///         .build()
76/// );
77/// let mut hub = Libraryagent::new(client, auth);
78/// // You can configure optional parameters by calling the respective setters at will, and
79/// // execute the final call using `doit()`.
80/// // Values shown here are possibly random and not representative !
81/// let result = hub.shelves().books_borrow("name")
82///              .doit().await;
83///
84/// match result {
85///     Err(e) => match e {
86///         // The Error enum provides details about what exactly happened.
87///         // You can also just use its `Debug`, `Display` or `Error` traits
88///          Error::HttpError(_)
89///         |Error::Io(_)
90///         |Error::MissingAPIKey
91///         |Error::MissingToken(_)
92///         |Error::Cancelled
93///         |Error::UploadSizeLimitExceeded(_, _)
94///         |Error::Failure(_)
95///         |Error::BadRequest(_)
96///         |Error::FieldClash(_)
97///         |Error::JsonDecodeError(_, _) => println!("{}", e),
98///     },
99///     Ok(res) => println!("Success: {:?}", res),
100/// }
101/// # }
102/// ```
103#[derive(Clone)]
104pub struct Libraryagent<C> {
105    pub client: common::Client<C>,
106    pub auth: Box<dyn common::GetToken>,
107    _user_agent: String,
108    _base_url: String,
109    _root_url: String,
110}
111
112impl<C> common::Hub for Libraryagent<C> {}
113
114impl<'a, C> Libraryagent<C> {
115    pub fn new<A: 'static + common::GetToken>(
116        client: common::Client<C>,
117        auth: A,
118    ) -> Libraryagent<C> {
119        Libraryagent {
120            client,
121            auth: Box::new(auth),
122            _user_agent: "google-api-rust-client/6.0.0".to_string(),
123            _base_url: "https://libraryagent.googleapis.com/".to_string(),
124            _root_url: "https://libraryagent.googleapis.com/".to_string(),
125        }
126    }
127
128    pub fn shelves(&'a self) -> ShelfMethods<'a, C> {
129        ShelfMethods { hub: self }
130    }
131
132    /// Set the user-agent header field to use in all requests to the server.
133    /// It defaults to `google-api-rust-client/6.0.0`.
134    ///
135    /// Returns the previously set user-agent.
136    pub fn user_agent(&mut self, agent_name: String) -> String {
137        std::mem::replace(&mut self._user_agent, agent_name)
138    }
139
140    /// Set the base url to use in all requests to the server.
141    /// It defaults to `https://libraryagent.googleapis.com/`.
142    ///
143    /// Returns the previously set base url.
144    pub fn base_url(&mut self, new_base_url: String) -> String {
145        std::mem::replace(&mut self._base_url, new_base_url)
146    }
147
148    /// Set the root url to use in all requests to the server.
149    /// It defaults to `https://libraryagent.googleapis.com/`.
150    ///
151    /// Returns the previously set root url.
152    pub fn root_url(&mut self, new_root_url: String) -> String {
153        std::mem::replace(&mut self._root_url, new_root_url)
154    }
155}
156
157// ############
158// SCHEMAS ###
159// ##########
160/// A single book in the library.
161///
162/// # Activities
163///
164/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
165/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
166///
167/// * [books borrow shelves](ShelfBookBorrowCall) (response)
168/// * [books get shelves](ShelfBookGetCall) (response)
169/// * [books return shelves](ShelfBookReturnCall) (response)
170#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
171#[serde_with::serde_as]
172#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
173pub struct GoogleExampleLibraryagentV1Book {
174    /// The name of the book author.
175    pub author: Option<String>,
176    /// The resource name of the book. Book names have the form `shelves/{shelf_id}/books/{book_id}`. The name is ignored when creating a book.
177    pub name: Option<String>,
178    /// Value indicating whether the book has been read.
179    pub read: Option<bool>,
180    /// The title of the book.
181    pub title: Option<String>,
182}
183
184impl common::ResponseResult for GoogleExampleLibraryagentV1Book {}
185
186/// Response message for LibraryAgent.ListBooks.
187///
188/// # Activities
189///
190/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
191/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
192///
193/// * [books list shelves](ShelfBookListCall) (response)
194#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
195#[serde_with::serde_as]
196#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
197pub struct GoogleExampleLibraryagentV1ListBooksResponse {
198    /// The list of books.
199    pub books: Option<Vec<GoogleExampleLibraryagentV1Book>>,
200    /// A token to retrieve next page of results. Pass this value in the ListBooksRequest.page_token field in the subsequent call to `ListBooks` method to retrieve the next page of results.
201    #[serde(rename = "nextPageToken")]
202    pub next_page_token: Option<String>,
203}
204
205impl common::ResponseResult for GoogleExampleLibraryagentV1ListBooksResponse {}
206
207/// Response message for LibraryAgent.ListShelves.
208///
209/// # Activities
210///
211/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
212/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
213///
214/// * [list shelves](ShelfListCall) (response)
215#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
216#[serde_with::serde_as]
217#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
218pub struct GoogleExampleLibraryagentV1ListShelvesResponse {
219    /// A token to retrieve next page of results. Pass this value in the ListShelvesRequest.page_token field in the subsequent call to `ListShelves` method to retrieve the next page of results.
220    #[serde(rename = "nextPageToken")]
221    pub next_page_token: Option<String>,
222    /// The list of shelves.
223    pub shelves: Option<Vec<GoogleExampleLibraryagentV1Shelf>>,
224}
225
226impl common::ResponseResult for GoogleExampleLibraryagentV1ListShelvesResponse {}
227
228/// A Shelf contains a collection of books with a theme.
229///
230/// # Activities
231///
232/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
233/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
234///
235/// * [get shelves](ShelfGetCall) (response)
236#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
237#[serde_with::serde_as]
238#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
239pub struct GoogleExampleLibraryagentV1Shelf {
240    /// Output only. The resource name of the shelf. Shelf names have the form `shelves/{shelf_id}`. The name is ignored when creating a shelf.
241    pub name: Option<String>,
242    /// The theme of the shelf
243    pub theme: Option<String>,
244}
245
246impl common::ResponseResult for GoogleExampleLibraryagentV1Shelf {}
247
248// ###################
249// MethodBuilders ###
250// #################
251
252/// A builder providing access to all methods supported on *shelf* resources.
253/// It is not used directly, but through the [`Libraryagent`] hub.
254///
255/// # Example
256///
257/// Instantiate a resource builder
258///
259/// ```test_harness,no_run
260/// extern crate hyper;
261/// extern crate hyper_rustls;
262/// extern crate google_libraryagent1 as libraryagent1;
263///
264/// # async fn dox() {
265/// use libraryagent1::{Libraryagent, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
266///
267/// let secret: yup_oauth2::ApplicationSecret = Default::default();
268/// let auth = yup_oauth2::InstalledFlowAuthenticator::builder(
269///     secret,
270///     yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
271/// ).build().await.unwrap();
272///
273/// let client = hyper_util::client::legacy::Client::builder(
274///     hyper_util::rt::TokioExecutor::new()
275/// )
276/// .build(
277///     hyper_rustls::HttpsConnectorBuilder::new()
278///         .with_native_roots()
279///         .unwrap()
280///         .https_or_http()
281///         .enable_http1()
282///         .build()
283/// );
284/// let mut hub = Libraryagent::new(client, auth);
285/// // Usually you wouldn't bind this to a variable, but keep calling *CallBuilders*
286/// // like `books_borrow(...)`, `books_get(...)`, `books_list(...)`, `books_return(...)`, `get(...)` and `list(...)`
287/// // to build up your call.
288/// let rb = hub.shelves();
289/// # }
290/// ```
291pub struct ShelfMethods<'a, C>
292where
293    C: 'a,
294{
295    hub: &'a Libraryagent<C>,
296}
297
298impl<'a, C> common::MethodsBuilder for ShelfMethods<'a, C> {}
299
300impl<'a, C> ShelfMethods<'a, C> {
301    /// Create a builder to help you perform the following task:
302    ///
303    /// Borrow a book from the library. Returns the book if it is borrowed successfully. Returns NOT_FOUND if the book does not exist in the library. Returns quota exceeded error if the amount of books borrowed exceeds allocation quota in any dimensions.
304    ///
305    /// # Arguments
306    ///
307    /// * `name` - Required. The name of the book to borrow.
308    pub fn books_borrow(&self, name: &str) -> ShelfBookBorrowCall<'a, C> {
309        ShelfBookBorrowCall {
310            hub: self.hub,
311            _name: name.to_string(),
312            _delegate: Default::default(),
313            _additional_params: Default::default(),
314            _scopes: Default::default(),
315        }
316    }
317
318    /// Create a builder to help you perform the following task:
319    ///
320    /// Gets a book. Returns NOT_FOUND if the book does not exist.
321    ///
322    /// # Arguments
323    ///
324    /// * `name` - Required. The name of the book to retrieve.
325    pub fn books_get(&self, name: &str) -> ShelfBookGetCall<'a, C> {
326        ShelfBookGetCall {
327            hub: self.hub,
328            _name: name.to_string(),
329            _delegate: Default::default(),
330            _additional_params: Default::default(),
331            _scopes: Default::default(),
332        }
333    }
334
335    /// Create a builder to help you perform the following task:
336    ///
337    /// Lists books in a shelf. The order is unspecified but deterministic. Newly created books will not necessarily be added to the end of this list. Returns NOT_FOUND if the shelf does not exist.
338    ///
339    /// # Arguments
340    ///
341    /// * `parent` - Required. The name of the shelf whose books we'd like to list.
342    pub fn books_list(&self, parent: &str) -> ShelfBookListCall<'a, C> {
343        ShelfBookListCall {
344            hub: self.hub,
345            _parent: parent.to_string(),
346            _page_token: Default::default(),
347            _page_size: Default::default(),
348            _delegate: Default::default(),
349            _additional_params: Default::default(),
350            _scopes: Default::default(),
351        }
352    }
353
354    /// Create a builder to help you perform the following task:
355    ///
356    /// Return a book to the library. Returns the book if it is returned to the library successfully. Returns error if the book does not belong to the library or the users didn't borrow before.
357    ///
358    /// # Arguments
359    ///
360    /// * `name` - Required. The name of the book to return.
361    pub fn books_return(&self, name: &str) -> ShelfBookReturnCall<'a, C> {
362        ShelfBookReturnCall {
363            hub: self.hub,
364            _name: name.to_string(),
365            _delegate: Default::default(),
366            _additional_params: Default::default(),
367            _scopes: Default::default(),
368        }
369    }
370
371    /// Create a builder to help you perform the following task:
372    ///
373    /// Gets a shelf. Returns NOT_FOUND if the shelf does not exist.
374    ///
375    /// # Arguments
376    ///
377    /// * `name` - Required. The name of the shelf to retrieve.
378    pub fn get(&self, name: &str) -> ShelfGetCall<'a, C> {
379        ShelfGetCall {
380            hub: self.hub,
381            _name: name.to_string(),
382            _delegate: Default::default(),
383            _additional_params: Default::default(),
384            _scopes: Default::default(),
385        }
386    }
387
388    /// Create a builder to help you perform the following task:
389    ///
390    /// Lists shelves. The order is unspecified but deterministic. Newly created shelves will not necessarily be added to the end of this list.
391    pub fn list(&self) -> ShelfListCall<'a, C> {
392        ShelfListCall {
393            hub: self.hub,
394            _page_token: Default::default(),
395            _page_size: Default::default(),
396            _delegate: Default::default(),
397            _additional_params: Default::default(),
398            _scopes: Default::default(),
399        }
400    }
401}
402
403// ###################
404// CallBuilders   ###
405// #################
406
407/// Borrow a book from the library. Returns the book if it is borrowed successfully. Returns NOT_FOUND if the book does not exist in the library. Returns quota exceeded error if the amount of books borrowed exceeds allocation quota in any dimensions.
408///
409/// A builder for the *books.borrow* method supported by a *shelf* resource.
410/// It is not used directly, but through a [`ShelfMethods`] instance.
411///
412/// # Example
413///
414/// Instantiate a resource method builder
415///
416/// ```test_harness,no_run
417/// # extern crate hyper;
418/// # extern crate hyper_rustls;
419/// # extern crate google_libraryagent1 as libraryagent1;
420/// # async fn dox() {
421/// # use libraryagent1::{Libraryagent, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
422///
423/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
424/// # let auth = yup_oauth2::InstalledFlowAuthenticator::builder(
425/// #     secret,
426/// #     yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
427/// # ).build().await.unwrap();
428///
429/// # let client = hyper_util::client::legacy::Client::builder(
430/// #     hyper_util::rt::TokioExecutor::new()
431/// # )
432/// # .build(
433/// #     hyper_rustls::HttpsConnectorBuilder::new()
434/// #         .with_native_roots()
435/// #         .unwrap()
436/// #         .https_or_http()
437/// #         .enable_http1()
438/// #         .build()
439/// # );
440/// # let mut hub = Libraryagent::new(client, auth);
441/// // You can configure optional parameters by calling the respective setters at will, and
442/// // execute the final call using `doit()`.
443/// // Values shown here are possibly random and not representative !
444/// let result = hub.shelves().books_borrow("name")
445///              .doit().await;
446/// # }
447/// ```
448pub struct ShelfBookBorrowCall<'a, C>
449where
450    C: 'a,
451{
452    hub: &'a Libraryagent<C>,
453    _name: String,
454    _delegate: Option<&'a mut dyn common::Delegate>,
455    _additional_params: HashMap<String, String>,
456    _scopes: BTreeSet<String>,
457}
458
459impl<'a, C> common::CallBuilder for ShelfBookBorrowCall<'a, C> {}
460
461impl<'a, C> ShelfBookBorrowCall<'a, C>
462where
463    C: common::Connector,
464{
465    /// Perform the operation you have build so far.
466    pub async fn doit(
467        mut self,
468    ) -> common::Result<(common::Response, GoogleExampleLibraryagentV1Book)> {
469        use std::borrow::Cow;
470        use std::io::{Read, Seek};
471
472        use common::{url::Params, ToParts};
473        use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
474
475        let mut dd = common::DefaultDelegate;
476        let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
477        dlg.begin(common::MethodInfo {
478            id: "libraryagent.shelves.books.borrow",
479            http_method: hyper::Method::POST,
480        });
481
482        for &field in ["alt", "name"].iter() {
483            if self._additional_params.contains_key(field) {
484                dlg.finished(false);
485                return Err(common::Error::FieldClash(field));
486            }
487        }
488
489        let mut params = Params::with_capacity(3 + self._additional_params.len());
490        params.push("name", self._name);
491
492        params.extend(self._additional_params.iter());
493
494        params.push("alt", "json");
495        let mut url = self.hub._base_url.clone() + "v1/{+name}:borrow";
496        if self._scopes.is_empty() {
497            self._scopes
498                .insert(Scope::CloudPlatform.as_ref().to_string());
499        }
500
501        #[allow(clippy::single_element_loop)]
502        for &(find_this, param_name) in [("{+name}", "name")].iter() {
503            url = params.uri_replacement(url, param_name, find_this, true);
504        }
505        {
506            let to_remove = ["name"];
507            params.remove_params(&to_remove);
508        }
509
510        let url = params.parse_with_url(&url);
511
512        loop {
513            let token = match self
514                .hub
515                .auth
516                .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
517                .await
518            {
519                Ok(token) => token,
520                Err(e) => match dlg.token(e) {
521                    Ok(token) => token,
522                    Err(e) => {
523                        dlg.finished(false);
524                        return Err(common::Error::MissingToken(e));
525                    }
526                },
527            };
528            let mut req_result = {
529                let client = &self.hub.client;
530                dlg.pre_request();
531                let mut req_builder = hyper::Request::builder()
532                    .method(hyper::Method::POST)
533                    .uri(url.as_str())
534                    .header(USER_AGENT, self.hub._user_agent.clone());
535
536                if let Some(token) = token.as_ref() {
537                    req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
538                }
539
540                let request = req_builder
541                    .header(CONTENT_LENGTH, 0_u64)
542                    .body(common::to_body::<String>(None));
543
544                client.request(request.unwrap()).await
545            };
546
547            match req_result {
548                Err(err) => {
549                    if let common::Retry::After(d) = dlg.http_error(&err) {
550                        sleep(d).await;
551                        continue;
552                    }
553                    dlg.finished(false);
554                    return Err(common::Error::HttpError(err));
555                }
556                Ok(res) => {
557                    let (mut parts, body) = res.into_parts();
558                    let mut body = common::Body::new(body);
559                    if !parts.status.is_success() {
560                        let bytes = common::to_bytes(body).await.unwrap_or_default();
561                        let error = serde_json::from_str(&common::to_string(&bytes));
562                        let response = common::to_response(parts, bytes.into());
563
564                        if let common::Retry::After(d) =
565                            dlg.http_failure(&response, error.as_ref().ok())
566                        {
567                            sleep(d).await;
568                            continue;
569                        }
570
571                        dlg.finished(false);
572
573                        return Err(match error {
574                            Ok(value) => common::Error::BadRequest(value),
575                            _ => common::Error::Failure(response),
576                        });
577                    }
578                    let response = {
579                        let bytes = common::to_bytes(body).await.unwrap_or_default();
580                        let encoded = common::to_string(&bytes);
581                        match serde_json::from_str(&encoded) {
582                            Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
583                            Err(error) => {
584                                dlg.response_json_decode_error(&encoded, &error);
585                                return Err(common::Error::JsonDecodeError(
586                                    encoded.to_string(),
587                                    error,
588                                ));
589                            }
590                        }
591                    };
592
593                    dlg.finished(true);
594                    return Ok(response);
595                }
596            }
597        }
598    }
599
600    /// Required. The name of the book to borrow.
601    ///
602    /// Sets the *name* path property to the given value.
603    ///
604    /// Even though the property as already been set when instantiating this call,
605    /// we provide this method for API completeness.
606    pub fn name(mut self, new_value: &str) -> ShelfBookBorrowCall<'a, C> {
607        self._name = new_value.to_string();
608        self
609    }
610    /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
611    /// while executing the actual API request.
612    ///
613    /// ````text
614    ///                   It should be used to handle progress information, and to implement a certain level of resilience.
615    /// ````
616    ///
617    /// Sets the *delegate* property to the given value.
618    pub fn delegate(
619        mut self,
620        new_value: &'a mut dyn common::Delegate,
621    ) -> ShelfBookBorrowCall<'a, C> {
622        self._delegate = Some(new_value);
623        self
624    }
625
626    /// Set any additional parameter of the query string used in the request.
627    /// It should be used to set parameters which are not yet available through their own
628    /// setters.
629    ///
630    /// Please note that this method must not be used to set any of the known parameters
631    /// which have their own setter method. If done anyway, the request will fail.
632    ///
633    /// # Additional Parameters
634    ///
635    /// * *$.xgafv* (query-string) - V1 error format.
636    /// * *access_token* (query-string) - OAuth access token.
637    /// * *alt* (query-string) - Data format for response.
638    /// * *callback* (query-string) - JSONP
639    /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
640    /// * *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.
641    /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
642    /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
643    /// * *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.
644    /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
645    /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
646    pub fn param<T>(mut self, name: T, value: T) -> ShelfBookBorrowCall<'a, C>
647    where
648        T: AsRef<str>,
649    {
650        self._additional_params
651            .insert(name.as_ref().to_string(), value.as_ref().to_string());
652        self
653    }
654
655    /// Identifies the authorization scope for the method you are building.
656    ///
657    /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
658    /// [`Scope::CloudPlatform`].
659    ///
660    /// The `scope` will be added to a set of scopes. This is important as one can maintain access
661    /// tokens for more than one scope.
662    ///
663    /// Usually there is more than one suitable scope to authorize an operation, some of which may
664    /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
665    /// sufficient, a read-write scope will do as well.
666    pub fn add_scope<St>(mut self, scope: St) -> ShelfBookBorrowCall<'a, C>
667    where
668        St: AsRef<str>,
669    {
670        self._scopes.insert(String::from(scope.as_ref()));
671        self
672    }
673    /// Identifies the authorization scope(s) for the method you are building.
674    ///
675    /// See [`Self::add_scope()`] for details.
676    pub fn add_scopes<I, St>(mut self, scopes: I) -> ShelfBookBorrowCall<'a, C>
677    where
678        I: IntoIterator<Item = St>,
679        St: AsRef<str>,
680    {
681        self._scopes
682            .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
683        self
684    }
685
686    /// Removes all scopes, and no default scope will be used either.
687    /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
688    /// for details).
689    pub fn clear_scopes(mut self) -> ShelfBookBorrowCall<'a, C> {
690        self._scopes.clear();
691        self
692    }
693}
694
695/// Gets a book. Returns NOT_FOUND if the book does not exist.
696///
697/// A builder for the *books.get* method supported by a *shelf* resource.
698/// It is not used directly, but through a [`ShelfMethods`] instance.
699///
700/// # Example
701///
702/// Instantiate a resource method builder
703///
704/// ```test_harness,no_run
705/// # extern crate hyper;
706/// # extern crate hyper_rustls;
707/// # extern crate google_libraryagent1 as libraryagent1;
708/// # async fn dox() {
709/// # use libraryagent1::{Libraryagent, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
710///
711/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
712/// # let auth = yup_oauth2::InstalledFlowAuthenticator::builder(
713/// #     secret,
714/// #     yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
715/// # ).build().await.unwrap();
716///
717/// # let client = hyper_util::client::legacy::Client::builder(
718/// #     hyper_util::rt::TokioExecutor::new()
719/// # )
720/// # .build(
721/// #     hyper_rustls::HttpsConnectorBuilder::new()
722/// #         .with_native_roots()
723/// #         .unwrap()
724/// #         .https_or_http()
725/// #         .enable_http1()
726/// #         .build()
727/// # );
728/// # let mut hub = Libraryagent::new(client, auth);
729/// // You can configure optional parameters by calling the respective setters at will, and
730/// // execute the final call using `doit()`.
731/// // Values shown here are possibly random and not representative !
732/// let result = hub.shelves().books_get("name")
733///              .doit().await;
734/// # }
735/// ```
736pub struct ShelfBookGetCall<'a, C>
737where
738    C: 'a,
739{
740    hub: &'a Libraryagent<C>,
741    _name: String,
742    _delegate: Option<&'a mut dyn common::Delegate>,
743    _additional_params: HashMap<String, String>,
744    _scopes: BTreeSet<String>,
745}
746
747impl<'a, C> common::CallBuilder for ShelfBookGetCall<'a, C> {}
748
749impl<'a, C> ShelfBookGetCall<'a, C>
750where
751    C: common::Connector,
752{
753    /// Perform the operation you have build so far.
754    pub async fn doit(
755        mut self,
756    ) -> common::Result<(common::Response, GoogleExampleLibraryagentV1Book)> {
757        use std::borrow::Cow;
758        use std::io::{Read, Seek};
759
760        use common::{url::Params, ToParts};
761        use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
762
763        let mut dd = common::DefaultDelegate;
764        let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
765        dlg.begin(common::MethodInfo {
766            id: "libraryagent.shelves.books.get",
767            http_method: hyper::Method::GET,
768        });
769
770        for &field in ["alt", "name"].iter() {
771            if self._additional_params.contains_key(field) {
772                dlg.finished(false);
773                return Err(common::Error::FieldClash(field));
774            }
775        }
776
777        let mut params = Params::with_capacity(3 + self._additional_params.len());
778        params.push("name", self._name);
779
780        params.extend(self._additional_params.iter());
781
782        params.push("alt", "json");
783        let mut url = self.hub._base_url.clone() + "v1/{+name}";
784        if self._scopes.is_empty() {
785            self._scopes
786                .insert(Scope::CloudPlatform.as_ref().to_string());
787        }
788
789        #[allow(clippy::single_element_loop)]
790        for &(find_this, param_name) in [("{+name}", "name")].iter() {
791            url = params.uri_replacement(url, param_name, find_this, true);
792        }
793        {
794            let to_remove = ["name"];
795            params.remove_params(&to_remove);
796        }
797
798        let url = params.parse_with_url(&url);
799
800        loop {
801            let token = match self
802                .hub
803                .auth
804                .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
805                .await
806            {
807                Ok(token) => token,
808                Err(e) => match dlg.token(e) {
809                    Ok(token) => token,
810                    Err(e) => {
811                        dlg.finished(false);
812                        return Err(common::Error::MissingToken(e));
813                    }
814                },
815            };
816            let mut req_result = {
817                let client = &self.hub.client;
818                dlg.pre_request();
819                let mut req_builder = hyper::Request::builder()
820                    .method(hyper::Method::GET)
821                    .uri(url.as_str())
822                    .header(USER_AGENT, self.hub._user_agent.clone());
823
824                if let Some(token) = token.as_ref() {
825                    req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
826                }
827
828                let request = req_builder
829                    .header(CONTENT_LENGTH, 0_u64)
830                    .body(common::to_body::<String>(None));
831
832                client.request(request.unwrap()).await
833            };
834
835            match req_result {
836                Err(err) => {
837                    if let common::Retry::After(d) = dlg.http_error(&err) {
838                        sleep(d).await;
839                        continue;
840                    }
841                    dlg.finished(false);
842                    return Err(common::Error::HttpError(err));
843                }
844                Ok(res) => {
845                    let (mut parts, body) = res.into_parts();
846                    let mut body = common::Body::new(body);
847                    if !parts.status.is_success() {
848                        let bytes = common::to_bytes(body).await.unwrap_or_default();
849                        let error = serde_json::from_str(&common::to_string(&bytes));
850                        let response = common::to_response(parts, bytes.into());
851
852                        if let common::Retry::After(d) =
853                            dlg.http_failure(&response, error.as_ref().ok())
854                        {
855                            sleep(d).await;
856                            continue;
857                        }
858
859                        dlg.finished(false);
860
861                        return Err(match error {
862                            Ok(value) => common::Error::BadRequest(value),
863                            _ => common::Error::Failure(response),
864                        });
865                    }
866                    let response = {
867                        let bytes = common::to_bytes(body).await.unwrap_or_default();
868                        let encoded = common::to_string(&bytes);
869                        match serde_json::from_str(&encoded) {
870                            Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
871                            Err(error) => {
872                                dlg.response_json_decode_error(&encoded, &error);
873                                return Err(common::Error::JsonDecodeError(
874                                    encoded.to_string(),
875                                    error,
876                                ));
877                            }
878                        }
879                    };
880
881                    dlg.finished(true);
882                    return Ok(response);
883                }
884            }
885        }
886    }
887
888    /// Required. The name of the book to retrieve.
889    ///
890    /// Sets the *name* path property to the given value.
891    ///
892    /// Even though the property as already been set when instantiating this call,
893    /// we provide this method for API completeness.
894    pub fn name(mut self, new_value: &str) -> ShelfBookGetCall<'a, C> {
895        self._name = new_value.to_string();
896        self
897    }
898    /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
899    /// while executing the actual API request.
900    ///
901    /// ````text
902    ///                   It should be used to handle progress information, and to implement a certain level of resilience.
903    /// ````
904    ///
905    /// Sets the *delegate* property to the given value.
906    pub fn delegate(mut self, new_value: &'a mut dyn common::Delegate) -> ShelfBookGetCall<'a, C> {
907        self._delegate = Some(new_value);
908        self
909    }
910
911    /// Set any additional parameter of the query string used in the request.
912    /// It should be used to set parameters which are not yet available through their own
913    /// setters.
914    ///
915    /// Please note that this method must not be used to set any of the known parameters
916    /// which have their own setter method. If done anyway, the request will fail.
917    ///
918    /// # Additional Parameters
919    ///
920    /// * *$.xgafv* (query-string) - V1 error format.
921    /// * *access_token* (query-string) - OAuth access token.
922    /// * *alt* (query-string) - Data format for response.
923    /// * *callback* (query-string) - JSONP
924    /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
925    /// * *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.
926    /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
927    /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
928    /// * *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.
929    /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
930    /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
931    pub fn param<T>(mut self, name: T, value: T) -> ShelfBookGetCall<'a, C>
932    where
933        T: AsRef<str>,
934    {
935        self._additional_params
936            .insert(name.as_ref().to_string(), value.as_ref().to_string());
937        self
938    }
939
940    /// Identifies the authorization scope for the method you are building.
941    ///
942    /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
943    /// [`Scope::CloudPlatform`].
944    ///
945    /// The `scope` will be added to a set of scopes. This is important as one can maintain access
946    /// tokens for more than one scope.
947    ///
948    /// Usually there is more than one suitable scope to authorize an operation, some of which may
949    /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
950    /// sufficient, a read-write scope will do as well.
951    pub fn add_scope<St>(mut self, scope: St) -> ShelfBookGetCall<'a, C>
952    where
953        St: AsRef<str>,
954    {
955        self._scopes.insert(String::from(scope.as_ref()));
956        self
957    }
958    /// Identifies the authorization scope(s) for the method you are building.
959    ///
960    /// See [`Self::add_scope()`] for details.
961    pub fn add_scopes<I, St>(mut self, scopes: I) -> ShelfBookGetCall<'a, C>
962    where
963        I: IntoIterator<Item = St>,
964        St: AsRef<str>,
965    {
966        self._scopes
967            .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
968        self
969    }
970
971    /// Removes all scopes, and no default scope will be used either.
972    /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
973    /// for details).
974    pub fn clear_scopes(mut self) -> ShelfBookGetCall<'a, C> {
975        self._scopes.clear();
976        self
977    }
978}
979
980/// Lists books in a shelf. The order is unspecified but deterministic. Newly created books will not necessarily be added to the end of this list. Returns NOT_FOUND if the shelf does not exist.
981///
982/// A builder for the *books.list* method supported by a *shelf* resource.
983/// It is not used directly, but through a [`ShelfMethods`] instance.
984///
985/// # Example
986///
987/// Instantiate a resource method builder
988///
989/// ```test_harness,no_run
990/// # extern crate hyper;
991/// # extern crate hyper_rustls;
992/// # extern crate google_libraryagent1 as libraryagent1;
993/// # async fn dox() {
994/// # use libraryagent1::{Libraryagent, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
995///
996/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
997/// # let auth = yup_oauth2::InstalledFlowAuthenticator::builder(
998/// #     secret,
999/// #     yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
1000/// # ).build().await.unwrap();
1001///
1002/// # let client = hyper_util::client::legacy::Client::builder(
1003/// #     hyper_util::rt::TokioExecutor::new()
1004/// # )
1005/// # .build(
1006/// #     hyper_rustls::HttpsConnectorBuilder::new()
1007/// #         .with_native_roots()
1008/// #         .unwrap()
1009/// #         .https_or_http()
1010/// #         .enable_http1()
1011/// #         .build()
1012/// # );
1013/// # let mut hub = Libraryagent::new(client, auth);
1014/// // You can configure optional parameters by calling the respective setters at will, and
1015/// // execute the final call using `doit()`.
1016/// // Values shown here are possibly random and not representative !
1017/// let result = hub.shelves().books_list("parent")
1018///              .page_token("sanctus")
1019///              .page_size(-80)
1020///              .doit().await;
1021/// # }
1022/// ```
1023pub struct ShelfBookListCall<'a, C>
1024where
1025    C: 'a,
1026{
1027    hub: &'a Libraryagent<C>,
1028    _parent: String,
1029    _page_token: Option<String>,
1030    _page_size: Option<i32>,
1031    _delegate: Option<&'a mut dyn common::Delegate>,
1032    _additional_params: HashMap<String, String>,
1033    _scopes: BTreeSet<String>,
1034}
1035
1036impl<'a, C> common::CallBuilder for ShelfBookListCall<'a, C> {}
1037
1038impl<'a, C> ShelfBookListCall<'a, C>
1039where
1040    C: common::Connector,
1041{
1042    /// Perform the operation you have build so far.
1043    pub async fn doit(
1044        mut self,
1045    ) -> common::Result<(
1046        common::Response,
1047        GoogleExampleLibraryagentV1ListBooksResponse,
1048    )> {
1049        use std::borrow::Cow;
1050        use std::io::{Read, Seek};
1051
1052        use common::{url::Params, ToParts};
1053        use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
1054
1055        let mut dd = common::DefaultDelegate;
1056        let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
1057        dlg.begin(common::MethodInfo {
1058            id: "libraryagent.shelves.books.list",
1059            http_method: hyper::Method::GET,
1060        });
1061
1062        for &field in ["alt", "parent", "pageToken", "pageSize"].iter() {
1063            if self._additional_params.contains_key(field) {
1064                dlg.finished(false);
1065                return Err(common::Error::FieldClash(field));
1066            }
1067        }
1068
1069        let mut params = Params::with_capacity(5 + self._additional_params.len());
1070        params.push("parent", self._parent);
1071        if let Some(value) = self._page_token.as_ref() {
1072            params.push("pageToken", value);
1073        }
1074        if let Some(value) = self._page_size.as_ref() {
1075            params.push("pageSize", value.to_string());
1076        }
1077
1078        params.extend(self._additional_params.iter());
1079
1080        params.push("alt", "json");
1081        let mut url = self.hub._base_url.clone() + "v1/{+parent}/books";
1082        if self._scopes.is_empty() {
1083            self._scopes
1084                .insert(Scope::CloudPlatform.as_ref().to_string());
1085        }
1086
1087        #[allow(clippy::single_element_loop)]
1088        for &(find_this, param_name) in [("{+parent}", "parent")].iter() {
1089            url = params.uri_replacement(url, param_name, find_this, true);
1090        }
1091        {
1092            let to_remove = ["parent"];
1093            params.remove_params(&to_remove);
1094        }
1095
1096        let url = params.parse_with_url(&url);
1097
1098        loop {
1099            let token = match self
1100                .hub
1101                .auth
1102                .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
1103                .await
1104            {
1105                Ok(token) => token,
1106                Err(e) => match dlg.token(e) {
1107                    Ok(token) => token,
1108                    Err(e) => {
1109                        dlg.finished(false);
1110                        return Err(common::Error::MissingToken(e));
1111                    }
1112                },
1113            };
1114            let mut req_result = {
1115                let client = &self.hub.client;
1116                dlg.pre_request();
1117                let mut req_builder = hyper::Request::builder()
1118                    .method(hyper::Method::GET)
1119                    .uri(url.as_str())
1120                    .header(USER_AGENT, self.hub._user_agent.clone());
1121
1122                if let Some(token) = token.as_ref() {
1123                    req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
1124                }
1125
1126                let request = req_builder
1127                    .header(CONTENT_LENGTH, 0_u64)
1128                    .body(common::to_body::<String>(None));
1129
1130                client.request(request.unwrap()).await
1131            };
1132
1133            match req_result {
1134                Err(err) => {
1135                    if let common::Retry::After(d) = dlg.http_error(&err) {
1136                        sleep(d).await;
1137                        continue;
1138                    }
1139                    dlg.finished(false);
1140                    return Err(common::Error::HttpError(err));
1141                }
1142                Ok(res) => {
1143                    let (mut parts, body) = res.into_parts();
1144                    let mut body = common::Body::new(body);
1145                    if !parts.status.is_success() {
1146                        let bytes = common::to_bytes(body).await.unwrap_or_default();
1147                        let error = serde_json::from_str(&common::to_string(&bytes));
1148                        let response = common::to_response(parts, bytes.into());
1149
1150                        if let common::Retry::After(d) =
1151                            dlg.http_failure(&response, error.as_ref().ok())
1152                        {
1153                            sleep(d).await;
1154                            continue;
1155                        }
1156
1157                        dlg.finished(false);
1158
1159                        return Err(match error {
1160                            Ok(value) => common::Error::BadRequest(value),
1161                            _ => common::Error::Failure(response),
1162                        });
1163                    }
1164                    let response = {
1165                        let bytes = common::to_bytes(body).await.unwrap_or_default();
1166                        let encoded = common::to_string(&bytes);
1167                        match serde_json::from_str(&encoded) {
1168                            Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
1169                            Err(error) => {
1170                                dlg.response_json_decode_error(&encoded, &error);
1171                                return Err(common::Error::JsonDecodeError(
1172                                    encoded.to_string(),
1173                                    error,
1174                                ));
1175                            }
1176                        }
1177                    };
1178
1179                    dlg.finished(true);
1180                    return Ok(response);
1181                }
1182            }
1183        }
1184    }
1185
1186    /// Required. The name of the shelf whose books we'd like to list.
1187    ///
1188    /// Sets the *parent* path property to the given value.
1189    ///
1190    /// Even though the property as already been set when instantiating this call,
1191    /// we provide this method for API completeness.
1192    pub fn parent(mut self, new_value: &str) -> ShelfBookListCall<'a, C> {
1193        self._parent = new_value.to_string();
1194        self
1195    }
1196    /// A token identifying a page of results the server should return. Typically, this is the value of ListBooksResponse.next_page_token. returned from the previous call to `ListBooks` method.
1197    ///
1198    /// Sets the *page token* query property to the given value.
1199    pub fn page_token(mut self, new_value: &str) -> ShelfBookListCall<'a, C> {
1200        self._page_token = Some(new_value.to_string());
1201        self
1202    }
1203    /// Requested page size. Server may return fewer books than requested. If unspecified, server will pick an appropriate default.
1204    ///
1205    /// Sets the *page size* query property to the given value.
1206    pub fn page_size(mut self, new_value: i32) -> ShelfBookListCall<'a, C> {
1207        self._page_size = Some(new_value);
1208        self
1209    }
1210    /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
1211    /// while executing the actual API request.
1212    ///
1213    /// ````text
1214    ///                   It should be used to handle progress information, and to implement a certain level of resilience.
1215    /// ````
1216    ///
1217    /// Sets the *delegate* property to the given value.
1218    pub fn delegate(mut self, new_value: &'a mut dyn common::Delegate) -> ShelfBookListCall<'a, C> {
1219        self._delegate = Some(new_value);
1220        self
1221    }
1222
1223    /// Set any additional parameter of the query string used in the request.
1224    /// It should be used to set parameters which are not yet available through their own
1225    /// setters.
1226    ///
1227    /// Please note that this method must not be used to set any of the known parameters
1228    /// which have their own setter method. If done anyway, the request will fail.
1229    ///
1230    /// # Additional Parameters
1231    ///
1232    /// * *$.xgafv* (query-string) - V1 error format.
1233    /// * *access_token* (query-string) - OAuth access token.
1234    /// * *alt* (query-string) - Data format for response.
1235    /// * *callback* (query-string) - JSONP
1236    /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
1237    /// * *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.
1238    /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
1239    /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
1240    /// * *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.
1241    /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
1242    /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
1243    pub fn param<T>(mut self, name: T, value: T) -> ShelfBookListCall<'a, C>
1244    where
1245        T: AsRef<str>,
1246    {
1247        self._additional_params
1248            .insert(name.as_ref().to_string(), value.as_ref().to_string());
1249        self
1250    }
1251
1252    /// Identifies the authorization scope for the method you are building.
1253    ///
1254    /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
1255    /// [`Scope::CloudPlatform`].
1256    ///
1257    /// The `scope` will be added to a set of scopes. This is important as one can maintain access
1258    /// tokens for more than one scope.
1259    ///
1260    /// Usually there is more than one suitable scope to authorize an operation, some of which may
1261    /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
1262    /// sufficient, a read-write scope will do as well.
1263    pub fn add_scope<St>(mut self, scope: St) -> ShelfBookListCall<'a, C>
1264    where
1265        St: AsRef<str>,
1266    {
1267        self._scopes.insert(String::from(scope.as_ref()));
1268        self
1269    }
1270    /// Identifies the authorization scope(s) for the method you are building.
1271    ///
1272    /// See [`Self::add_scope()`] for details.
1273    pub fn add_scopes<I, St>(mut self, scopes: I) -> ShelfBookListCall<'a, C>
1274    where
1275        I: IntoIterator<Item = St>,
1276        St: AsRef<str>,
1277    {
1278        self._scopes
1279            .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
1280        self
1281    }
1282
1283    /// Removes all scopes, and no default scope will be used either.
1284    /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
1285    /// for details).
1286    pub fn clear_scopes(mut self) -> ShelfBookListCall<'a, C> {
1287        self._scopes.clear();
1288        self
1289    }
1290}
1291
1292/// Return a book to the library. Returns the book if it is returned to the library successfully. Returns error if the book does not belong to the library or the users didn't borrow before.
1293///
1294/// A builder for the *books.return* method supported by a *shelf* resource.
1295/// It is not used directly, but through a [`ShelfMethods`] instance.
1296///
1297/// # Example
1298///
1299/// Instantiate a resource method builder
1300///
1301/// ```test_harness,no_run
1302/// # extern crate hyper;
1303/// # extern crate hyper_rustls;
1304/// # extern crate google_libraryagent1 as libraryagent1;
1305/// # async fn dox() {
1306/// # use libraryagent1::{Libraryagent, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
1307///
1308/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
1309/// # let auth = yup_oauth2::InstalledFlowAuthenticator::builder(
1310/// #     secret,
1311/// #     yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
1312/// # ).build().await.unwrap();
1313///
1314/// # let client = hyper_util::client::legacy::Client::builder(
1315/// #     hyper_util::rt::TokioExecutor::new()
1316/// # )
1317/// # .build(
1318/// #     hyper_rustls::HttpsConnectorBuilder::new()
1319/// #         .with_native_roots()
1320/// #         .unwrap()
1321/// #         .https_or_http()
1322/// #         .enable_http1()
1323/// #         .build()
1324/// # );
1325/// # let mut hub = Libraryagent::new(client, auth);
1326/// // You can configure optional parameters by calling the respective setters at will, and
1327/// // execute the final call using `doit()`.
1328/// // Values shown here are possibly random and not representative !
1329/// let result = hub.shelves().books_return("name")
1330///              .doit().await;
1331/// # }
1332/// ```
1333pub struct ShelfBookReturnCall<'a, C>
1334where
1335    C: 'a,
1336{
1337    hub: &'a Libraryagent<C>,
1338    _name: String,
1339    _delegate: Option<&'a mut dyn common::Delegate>,
1340    _additional_params: HashMap<String, String>,
1341    _scopes: BTreeSet<String>,
1342}
1343
1344impl<'a, C> common::CallBuilder for ShelfBookReturnCall<'a, C> {}
1345
1346impl<'a, C> ShelfBookReturnCall<'a, C>
1347where
1348    C: common::Connector,
1349{
1350    /// Perform the operation you have build so far.
1351    pub async fn doit(
1352        mut self,
1353    ) -> common::Result<(common::Response, GoogleExampleLibraryagentV1Book)> {
1354        use std::borrow::Cow;
1355        use std::io::{Read, Seek};
1356
1357        use common::{url::Params, ToParts};
1358        use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
1359
1360        let mut dd = common::DefaultDelegate;
1361        let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
1362        dlg.begin(common::MethodInfo {
1363            id: "libraryagent.shelves.books.return",
1364            http_method: hyper::Method::POST,
1365        });
1366
1367        for &field in ["alt", "name"].iter() {
1368            if self._additional_params.contains_key(field) {
1369                dlg.finished(false);
1370                return Err(common::Error::FieldClash(field));
1371            }
1372        }
1373
1374        let mut params = Params::with_capacity(3 + self._additional_params.len());
1375        params.push("name", self._name);
1376
1377        params.extend(self._additional_params.iter());
1378
1379        params.push("alt", "json");
1380        let mut url = self.hub._base_url.clone() + "v1/{+name}:return";
1381        if self._scopes.is_empty() {
1382            self._scopes
1383                .insert(Scope::CloudPlatform.as_ref().to_string());
1384        }
1385
1386        #[allow(clippy::single_element_loop)]
1387        for &(find_this, param_name) in [("{+name}", "name")].iter() {
1388            url = params.uri_replacement(url, param_name, find_this, true);
1389        }
1390        {
1391            let to_remove = ["name"];
1392            params.remove_params(&to_remove);
1393        }
1394
1395        let url = params.parse_with_url(&url);
1396
1397        loop {
1398            let token = match self
1399                .hub
1400                .auth
1401                .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
1402                .await
1403            {
1404                Ok(token) => token,
1405                Err(e) => match dlg.token(e) {
1406                    Ok(token) => token,
1407                    Err(e) => {
1408                        dlg.finished(false);
1409                        return Err(common::Error::MissingToken(e));
1410                    }
1411                },
1412            };
1413            let mut req_result = {
1414                let client = &self.hub.client;
1415                dlg.pre_request();
1416                let mut req_builder = hyper::Request::builder()
1417                    .method(hyper::Method::POST)
1418                    .uri(url.as_str())
1419                    .header(USER_AGENT, self.hub._user_agent.clone());
1420
1421                if let Some(token) = token.as_ref() {
1422                    req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
1423                }
1424
1425                let request = req_builder
1426                    .header(CONTENT_LENGTH, 0_u64)
1427                    .body(common::to_body::<String>(None));
1428
1429                client.request(request.unwrap()).await
1430            };
1431
1432            match req_result {
1433                Err(err) => {
1434                    if let common::Retry::After(d) = dlg.http_error(&err) {
1435                        sleep(d).await;
1436                        continue;
1437                    }
1438                    dlg.finished(false);
1439                    return Err(common::Error::HttpError(err));
1440                }
1441                Ok(res) => {
1442                    let (mut parts, body) = res.into_parts();
1443                    let mut body = common::Body::new(body);
1444                    if !parts.status.is_success() {
1445                        let bytes = common::to_bytes(body).await.unwrap_or_default();
1446                        let error = serde_json::from_str(&common::to_string(&bytes));
1447                        let response = common::to_response(parts, bytes.into());
1448
1449                        if let common::Retry::After(d) =
1450                            dlg.http_failure(&response, error.as_ref().ok())
1451                        {
1452                            sleep(d).await;
1453                            continue;
1454                        }
1455
1456                        dlg.finished(false);
1457
1458                        return Err(match error {
1459                            Ok(value) => common::Error::BadRequest(value),
1460                            _ => common::Error::Failure(response),
1461                        });
1462                    }
1463                    let response = {
1464                        let bytes = common::to_bytes(body).await.unwrap_or_default();
1465                        let encoded = common::to_string(&bytes);
1466                        match serde_json::from_str(&encoded) {
1467                            Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
1468                            Err(error) => {
1469                                dlg.response_json_decode_error(&encoded, &error);
1470                                return Err(common::Error::JsonDecodeError(
1471                                    encoded.to_string(),
1472                                    error,
1473                                ));
1474                            }
1475                        }
1476                    };
1477
1478                    dlg.finished(true);
1479                    return Ok(response);
1480                }
1481            }
1482        }
1483    }
1484
1485    /// Required. The name of the book to return.
1486    ///
1487    /// Sets the *name* path property to the given value.
1488    ///
1489    /// Even though the property as already been set when instantiating this call,
1490    /// we provide this method for API completeness.
1491    pub fn name(mut self, new_value: &str) -> ShelfBookReturnCall<'a, C> {
1492        self._name = new_value.to_string();
1493        self
1494    }
1495    /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
1496    /// while executing the actual API request.
1497    ///
1498    /// ````text
1499    ///                   It should be used to handle progress information, and to implement a certain level of resilience.
1500    /// ````
1501    ///
1502    /// Sets the *delegate* property to the given value.
1503    pub fn delegate(
1504        mut self,
1505        new_value: &'a mut dyn common::Delegate,
1506    ) -> ShelfBookReturnCall<'a, C> {
1507        self._delegate = Some(new_value);
1508        self
1509    }
1510
1511    /// Set any additional parameter of the query string used in the request.
1512    /// It should be used to set parameters which are not yet available through their own
1513    /// setters.
1514    ///
1515    /// Please note that this method must not be used to set any of the known parameters
1516    /// which have their own setter method. If done anyway, the request will fail.
1517    ///
1518    /// # Additional Parameters
1519    ///
1520    /// * *$.xgafv* (query-string) - V1 error format.
1521    /// * *access_token* (query-string) - OAuth access token.
1522    /// * *alt* (query-string) - Data format for response.
1523    /// * *callback* (query-string) - JSONP
1524    /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
1525    /// * *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.
1526    /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
1527    /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
1528    /// * *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.
1529    /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
1530    /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
1531    pub fn param<T>(mut self, name: T, value: T) -> ShelfBookReturnCall<'a, C>
1532    where
1533        T: AsRef<str>,
1534    {
1535        self._additional_params
1536            .insert(name.as_ref().to_string(), value.as_ref().to_string());
1537        self
1538    }
1539
1540    /// Identifies the authorization scope for the method you are building.
1541    ///
1542    /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
1543    /// [`Scope::CloudPlatform`].
1544    ///
1545    /// The `scope` will be added to a set of scopes. This is important as one can maintain access
1546    /// tokens for more than one scope.
1547    ///
1548    /// Usually there is more than one suitable scope to authorize an operation, some of which may
1549    /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
1550    /// sufficient, a read-write scope will do as well.
1551    pub fn add_scope<St>(mut self, scope: St) -> ShelfBookReturnCall<'a, C>
1552    where
1553        St: AsRef<str>,
1554    {
1555        self._scopes.insert(String::from(scope.as_ref()));
1556        self
1557    }
1558    /// Identifies the authorization scope(s) for the method you are building.
1559    ///
1560    /// See [`Self::add_scope()`] for details.
1561    pub fn add_scopes<I, St>(mut self, scopes: I) -> ShelfBookReturnCall<'a, C>
1562    where
1563        I: IntoIterator<Item = St>,
1564        St: AsRef<str>,
1565    {
1566        self._scopes
1567            .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
1568        self
1569    }
1570
1571    /// Removes all scopes, and no default scope will be used either.
1572    /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
1573    /// for details).
1574    pub fn clear_scopes(mut self) -> ShelfBookReturnCall<'a, C> {
1575        self._scopes.clear();
1576        self
1577    }
1578}
1579
1580/// Gets a shelf. Returns NOT_FOUND if the shelf does not exist.
1581///
1582/// A builder for the *get* method supported by a *shelf* resource.
1583/// It is not used directly, but through a [`ShelfMethods`] instance.
1584///
1585/// # Example
1586///
1587/// Instantiate a resource method builder
1588///
1589/// ```test_harness,no_run
1590/// # extern crate hyper;
1591/// # extern crate hyper_rustls;
1592/// # extern crate google_libraryagent1 as libraryagent1;
1593/// # async fn dox() {
1594/// # use libraryagent1::{Libraryagent, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
1595///
1596/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
1597/// # let auth = yup_oauth2::InstalledFlowAuthenticator::builder(
1598/// #     secret,
1599/// #     yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
1600/// # ).build().await.unwrap();
1601///
1602/// # let client = hyper_util::client::legacy::Client::builder(
1603/// #     hyper_util::rt::TokioExecutor::new()
1604/// # )
1605/// # .build(
1606/// #     hyper_rustls::HttpsConnectorBuilder::new()
1607/// #         .with_native_roots()
1608/// #         .unwrap()
1609/// #         .https_or_http()
1610/// #         .enable_http1()
1611/// #         .build()
1612/// # );
1613/// # let mut hub = Libraryagent::new(client, auth);
1614/// // You can configure optional parameters by calling the respective setters at will, and
1615/// // execute the final call using `doit()`.
1616/// // Values shown here are possibly random and not representative !
1617/// let result = hub.shelves().get("name")
1618///              .doit().await;
1619/// # }
1620/// ```
1621pub struct ShelfGetCall<'a, C>
1622where
1623    C: 'a,
1624{
1625    hub: &'a Libraryagent<C>,
1626    _name: String,
1627    _delegate: Option<&'a mut dyn common::Delegate>,
1628    _additional_params: HashMap<String, String>,
1629    _scopes: BTreeSet<String>,
1630}
1631
1632impl<'a, C> common::CallBuilder for ShelfGetCall<'a, C> {}
1633
1634impl<'a, C> ShelfGetCall<'a, C>
1635where
1636    C: common::Connector,
1637{
1638    /// Perform the operation you have build so far.
1639    pub async fn doit(
1640        mut self,
1641    ) -> common::Result<(common::Response, GoogleExampleLibraryagentV1Shelf)> {
1642        use std::borrow::Cow;
1643        use std::io::{Read, Seek};
1644
1645        use common::{url::Params, ToParts};
1646        use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
1647
1648        let mut dd = common::DefaultDelegate;
1649        let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
1650        dlg.begin(common::MethodInfo {
1651            id: "libraryagent.shelves.get",
1652            http_method: hyper::Method::GET,
1653        });
1654
1655        for &field in ["alt", "name"].iter() {
1656            if self._additional_params.contains_key(field) {
1657                dlg.finished(false);
1658                return Err(common::Error::FieldClash(field));
1659            }
1660        }
1661
1662        let mut params = Params::with_capacity(3 + self._additional_params.len());
1663        params.push("name", self._name);
1664
1665        params.extend(self._additional_params.iter());
1666
1667        params.push("alt", "json");
1668        let mut url = self.hub._base_url.clone() + "v1/{+name}";
1669        if self._scopes.is_empty() {
1670            self._scopes
1671                .insert(Scope::CloudPlatform.as_ref().to_string());
1672        }
1673
1674        #[allow(clippy::single_element_loop)]
1675        for &(find_this, param_name) in [("{+name}", "name")].iter() {
1676            url = params.uri_replacement(url, param_name, find_this, true);
1677        }
1678        {
1679            let to_remove = ["name"];
1680            params.remove_params(&to_remove);
1681        }
1682
1683        let url = params.parse_with_url(&url);
1684
1685        loop {
1686            let token = match self
1687                .hub
1688                .auth
1689                .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
1690                .await
1691            {
1692                Ok(token) => token,
1693                Err(e) => match dlg.token(e) {
1694                    Ok(token) => token,
1695                    Err(e) => {
1696                        dlg.finished(false);
1697                        return Err(common::Error::MissingToken(e));
1698                    }
1699                },
1700            };
1701            let mut req_result = {
1702                let client = &self.hub.client;
1703                dlg.pre_request();
1704                let mut req_builder = hyper::Request::builder()
1705                    .method(hyper::Method::GET)
1706                    .uri(url.as_str())
1707                    .header(USER_AGENT, self.hub._user_agent.clone());
1708
1709                if let Some(token) = token.as_ref() {
1710                    req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
1711                }
1712
1713                let request = req_builder
1714                    .header(CONTENT_LENGTH, 0_u64)
1715                    .body(common::to_body::<String>(None));
1716
1717                client.request(request.unwrap()).await
1718            };
1719
1720            match req_result {
1721                Err(err) => {
1722                    if let common::Retry::After(d) = dlg.http_error(&err) {
1723                        sleep(d).await;
1724                        continue;
1725                    }
1726                    dlg.finished(false);
1727                    return Err(common::Error::HttpError(err));
1728                }
1729                Ok(res) => {
1730                    let (mut parts, body) = res.into_parts();
1731                    let mut body = common::Body::new(body);
1732                    if !parts.status.is_success() {
1733                        let bytes = common::to_bytes(body).await.unwrap_or_default();
1734                        let error = serde_json::from_str(&common::to_string(&bytes));
1735                        let response = common::to_response(parts, bytes.into());
1736
1737                        if let common::Retry::After(d) =
1738                            dlg.http_failure(&response, error.as_ref().ok())
1739                        {
1740                            sleep(d).await;
1741                            continue;
1742                        }
1743
1744                        dlg.finished(false);
1745
1746                        return Err(match error {
1747                            Ok(value) => common::Error::BadRequest(value),
1748                            _ => common::Error::Failure(response),
1749                        });
1750                    }
1751                    let response = {
1752                        let bytes = common::to_bytes(body).await.unwrap_or_default();
1753                        let encoded = common::to_string(&bytes);
1754                        match serde_json::from_str(&encoded) {
1755                            Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
1756                            Err(error) => {
1757                                dlg.response_json_decode_error(&encoded, &error);
1758                                return Err(common::Error::JsonDecodeError(
1759                                    encoded.to_string(),
1760                                    error,
1761                                ));
1762                            }
1763                        }
1764                    };
1765
1766                    dlg.finished(true);
1767                    return Ok(response);
1768                }
1769            }
1770        }
1771    }
1772
1773    /// Required. The name of the shelf to retrieve.
1774    ///
1775    /// Sets the *name* path property to the given value.
1776    ///
1777    /// Even though the property as already been set when instantiating this call,
1778    /// we provide this method for API completeness.
1779    pub fn name(mut self, new_value: &str) -> ShelfGetCall<'a, C> {
1780        self._name = new_value.to_string();
1781        self
1782    }
1783    /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
1784    /// while executing the actual API request.
1785    ///
1786    /// ````text
1787    ///                   It should be used to handle progress information, and to implement a certain level of resilience.
1788    /// ````
1789    ///
1790    /// Sets the *delegate* property to the given value.
1791    pub fn delegate(mut self, new_value: &'a mut dyn common::Delegate) -> ShelfGetCall<'a, C> {
1792        self._delegate = Some(new_value);
1793        self
1794    }
1795
1796    /// Set any additional parameter of the query string used in the request.
1797    /// It should be used to set parameters which are not yet available through their own
1798    /// setters.
1799    ///
1800    /// Please note that this method must not be used to set any of the known parameters
1801    /// which have their own setter method. If done anyway, the request will fail.
1802    ///
1803    /// # Additional Parameters
1804    ///
1805    /// * *$.xgafv* (query-string) - V1 error format.
1806    /// * *access_token* (query-string) - OAuth access token.
1807    /// * *alt* (query-string) - Data format for response.
1808    /// * *callback* (query-string) - JSONP
1809    /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
1810    /// * *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.
1811    /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
1812    /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
1813    /// * *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.
1814    /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
1815    /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
1816    pub fn param<T>(mut self, name: T, value: T) -> ShelfGetCall<'a, C>
1817    where
1818        T: AsRef<str>,
1819    {
1820        self._additional_params
1821            .insert(name.as_ref().to_string(), value.as_ref().to_string());
1822        self
1823    }
1824
1825    /// Identifies the authorization scope for the method you are building.
1826    ///
1827    /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
1828    /// [`Scope::CloudPlatform`].
1829    ///
1830    /// The `scope` will be added to a set of scopes. This is important as one can maintain access
1831    /// tokens for more than one scope.
1832    ///
1833    /// Usually there is more than one suitable scope to authorize an operation, some of which may
1834    /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
1835    /// sufficient, a read-write scope will do as well.
1836    pub fn add_scope<St>(mut self, scope: St) -> ShelfGetCall<'a, C>
1837    where
1838        St: AsRef<str>,
1839    {
1840        self._scopes.insert(String::from(scope.as_ref()));
1841        self
1842    }
1843    /// Identifies the authorization scope(s) for the method you are building.
1844    ///
1845    /// See [`Self::add_scope()`] for details.
1846    pub fn add_scopes<I, St>(mut self, scopes: I) -> ShelfGetCall<'a, C>
1847    where
1848        I: IntoIterator<Item = St>,
1849        St: AsRef<str>,
1850    {
1851        self._scopes
1852            .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
1853        self
1854    }
1855
1856    /// Removes all scopes, and no default scope will be used either.
1857    /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
1858    /// for details).
1859    pub fn clear_scopes(mut self) -> ShelfGetCall<'a, C> {
1860        self._scopes.clear();
1861        self
1862    }
1863}
1864
1865/// Lists shelves. The order is unspecified but deterministic. Newly created shelves will not necessarily be added to the end of this list.
1866///
1867/// A builder for the *list* method supported by a *shelf* resource.
1868/// It is not used directly, but through a [`ShelfMethods`] instance.
1869///
1870/// # Example
1871///
1872/// Instantiate a resource method builder
1873///
1874/// ```test_harness,no_run
1875/// # extern crate hyper;
1876/// # extern crate hyper_rustls;
1877/// # extern crate google_libraryagent1 as libraryagent1;
1878/// # async fn dox() {
1879/// # use libraryagent1::{Libraryagent, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
1880///
1881/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
1882/// # let auth = yup_oauth2::InstalledFlowAuthenticator::builder(
1883/// #     secret,
1884/// #     yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
1885/// # ).build().await.unwrap();
1886///
1887/// # let client = hyper_util::client::legacy::Client::builder(
1888/// #     hyper_util::rt::TokioExecutor::new()
1889/// # )
1890/// # .build(
1891/// #     hyper_rustls::HttpsConnectorBuilder::new()
1892/// #         .with_native_roots()
1893/// #         .unwrap()
1894/// #         .https_or_http()
1895/// #         .enable_http1()
1896/// #         .build()
1897/// # );
1898/// # let mut hub = Libraryagent::new(client, auth);
1899/// // You can configure optional parameters by calling the respective setters at will, and
1900/// // execute the final call using `doit()`.
1901/// // Values shown here are possibly random and not representative !
1902/// let result = hub.shelves().list()
1903///              .page_token("amet.")
1904///              .page_size(-20)
1905///              .doit().await;
1906/// # }
1907/// ```
1908pub struct ShelfListCall<'a, C>
1909where
1910    C: 'a,
1911{
1912    hub: &'a Libraryagent<C>,
1913    _page_token: Option<String>,
1914    _page_size: Option<i32>,
1915    _delegate: Option<&'a mut dyn common::Delegate>,
1916    _additional_params: HashMap<String, String>,
1917    _scopes: BTreeSet<String>,
1918}
1919
1920impl<'a, C> common::CallBuilder for ShelfListCall<'a, C> {}
1921
1922impl<'a, C> ShelfListCall<'a, C>
1923where
1924    C: common::Connector,
1925{
1926    /// Perform the operation you have build so far.
1927    pub async fn doit(
1928        mut self,
1929    ) -> common::Result<(
1930        common::Response,
1931        GoogleExampleLibraryagentV1ListShelvesResponse,
1932    )> {
1933        use std::borrow::Cow;
1934        use std::io::{Read, Seek};
1935
1936        use common::{url::Params, ToParts};
1937        use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
1938
1939        let mut dd = common::DefaultDelegate;
1940        let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
1941        dlg.begin(common::MethodInfo {
1942            id: "libraryagent.shelves.list",
1943            http_method: hyper::Method::GET,
1944        });
1945
1946        for &field in ["alt", "pageToken", "pageSize"].iter() {
1947            if self._additional_params.contains_key(field) {
1948                dlg.finished(false);
1949                return Err(common::Error::FieldClash(field));
1950            }
1951        }
1952
1953        let mut params = Params::with_capacity(4 + self._additional_params.len());
1954        if let Some(value) = self._page_token.as_ref() {
1955            params.push("pageToken", value);
1956        }
1957        if let Some(value) = self._page_size.as_ref() {
1958            params.push("pageSize", value.to_string());
1959        }
1960
1961        params.extend(self._additional_params.iter());
1962
1963        params.push("alt", "json");
1964        let mut url = self.hub._base_url.clone() + "v1/shelves";
1965        if self._scopes.is_empty() {
1966            self._scopes
1967                .insert(Scope::CloudPlatform.as_ref().to_string());
1968        }
1969
1970        let url = params.parse_with_url(&url);
1971
1972        loop {
1973            let token = match self
1974                .hub
1975                .auth
1976                .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
1977                .await
1978            {
1979                Ok(token) => token,
1980                Err(e) => match dlg.token(e) {
1981                    Ok(token) => token,
1982                    Err(e) => {
1983                        dlg.finished(false);
1984                        return Err(common::Error::MissingToken(e));
1985                    }
1986                },
1987            };
1988            let mut req_result = {
1989                let client = &self.hub.client;
1990                dlg.pre_request();
1991                let mut req_builder = hyper::Request::builder()
1992                    .method(hyper::Method::GET)
1993                    .uri(url.as_str())
1994                    .header(USER_AGENT, self.hub._user_agent.clone());
1995
1996                if let Some(token) = token.as_ref() {
1997                    req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
1998                }
1999
2000                let request = req_builder
2001                    .header(CONTENT_LENGTH, 0_u64)
2002                    .body(common::to_body::<String>(None));
2003
2004                client.request(request.unwrap()).await
2005            };
2006
2007            match req_result {
2008                Err(err) => {
2009                    if let common::Retry::After(d) = dlg.http_error(&err) {
2010                        sleep(d).await;
2011                        continue;
2012                    }
2013                    dlg.finished(false);
2014                    return Err(common::Error::HttpError(err));
2015                }
2016                Ok(res) => {
2017                    let (mut parts, body) = res.into_parts();
2018                    let mut body = common::Body::new(body);
2019                    if !parts.status.is_success() {
2020                        let bytes = common::to_bytes(body).await.unwrap_or_default();
2021                        let error = serde_json::from_str(&common::to_string(&bytes));
2022                        let response = common::to_response(parts, bytes.into());
2023
2024                        if let common::Retry::After(d) =
2025                            dlg.http_failure(&response, error.as_ref().ok())
2026                        {
2027                            sleep(d).await;
2028                            continue;
2029                        }
2030
2031                        dlg.finished(false);
2032
2033                        return Err(match error {
2034                            Ok(value) => common::Error::BadRequest(value),
2035                            _ => common::Error::Failure(response),
2036                        });
2037                    }
2038                    let response = {
2039                        let bytes = common::to_bytes(body).await.unwrap_or_default();
2040                        let encoded = common::to_string(&bytes);
2041                        match serde_json::from_str(&encoded) {
2042                            Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
2043                            Err(error) => {
2044                                dlg.response_json_decode_error(&encoded, &error);
2045                                return Err(common::Error::JsonDecodeError(
2046                                    encoded.to_string(),
2047                                    error,
2048                                ));
2049                            }
2050                        }
2051                    };
2052
2053                    dlg.finished(true);
2054                    return Ok(response);
2055                }
2056            }
2057        }
2058    }
2059
2060    /// A token identifying a page of results the server should return. Typically, this is the value of ListShelvesResponse.next_page_token returned from the previous call to `ListShelves` method.
2061    ///
2062    /// Sets the *page token* query property to the given value.
2063    pub fn page_token(mut self, new_value: &str) -> ShelfListCall<'a, C> {
2064        self._page_token = Some(new_value.to_string());
2065        self
2066    }
2067    /// Requested page size. Server may return fewer shelves than requested. If unspecified, server will pick an appropriate default.
2068    ///
2069    /// Sets the *page size* query property to the given value.
2070    pub fn page_size(mut self, new_value: i32) -> ShelfListCall<'a, C> {
2071        self._page_size = Some(new_value);
2072        self
2073    }
2074    /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
2075    /// while executing the actual API request.
2076    ///
2077    /// ````text
2078    ///                   It should be used to handle progress information, and to implement a certain level of resilience.
2079    /// ````
2080    ///
2081    /// Sets the *delegate* property to the given value.
2082    pub fn delegate(mut self, new_value: &'a mut dyn common::Delegate) -> ShelfListCall<'a, C> {
2083        self._delegate = Some(new_value);
2084        self
2085    }
2086
2087    /// Set any additional parameter of the query string used in the request.
2088    /// It should be used to set parameters which are not yet available through their own
2089    /// setters.
2090    ///
2091    /// Please note that this method must not be used to set any of the known parameters
2092    /// which have their own setter method. If done anyway, the request will fail.
2093    ///
2094    /// # Additional Parameters
2095    ///
2096    /// * *$.xgafv* (query-string) - V1 error format.
2097    /// * *access_token* (query-string) - OAuth access token.
2098    /// * *alt* (query-string) - Data format for response.
2099    /// * *callback* (query-string) - JSONP
2100    /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
2101    /// * *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.
2102    /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
2103    /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
2104    /// * *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.
2105    /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
2106    /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
2107    pub fn param<T>(mut self, name: T, value: T) -> ShelfListCall<'a, C>
2108    where
2109        T: AsRef<str>,
2110    {
2111        self._additional_params
2112            .insert(name.as_ref().to_string(), value.as_ref().to_string());
2113        self
2114    }
2115
2116    /// Identifies the authorization scope for the method you are building.
2117    ///
2118    /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
2119    /// [`Scope::CloudPlatform`].
2120    ///
2121    /// The `scope` will be added to a set of scopes. This is important as one can maintain access
2122    /// tokens for more than one scope.
2123    ///
2124    /// Usually there is more than one suitable scope to authorize an operation, some of which may
2125    /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
2126    /// sufficient, a read-write scope will do as well.
2127    pub fn add_scope<St>(mut self, scope: St) -> ShelfListCall<'a, C>
2128    where
2129        St: AsRef<str>,
2130    {
2131        self._scopes.insert(String::from(scope.as_ref()));
2132        self
2133    }
2134    /// Identifies the authorization scope(s) for the method you are building.
2135    ///
2136    /// See [`Self::add_scope()`] for details.
2137    pub fn add_scopes<I, St>(mut self, scopes: I) -> ShelfListCall<'a, C>
2138    where
2139        I: IntoIterator<Item = St>,
2140        St: AsRef<str>,
2141    {
2142        self._scopes
2143            .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
2144        self
2145    }
2146
2147    /// Removes all scopes, and no default scope will be used either.
2148    /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
2149    /// for details).
2150    pub fn clear_scopes(mut self) -> ShelfListCall<'a, C> {
2151        self._scopes.clear();
2152        self
2153    }
2154}