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