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