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