mirror of
https://github.com/OMGeeky/google-apis-rs.git
synced 2026-01-02 01:20:02 +01:00
2549 lines
108 KiB
Rust
2549 lines
108 KiB
Rust
use std::collections::HashMap;
|
||
use std::cell::RefCell;
|
||
use std::default::Default;
|
||
use std::collections::BTreeMap;
|
||
use serde_json as json;
|
||
use std::io;
|
||
use std::fs;
|
||
use std::mem;
|
||
use std::thread::sleep;
|
||
|
||
use crate::client;
|
||
|
||
// ##############
|
||
// UTILITIES ###
|
||
// ############
|
||
|
||
/// Identifies the an OAuth2 authorization scope.
|
||
/// A scope is needed when requesting an
|
||
/// [authorization token](https://developers.google.com/youtube/v3/guides/authentication).
|
||
#[derive(PartialEq, Eq, Hash)]
|
||
pub enum Scope {
|
||
/// See, edit, create and permanently delete all your Google Keep data
|
||
Full,
|
||
|
||
/// View all your Google Keep data
|
||
Readonly,
|
||
}
|
||
|
||
impl AsRef<str> for Scope {
|
||
fn as_ref(&self) -> &str {
|
||
match *self {
|
||
Scope::Full => "https://www.googleapis.com/auth/keep",
|
||
Scope::Readonly => "https://www.googleapis.com/auth/keep.readonly",
|
||
}
|
||
}
|
||
}
|
||
|
||
impl Default for Scope {
|
||
fn default() -> Scope {
|
||
Scope::Readonly
|
||
}
|
||
}
|
||
|
||
|
||
|
||
// ########
|
||
// HUB ###
|
||
// ######
|
||
|
||
/// Central instance to access all Keep related resource activities
|
||
///
|
||
/// # Examples
|
||
///
|
||
/// Instantiate a new hub
|
||
///
|
||
/// ```test_harness,no_run
|
||
/// extern crate hyper;
|
||
/// extern crate hyper_rustls;
|
||
/// extern crate google_keep1 as keep1;
|
||
/// use keep1::{Result, Error};
|
||
/// # async fn dox() {
|
||
/// use std::default::Default;
|
||
/// use keep1::{Keep, oauth2, hyper, hyper_rustls};
|
||
///
|
||
/// // Get an ApplicationSecret instance by some means. It contains the `client_id` and
|
||
/// // `client_secret`, among other things.
|
||
/// let secret: oauth2::ApplicationSecret = Default::default();
|
||
/// // Instantiate the authenticator. It will choose a suitable authentication flow for you,
|
||
/// // unless you replace `None` with the desired Flow.
|
||
/// // Provide your own `AuthenticatorDelegate` to adjust the way it operates and get feedback about
|
||
/// // what's going on. You probably want to bring in your own `TokenStorage` to persist tokens and
|
||
/// // retrieve them from storage.
|
||
/// let auth = oauth2::InstalledFlowAuthenticator::builder(
|
||
/// secret,
|
||
/// oauth2::InstalledFlowReturnMethod::HTTPRedirect,
|
||
/// ).build().await.unwrap();
|
||
/// let mut hub = Keep::new(hyper::Client::builder().build(hyper_rustls::HttpsConnector::with_native_roots().https_or_http().enable_http1().enable_http2().build()), auth);
|
||
/// // You can configure optional parameters by calling the respective setters at will, and
|
||
/// // execute the final call using `doit()`.
|
||
/// // Values shown here are possibly random and not representative !
|
||
/// let result = hub.notes().list()
|
||
/// .page_token("sanctus")
|
||
/// .page_size(-80)
|
||
/// .filter("amet.")
|
||
/// .doit().await;
|
||
///
|
||
/// match result {
|
||
/// Err(e) => match e {
|
||
/// // The Error enum provides details about what exactly happened.
|
||
/// // You can also just use its `Debug`, `Display` or `Error` traits
|
||
/// Error::HttpError(_)
|
||
/// |Error::Io(_)
|
||
/// |Error::MissingAPIKey
|
||
/// |Error::MissingToken(_)
|
||
/// |Error::Cancelled
|
||
/// |Error::UploadSizeLimitExceeded(_, _)
|
||
/// |Error::Failure(_)
|
||
/// |Error::BadRequest(_)
|
||
/// |Error::FieldClash(_)
|
||
/// |Error::JsonDecodeError(_, _) => println!("{}", e),
|
||
/// },
|
||
/// Ok(res) => println!("Success: {:?}", res),
|
||
/// }
|
||
/// # }
|
||
/// ```
|
||
#[derive(Clone)]
|
||
pub struct Keep<> {
|
||
pub client: hyper::Client<hyper_rustls::HttpsConnector<hyper::client::connect::HttpConnector>, hyper::body::Body>,
|
||
pub auth: oauth2::authenticator::Authenticator<hyper_rustls::HttpsConnector<hyper::client::connect::HttpConnector>>,
|
||
_user_agent: String,
|
||
_base_url: String,
|
||
_root_url: String,
|
||
}
|
||
|
||
impl<'a, > client::Hub for Keep<> {}
|
||
|
||
impl<'a, > Keep<> {
|
||
|
||
pub fn new(client: hyper::Client<hyper_rustls::HttpsConnector<hyper::client::connect::HttpConnector>, hyper::body::Body>, authenticator: oauth2::authenticator::Authenticator<hyper_rustls::HttpsConnector<hyper::client::connect::HttpConnector>>) -> Keep<> {
|
||
Keep {
|
||
client,
|
||
auth: authenticator,
|
||
_user_agent: "google-api-rust-client/3.1.0".to_string(),
|
||
_base_url: "https://keep.googleapis.com/".to_string(),
|
||
_root_url: "https://keep.googleapis.com/".to_string(),
|
||
}
|
||
}
|
||
|
||
pub fn media(&'a self) -> MediaMethods<'a> {
|
||
MediaMethods { hub: &self }
|
||
}
|
||
pub fn notes(&'a self) -> NoteMethods<'a> {
|
||
NoteMethods { hub: &self }
|
||
}
|
||
|
||
/// Set the user-agent header field to use in all requests to the server.
|
||
/// It defaults to `google-api-rust-client/3.1.0`.
|
||
///
|
||
/// Returns the previously set user-agent.
|
||
pub fn user_agent(&mut self, agent_name: String) -> String {
|
||
mem::replace(&mut self._user_agent, agent_name)
|
||
}
|
||
|
||
/// Set the base url to use in all requests to the server.
|
||
/// It defaults to `https://keep.googleapis.com/`.
|
||
///
|
||
/// Returns the previously set base url.
|
||
pub fn base_url(&mut self, new_base_url: String) -> String {
|
||
mem::replace(&mut self._base_url, new_base_url)
|
||
}
|
||
|
||
/// Set the root url to use in all requests to the server.
|
||
/// It defaults to `https://keep.googleapis.com/`.
|
||
///
|
||
/// Returns the previously set root url.
|
||
pub fn root_url(&mut self, new_root_url: String) -> String {
|
||
mem::replace(&mut self._root_url, new_root_url)
|
||
}
|
||
}
|
||
|
||
|
||
// ############
|
||
// SCHEMAS ###
|
||
// ##########
|
||
/// An attachment to a note.
|
||
///
|
||
/// # Activities
|
||
///
|
||
/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
|
||
/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
|
||
///
|
||
/// * [download media](MediaDownloadCall) (response)
|
||
///
|
||
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
|
||
pub struct Attachment {
|
||
/// The MIME types (IANA media types) in which the attachment is available.
|
||
#[serde(rename="mimeType")]
|
||
pub mime_type: Option<Vec<String>>,
|
||
/// The resource name;
|
||
pub name: Option<String>,
|
||
}
|
||
|
||
impl client::ResponseResult for Attachment {}
|
||
|
||
|
||
/// 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.
|
||
///
|
||
/// # Activities
|
||
///
|
||
/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
|
||
/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
|
||
///
|
||
/// * [permissions batch create notes](NotePermissionBatchCreateCall) (request)
|
||
///
|
||
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
|
||
pub struct BatchCreatePermissionsRequest {
|
||
/// The request message specifying the resources to create.
|
||
pub requests: Option<Vec<CreatePermissionRequest>>,
|
||
}
|
||
|
||
impl client::RequestValue for BatchCreatePermissionsRequest {}
|
||
|
||
|
||
/// The response for creating permissions on a note.
|
||
///
|
||
/// # Activities
|
||
///
|
||
/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
|
||
/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
|
||
///
|
||
/// * [permissions batch create notes](NotePermissionBatchCreateCall) (response)
|
||
///
|
||
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
|
||
pub struct BatchCreatePermissionsResponse {
|
||
/// Permissions created.
|
||
pub permissions: Option<Vec<Permission>>,
|
||
}
|
||
|
||
impl client::ResponseResult for BatchCreatePermissionsResponse {}
|
||
|
||
|
||
/// 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.
|
||
///
|
||
/// # Activities
|
||
///
|
||
/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
|
||
/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
|
||
///
|
||
/// * [permissions batch delete notes](NotePermissionBatchDeleteCall) (request)
|
||
///
|
||
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
|
||
pub struct BatchDeletePermissionsRequest {
|
||
/// Required. The names of the permissions to delete. Format: `notes/{note}/permissions/{permission}`
|
||
pub names: Option<Vec<String>>,
|
||
}
|
||
|
||
impl client::RequestValue for BatchDeletePermissionsRequest {}
|
||
|
||
|
||
/// The request to add a single permission on the note.
|
||
///
|
||
/// This type is not used in any activity, and only used as *part* of another schema.
|
||
///
|
||
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
|
||
pub struct CreatePermissionRequest {
|
||
/// Required. The parent note where this permission will be created. Format: `notes/{note}`
|
||
pub parent: Option<String>,
|
||
/// Required. The permission to create. One of Permission.email, User.email or Group.email must be supplied.
|
||
pub permission: Option<Permission>,
|
||
}
|
||
|
||
impl client::Part for CreatePermissionRequest {}
|
||
|
||
|
||
/// 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); } The JSON representation for `Empty` is empty JSON object `{}`.
|
||
///
|
||
/// # Activities
|
||
///
|
||
/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
|
||
/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
|
||
///
|
||
/// * [permissions batch delete notes](NotePermissionBatchDeleteCall) (response)
|
||
/// * [delete notes](NoteDeleteCall) (response)
|
||
///
|
||
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
|
||
pub struct Empty { _never_set: Option<bool> }
|
||
|
||
impl client::ResponseResult for Empty {}
|
||
|
||
|
||
/// Describes a single Google Family.
|
||
///
|
||
/// This type is not used in any activity, and only used as *part* of another schema.
|
||
///
|
||
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
|
||
pub struct Family { _never_set: Option<bool> }
|
||
|
||
impl client::Part for Family {}
|
||
|
||
|
||
/// Describes a single Group.
|
||
///
|
||
/// This type is not used in any activity, and only used as *part* of another schema.
|
||
///
|
||
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
|
||
pub struct Group {
|
||
/// The group email.
|
||
pub email: Option<String>,
|
||
}
|
||
|
||
impl client::Part for Group {}
|
||
|
||
|
||
/// The list of items for a single list note.
|
||
///
|
||
/// This type is not used in any activity, and only used as *part* of another schema.
|
||
///
|
||
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
|
||
pub struct ListContent {
|
||
/// The items in the list. The number of items must be less than 1,000.
|
||
#[serde(rename="listItems")]
|
||
pub list_items: Option<Vec<ListItem>>,
|
||
}
|
||
|
||
impl client::Part for ListContent {}
|
||
|
||
|
||
/// A single list item in a note's list.
|
||
///
|
||
/// This type is not used in any activity, and only used as *part* of another schema.
|
||
///
|
||
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
|
||
pub struct ListItem {
|
||
/// Whether this item has been checked off or not.
|
||
pub checked: Option<bool>,
|
||
/// If set, list of list items nested under this list item. Only one level of nesting is allowed.
|
||
#[serde(rename="childListItems")]
|
||
pub child_list_items: Option<Vec<ListItem>>,
|
||
/// The text of this item. Length must be less than 1,000 characters.
|
||
pub text: Option<TextContent>,
|
||
}
|
||
|
||
impl client::Part for ListItem {}
|
||
|
||
|
||
/// The response when listing a page of notes.
|
||
///
|
||
/// # Activities
|
||
///
|
||
/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
|
||
/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
|
||
///
|
||
/// * [list notes](NoteListCall) (response)
|
||
///
|
||
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
|
||
pub struct ListNotesResponse {
|
||
/// Next page's `page_token` field.
|
||
#[serde(rename="nextPageToken")]
|
||
pub next_page_token: Option<String>,
|
||
/// A page of notes.
|
||
pub notes: Option<Vec<Note>>,
|
||
}
|
||
|
||
impl client::ResponseResult for ListNotesResponse {}
|
||
|
||
|
||
/// A single note.
|
||
///
|
||
/// # Activities
|
||
///
|
||
/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
|
||
/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
|
||
///
|
||
/// * [permissions batch create notes](NotePermissionBatchCreateCall) (none)
|
||
/// * [permissions batch delete notes](NotePermissionBatchDeleteCall) (none)
|
||
/// * [create notes](NoteCreateCall) (request|response)
|
||
/// * [delete notes](NoteDeleteCall) (none)
|
||
/// * [get notes](NoteGetCall) (response)
|
||
/// * [list notes](NoteListCall) (none)
|
||
///
|
||
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
|
||
pub struct Note {
|
||
/// Output only. The attachments attached to this note.
|
||
pub attachments: Option<Vec<Attachment>>,
|
||
/// The body of the note.
|
||
pub body: Option<Section>,
|
||
/// Output only. When this note was created.
|
||
#[serde(rename="createTime")]
|
||
pub create_time: Option<String>,
|
||
/// Output only. The resource name of this note. See general note on identifiers in KeepService.
|
||
pub name: Option<String>,
|
||
/// Output only. The list of permissions set on the note. Contains at least one entry for the note owner.
|
||
pub permissions: Option<Vec<Permission>>,
|
||
/// The title of the note. Length must be less than 1,000 characters.
|
||
pub title: Option<String>,
|
||
/// 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`).
|
||
#[serde(rename="trashTime")]
|
||
pub trash_time: Option<String>,
|
||
/// Output only. `true` if this note has been trashed. If trashed, the note is eventually deleted.
|
||
pub trashed: Option<bool>,
|
||
/// Output only. When this note was last modified.
|
||
#[serde(rename="updateTime")]
|
||
pub update_time: Option<String>,
|
||
}
|
||
|
||
impl client::RequestValue for Note {}
|
||
impl client::Resource for Note {}
|
||
impl client::ResponseResult for Note {}
|
||
|
||
|
||
/// A single permission on the note. Associates a `member` with a `role`.
|
||
///
|
||
/// This type is not used in any activity, and only used as *part* of another schema.
|
||
///
|
||
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
|
||
pub struct Permission {
|
||
/// 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.
|
||
pub deleted: Option<bool>,
|
||
/// 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.
|
||
pub email: Option<String>,
|
||
/// Output only. The Google Family to which this role applies.
|
||
pub family: Option<Family>,
|
||
/// Output only. The group to which this role applies.
|
||
pub group: Option<Group>,
|
||
/// Output only. The resource name.
|
||
pub name: Option<String>,
|
||
/// The role granted by this permission. The role determines the entity’s ability to read, write, and share notes.
|
||
pub role: Option<String>,
|
||
/// Output only. The user to whom this role applies.
|
||
pub user: Option<User>,
|
||
}
|
||
|
||
impl client::Part for Permission {}
|
||
|
||
|
||
/// The content of the note.
|
||
///
|
||
/// This type is not used in any activity, and only used as *part* of another schema.
|
||
///
|
||
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
|
||
pub struct Section {
|
||
/// Used if this section's content is a list.
|
||
pub list: Option<ListContent>,
|
||
/// Used if this section's content is a block of text. The length of the text content must be less than 20,000 characters.
|
||
pub text: Option<TextContent>,
|
||
}
|
||
|
||
impl client::Part for Section {}
|
||
|
||
|
||
/// The block of text for a single text section or list item.
|
||
///
|
||
/// This type is not used in any activity, and only used as *part* of another schema.
|
||
///
|
||
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
|
||
pub struct TextContent {
|
||
/// The text of the note. The limits on this vary with the specific field using this type.
|
||
pub text: Option<String>,
|
||
}
|
||
|
||
impl client::Part for TextContent {}
|
||
|
||
|
||
/// Describes a single user.
|
||
///
|
||
/// This type is not used in any activity, and only used as *part* of another schema.
|
||
///
|
||
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
|
||
pub struct User {
|
||
/// The user's email.
|
||
pub email: Option<String>,
|
||
}
|
||
|
||
impl client::Part for User {}
|
||
|
||
|
||
|
||
// ###################
|
||
// MethodBuilders ###
|
||
// #################
|
||
|
||
/// A builder providing access to all methods supported on *media* resources.
|
||
/// It is not used directly, but through the `Keep` hub.
|
||
///
|
||
/// # Example
|
||
///
|
||
/// Instantiate a resource builder
|
||
///
|
||
/// ```test_harness,no_run
|
||
/// extern crate hyper;
|
||
/// extern crate hyper_rustls;
|
||
/// extern crate google_keep1 as keep1;
|
||
///
|
||
/// # async fn dox() {
|
||
/// use std::default::Default;
|
||
/// use keep1::{Keep, oauth2, hyper, hyper_rustls};
|
||
///
|
||
/// let secret: oauth2::ApplicationSecret = Default::default();
|
||
/// let auth = oauth2::InstalledFlowAuthenticator::builder(
|
||
/// secret,
|
||
/// oauth2::InstalledFlowReturnMethod::HTTPRedirect,
|
||
/// ).build().await.unwrap();
|
||
/// let mut hub = Keep::new(hyper::Client::builder().build(hyper_rustls::HttpsConnector::with_native_roots().https_or_http().enable_http1().enable_http2().build()), auth);
|
||
/// // Usually you wouldn't bind this to a variable, but keep calling *CallBuilders*
|
||
/// // like `download(...)`
|
||
/// // to build up your call.
|
||
/// let rb = hub.media();
|
||
/// # }
|
||
/// ```
|
||
pub struct MediaMethods<'a>
|
||
where {
|
||
|
||
hub: &'a Keep<>,
|
||
}
|
||
|
||
impl<'a> client::MethodsBuilder for MediaMethods<'a> {}
|
||
|
||
impl<'a> MediaMethods<'a> {
|
||
|
||
/// Create a builder to help you perform the following task:
|
||
///
|
||
/// 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.
|
||
///
|
||
/// # Arguments
|
||
///
|
||
/// * `name` - Required. The name of the attachment.
|
||
pub fn download(&self, name: &str) -> MediaDownloadCall<'a> {
|
||
MediaDownloadCall {
|
||
hub: self.hub,
|
||
_name: name.to_string(),
|
||
_mime_type: Default::default(),
|
||
_delegate: Default::default(),
|
||
_additional_params: Default::default(),
|
||
_scopes: Default::default(),
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
|
||
/// A builder providing access to all methods supported on *note* resources.
|
||
/// It is not used directly, but through the `Keep` hub.
|
||
///
|
||
/// # Example
|
||
///
|
||
/// Instantiate a resource builder
|
||
///
|
||
/// ```test_harness,no_run
|
||
/// extern crate hyper;
|
||
/// extern crate hyper_rustls;
|
||
/// extern crate google_keep1 as keep1;
|
||
///
|
||
/// # async fn dox() {
|
||
/// use std::default::Default;
|
||
/// use keep1::{Keep, oauth2, hyper, hyper_rustls};
|
||
///
|
||
/// let secret: oauth2::ApplicationSecret = Default::default();
|
||
/// let auth = oauth2::InstalledFlowAuthenticator::builder(
|
||
/// secret,
|
||
/// oauth2::InstalledFlowReturnMethod::HTTPRedirect,
|
||
/// ).build().await.unwrap();
|
||
/// let mut hub = Keep::new(hyper::Client::builder().build(hyper_rustls::HttpsConnector::with_native_roots().https_or_http().enable_http1().enable_http2().build()), auth);
|
||
/// // Usually you wouldn't bind this to a variable, but keep calling *CallBuilders*
|
||
/// // like `create(...)`, `delete(...)`, `get(...)`, `list(...)`, `permissions_batch_create(...)` and `permissions_batch_delete(...)`
|
||
/// // to build up your call.
|
||
/// let rb = hub.notes();
|
||
/// # }
|
||
/// ```
|
||
pub struct NoteMethods<'a>
|
||
where {
|
||
|
||
hub: &'a Keep<>,
|
||
}
|
||
|
||
impl<'a> client::MethodsBuilder for NoteMethods<'a> {}
|
||
|
||
impl<'a> NoteMethods<'a> {
|
||
|
||
/// Create a builder to help you perform the following task:
|
||
///
|
||
/// 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.
|
||
///
|
||
/// # Arguments
|
||
///
|
||
/// * `request` - No description provided.
|
||
/// * `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.
|
||
pub fn permissions_batch_create(&self, request: BatchCreatePermissionsRequest, parent: &str) -> NotePermissionBatchCreateCall<'a> {
|
||
NotePermissionBatchCreateCall {
|
||
hub: self.hub,
|
||
_request: request,
|
||
_parent: parent.to_string(),
|
||
_delegate: Default::default(),
|
||
_additional_params: Default::default(),
|
||
_scopes: Default::default(),
|
||
}
|
||
}
|
||
|
||
/// Create a builder to help you perform the following task:
|
||
///
|
||
/// 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.
|
||
///
|
||
/// # Arguments
|
||
///
|
||
/// * `request` - No description provided.
|
||
/// * `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.
|
||
pub fn permissions_batch_delete(&self, request: BatchDeletePermissionsRequest, parent: &str) -> NotePermissionBatchDeleteCall<'a> {
|
||
NotePermissionBatchDeleteCall {
|
||
hub: self.hub,
|
||
_request: request,
|
||
_parent: parent.to_string(),
|
||
_delegate: Default::default(),
|
||
_additional_params: Default::default(),
|
||
_scopes: Default::default(),
|
||
}
|
||
}
|
||
|
||
/// Create a builder to help you perform the following task:
|
||
///
|
||
/// Creates a new note.
|
||
///
|
||
/// # Arguments
|
||
///
|
||
/// * `request` - No description provided.
|
||
pub fn create(&self, request: Note) -> NoteCreateCall<'a> {
|
||
NoteCreateCall {
|
||
hub: self.hub,
|
||
_request: request,
|
||
_delegate: Default::default(),
|
||
_additional_params: Default::default(),
|
||
_scopes: Default::default(),
|
||
}
|
||
}
|
||
|
||
/// Create a builder to help you perform the following task:
|
||
///
|
||
/// 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.
|
||
///
|
||
/// # Arguments
|
||
///
|
||
/// * `name` - Required. Name of the note to delete.
|
||
pub fn delete(&self, name: &str) -> NoteDeleteCall<'a> {
|
||
NoteDeleteCall {
|
||
hub: self.hub,
|
||
_name: name.to_string(),
|
||
_delegate: Default::default(),
|
||
_additional_params: Default::default(),
|
||
_scopes: Default::default(),
|
||
}
|
||
}
|
||
|
||
/// Create a builder to help you perform the following task:
|
||
///
|
||
/// Gets a note.
|
||
///
|
||
/// # Arguments
|
||
///
|
||
/// * `name` - Required. Name of the resource.
|
||
pub fn get(&self, name: &str) -> NoteGetCall<'a> {
|
||
NoteGetCall {
|
||
hub: self.hub,
|
||
_name: name.to_string(),
|
||
_delegate: Default::default(),
|
||
_additional_params: Default::default(),
|
||
_scopes: Default::default(),
|
||
}
|
||
}
|
||
|
||
/// Create a builder to help you perform the following task:
|
||
///
|
||
/// 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.
|
||
pub fn list(&self) -> NoteListCall<'a> {
|
||
NoteListCall {
|
||
hub: self.hub,
|
||
_page_token: Default::default(),
|
||
_page_size: Default::default(),
|
||
_filter: Default::default(),
|
||
_delegate: Default::default(),
|
||
_additional_params: Default::default(),
|
||
_scopes: Default::default(),
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
// ###################
|
||
// CallBuilders ###
|
||
// #################
|
||
|
||
/// 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.
|
||
///
|
||
/// This method supports **media download**. To enable it, adjust the builder like this:
|
||
/// `.param("alt", "media")`.
|
||
/// Please note that due to missing multi-part support on the server side, you will only receive the media,
|
||
/// but not the `Attachment` structure that you would usually get. The latter will be a default value.
|
||
///
|
||
/// A builder for the *download* method supported by a *media* resource.
|
||
/// It is not used directly, but through a `MediaMethods` instance.
|
||
///
|
||
/// # Example
|
||
///
|
||
/// Instantiate a resource method builder
|
||
///
|
||
/// ```test_harness,no_run
|
||
/// # extern crate hyper;
|
||
/// # extern crate hyper_rustls;
|
||
/// # extern crate google_keep1 as keep1;
|
||
/// # async fn dox() {
|
||
/// # use std::default::Default;
|
||
/// # use keep1::{Keep, oauth2, hyper, hyper_rustls};
|
||
///
|
||
/// # let secret: oauth2::ApplicationSecret = Default::default();
|
||
/// # let auth = oauth2::InstalledFlowAuthenticator::builder(
|
||
/// # secret,
|
||
/// # oauth2::InstalledFlowReturnMethod::HTTPRedirect,
|
||
/// # ).build().await.unwrap();
|
||
/// # let mut hub = Keep::new(hyper::Client::builder().build(hyper_rustls::HttpsConnector::with_native_roots().https_or_http().enable_http1().enable_http2().build()), auth);
|
||
/// // You can configure optional parameters by calling the respective setters at will, and
|
||
/// // execute the final call using `doit()`.
|
||
/// // Values shown here are possibly random and not representative !
|
||
/// let result = hub.media().download("name")
|
||
/// .mime_type("amet.")
|
||
/// .doit().await;
|
||
/// # }
|
||
/// ```
|
||
pub struct MediaDownloadCall<'a>
|
||
where {
|
||
|
||
hub: &'a Keep<>,
|
||
_name: String,
|
||
_mime_type: Option<String>,
|
||
_delegate: Option<&'a mut dyn client::Delegate>,
|
||
_additional_params: HashMap<String, String>,
|
||
_scopes: BTreeMap<String, ()>
|
||
}
|
||
|
||
impl<'a> client::CallBuilder for MediaDownloadCall<'a> {}
|
||
|
||
impl<'a> MediaDownloadCall<'a> {
|
||
|
||
|
||
/// Perform the operation you have build so far.
|
||
pub async fn doit(mut self) -> client::Result<(hyper::Response<hyper::body::Body>, Attachment)> {
|
||
use url::percent_encoding::{percent_encode, DEFAULT_ENCODE_SET};
|
||
use std::io::{Read, Seek};
|
||
use hyper::header::{CONTENT_TYPE, CONTENT_LENGTH, AUTHORIZATION, USER_AGENT, LOCATION};
|
||
use client::ToParts;
|
||
let mut dd = client::DefaultDelegate;
|
||
let mut dlg: &mut dyn client::Delegate = match self._delegate {
|
||
Some(d) => d,
|
||
None => &mut dd
|
||
};
|
||
dlg.begin(client::MethodInfo { id: "keep.media.download",
|
||
http_method: hyper::Method::GET });
|
||
let mut params: Vec<(&str, String)> = Vec::with_capacity(3 + self._additional_params.len());
|
||
params.push(("name", self._name.to_string()));
|
||
if let Some(value) = self._mime_type {
|
||
params.push(("mimeType", value.to_string()));
|
||
}
|
||
for &field in ["name", "mimeType"].iter() {
|
||
if self._additional_params.contains_key(field) {
|
||
dlg.finished(false);
|
||
return Err(client::Error::FieldClash(field));
|
||
}
|
||
}
|
||
for (name, value) in self._additional_params.iter() {
|
||
params.push((&name, value.clone()));
|
||
}
|
||
|
||
let (json_field_missing, enable_resource_parsing) = {
|
||
let mut enable = true;
|
||
let mut field_present = true;
|
||
for &(name, ref value) in params.iter() {
|
||
if name == "alt" {
|
||
field_present = false;
|
||
if <String as AsRef<str>>::as_ref(&value) != "json" {
|
||
enable = false;
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
(field_present, enable)
|
||
};
|
||
if json_field_missing {
|
||
params.push(("alt", "json".to_string()));
|
||
}
|
||
|
||
let mut url = self.hub._base_url.clone() + "v1/{+name}";
|
||
if self._scopes.len() == 0 {
|
||
self._scopes.insert(Scope::Readonly.as_ref().to_string(), ());
|
||
}
|
||
|
||
for &(find_this, param_name) in [("{+name}", "name")].iter() {
|
||
let mut replace_with = String::new();
|
||
for &(name, ref value) in params.iter() {
|
||
if name == param_name {
|
||
replace_with = value.to_string();
|
||
break;
|
||
}
|
||
}
|
||
if find_this.as_bytes()[1] == '+' as u8 {
|
||
replace_with = percent_encode(replace_with.as_bytes(), DEFAULT_ENCODE_SET).to_string();
|
||
}
|
||
url = url.replace(find_this, &replace_with);
|
||
}
|
||
{
|
||
let mut indices_for_removal: Vec<usize> = Vec::with_capacity(1);
|
||
for param_name in ["name"].iter() {
|
||
if let Some(index) = params.iter().position(|t| &t.0 == param_name) {
|
||
indices_for_removal.push(index);
|
||
}
|
||
}
|
||
for &index in indices_for_removal.iter() {
|
||
params.remove(index);
|
||
}
|
||
}
|
||
|
||
let url = url::Url::parse_with_params(&url, params).unwrap();
|
||
|
||
|
||
|
||
loop {
|
||
let token = match self.hub.auth.token(&self._scopes.keys().collect::<Vec<_>>()[..]).await {
|
||
Ok(token) => token.clone(),
|
||
Err(err) => {
|
||
match dlg.token(&err) {
|
||
Some(token) => token,
|
||
None => {
|
||
dlg.finished(false);
|
||
return Err(client::Error::MissingToken(err))
|
||
}
|
||
}
|
||
}
|
||
};
|
||
let mut req_result = {
|
||
let client = &self.hub.client;
|
||
dlg.pre_request();
|
||
let mut req_builder = hyper::Request::builder().method(hyper::Method::GET).uri(url.clone().into_string())
|
||
.header(USER_AGENT, self.hub._user_agent.clone()) .header(AUTHORIZATION, format!("Bearer {}", token.as_str()));
|
||
|
||
|
||
let request = req_builder
|
||
.body(hyper::body::Body::empty());
|
||
|
||
client.request(request.unwrap()).await
|
||
|
||
};
|
||
|
||
match req_result {
|
||
Err(err) => {
|
||
if let client::Retry::After(d) = dlg.http_error(&err) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return Err(client::Error::HttpError(err))
|
||
}
|
||
Ok(mut res) => {
|
||
if !res.status().is_success() {
|
||
let res_body_string = client::get_body_as_string(res.body_mut()).await;
|
||
let (parts, _) = res.into_parts();
|
||
let body = hyper::Body::from(res_body_string.clone());
|
||
let restored_response = hyper::Response::from_parts(parts, body);
|
||
|
||
let server_response = json::from_str::<serde_json::Value>(&res_body_string).ok();
|
||
|
||
if let client::Retry::After(d) = dlg.http_failure(&restored_response, server_response.clone()) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
|
||
dlg.finished(false);
|
||
|
||
return match server_response {
|
||
Some(error_value) => Err(client::Error::BadRequest(error_value)),
|
||
None => Err(client::Error::Failure(restored_response)),
|
||
}
|
||
}
|
||
let result_value = if enable_resource_parsing {
|
||
let res_body_string = client::get_body_as_string(res.body_mut()).await;
|
||
|
||
match json::from_str(&res_body_string) {
|
||
Ok(decoded) => (res, decoded),
|
||
Err(err) => {
|
||
dlg.response_json_decode_error(&res_body_string, &err);
|
||
return Err(client::Error::JsonDecodeError(res_body_string, err));
|
||
}
|
||
}
|
||
} else { (res, Default::default()) };
|
||
|
||
dlg.finished(true);
|
||
return Ok(result_value)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
/// Required. The name of the attachment.
|
||
///
|
||
/// Sets the *name* path property to the given value.
|
||
///
|
||
/// Even though the property as already been set when instantiating this call,
|
||
/// we provide this method for API completeness.
|
||
pub fn name(mut self, new_value: &str) -> MediaDownloadCall<'a> {
|
||
self._name = new_value.to_string();
|
||
self
|
||
}
|
||
/// 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.
|
||
///
|
||
/// Sets the *mime type* query property to the given value.
|
||
pub fn mime_type(mut self, new_value: &str) -> MediaDownloadCall<'a> {
|
||
self._mime_type = Some(new_value.to_string());
|
||
self
|
||
}
|
||
/// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
|
||
/// while executing the actual API request.
|
||
///
|
||
/// It should be used to handle progress information, and to implement a certain level of resilience.
|
||
///
|
||
/// Sets the *delegate* property to the given value.
|
||
pub fn delegate(mut self, new_value: &'a mut dyn client::Delegate) -> MediaDownloadCall<'a> {
|
||
self._delegate = Some(new_value);
|
||
self
|
||
}
|
||
|
||
/// Set any additional parameter of the query string used in the request.
|
||
/// It should be used to set parameters which are not yet available through their own
|
||
/// setters.
|
||
///
|
||
/// Please note that this method must not be used to set any of the known parameters
|
||
/// which have their own setter method. If done anyway, the request will fail.
|
||
///
|
||
/// # Additional Parameters
|
||
///
|
||
/// * *$.xgafv* (query-string) - V1 error format.
|
||
/// * *access_token* (query-string) - OAuth access token.
|
||
/// * *alt* (query-string) - Data format for response.
|
||
/// * *callback* (query-string) - JSONP
|
||
/// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
|
||
/// * *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.
|
||
/// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
|
||
/// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
|
||
/// * *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.
|
||
/// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
|
||
/// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
|
||
pub fn param<T>(mut self, name: T, value: T) -> MediaDownloadCall<'a>
|
||
where T: AsRef<str> {
|
||
self._additional_params.insert(name.as_ref().to_string(), value.as_ref().to_string());
|
||
self
|
||
}
|
||
|
||
/// Identifies the authorization scope for the method you are building.
|
||
///
|
||
/// Use this method to actively specify which scope should be used, instead the default `Scope` variant
|
||
/// `Scope::Readonly`.
|
||
///
|
||
/// The `scope` will be added to a set of scopes. This is important as one can maintain access
|
||
/// tokens for more than one scope.
|
||
/// If `None` is specified, then all scopes will be removed and no default scope will be used either.
|
||
/// In that case, you have to specify your API-key using the `key` parameter (see the `param()`
|
||
/// function for details).
|
||
///
|
||
/// Usually there is more than one suitable scope to authorize an operation, some of which may
|
||
/// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
|
||
/// sufficient, a read-write scope will do as well.
|
||
pub fn add_scope<T, S>(mut self, scope: T) -> MediaDownloadCall<'a>
|
||
where T: Into<Option<S>>,
|
||
S: AsRef<str> {
|
||
match scope.into() {
|
||
Some(scope) => self._scopes.insert(scope.as_ref().to_string(), ()),
|
||
None => None,
|
||
};
|
||
self
|
||
}
|
||
}
|
||
|
||
|
||
/// 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.
|
||
///
|
||
/// A builder for the *permissions.batchCreate* method supported by a *note* resource.
|
||
/// It is not used directly, but through a `NoteMethods` instance.
|
||
///
|
||
/// # Example
|
||
///
|
||
/// Instantiate a resource method builder
|
||
///
|
||
/// ```test_harness,no_run
|
||
/// # extern crate hyper;
|
||
/// # extern crate hyper_rustls;
|
||
/// # extern crate google_keep1 as keep1;
|
||
/// use keep1::api::BatchCreatePermissionsRequest;
|
||
/// # async fn dox() {
|
||
/// # use std::default::Default;
|
||
/// # use keep1::{Keep, oauth2, hyper, hyper_rustls};
|
||
///
|
||
/// # let secret: oauth2::ApplicationSecret = Default::default();
|
||
/// # let auth = oauth2::InstalledFlowAuthenticator::builder(
|
||
/// # secret,
|
||
/// # oauth2::InstalledFlowReturnMethod::HTTPRedirect,
|
||
/// # ).build().await.unwrap();
|
||
/// # let mut hub = Keep::new(hyper::Client::builder().build(hyper_rustls::HttpsConnector::with_native_roots().https_or_http().enable_http1().enable_http2().build()), auth);
|
||
/// // As the method needs a request, you would usually fill it with the desired information
|
||
/// // into the respective structure. Some of the parts shown here might not be applicable !
|
||
/// // Values shown here are possibly random and not representative !
|
||
/// let mut req = BatchCreatePermissionsRequest::default();
|
||
///
|
||
/// // You can configure optional parameters by calling the respective setters at will, and
|
||
/// // execute the final call using `doit()`.
|
||
/// // Values shown here are possibly random and not representative !
|
||
/// let result = hub.notes().permissions_batch_create(req, "parent")
|
||
/// .doit().await;
|
||
/// # }
|
||
/// ```
|
||
pub struct NotePermissionBatchCreateCall<'a>
|
||
where {
|
||
|
||
hub: &'a Keep<>,
|
||
_request: BatchCreatePermissionsRequest,
|
||
_parent: String,
|
||
_delegate: Option<&'a mut dyn client::Delegate>,
|
||
_additional_params: HashMap<String, String>,
|
||
_scopes: BTreeMap<String, ()>
|
||
}
|
||
|
||
impl<'a> client::CallBuilder for NotePermissionBatchCreateCall<'a> {}
|
||
|
||
impl<'a> NotePermissionBatchCreateCall<'a> {
|
||
|
||
|
||
/// Perform the operation you have build so far.
|
||
pub async fn doit(mut self) -> client::Result<(hyper::Response<hyper::body::Body>, BatchCreatePermissionsResponse)> {
|
||
use url::percent_encoding::{percent_encode, DEFAULT_ENCODE_SET};
|
||
use std::io::{Read, Seek};
|
||
use hyper::header::{CONTENT_TYPE, CONTENT_LENGTH, AUTHORIZATION, USER_AGENT, LOCATION};
|
||
use client::ToParts;
|
||
let mut dd = client::DefaultDelegate;
|
||
let mut dlg: &mut dyn client::Delegate = match self._delegate {
|
||
Some(d) => d,
|
||
None => &mut dd
|
||
};
|
||
dlg.begin(client::MethodInfo { id: "keep.notes.permissions.batchCreate",
|
||
http_method: hyper::Method::POST });
|
||
let mut params: Vec<(&str, String)> = Vec::with_capacity(4 + self._additional_params.len());
|
||
params.push(("parent", self._parent.to_string()));
|
||
for &field in ["alt", "parent"].iter() {
|
||
if self._additional_params.contains_key(field) {
|
||
dlg.finished(false);
|
||
return Err(client::Error::FieldClash(field));
|
||
}
|
||
}
|
||
for (name, value) in self._additional_params.iter() {
|
||
params.push((&name, value.clone()));
|
||
}
|
||
|
||
params.push(("alt", "json".to_string()));
|
||
|
||
let mut url = self.hub._base_url.clone() + "v1/{+parent}/permissions:batchCreate";
|
||
if self._scopes.len() == 0 {
|
||
self._scopes.insert(Scope::Full.as_ref().to_string(), ());
|
||
}
|
||
|
||
for &(find_this, param_name) in [("{+parent}", "parent")].iter() {
|
||
let mut replace_with = String::new();
|
||
for &(name, ref value) in params.iter() {
|
||
if name == param_name {
|
||
replace_with = value.to_string();
|
||
break;
|
||
}
|
||
}
|
||
if find_this.as_bytes()[1] == '+' as u8 {
|
||
replace_with = percent_encode(replace_with.as_bytes(), DEFAULT_ENCODE_SET).to_string();
|
||
}
|
||
url = url.replace(find_this, &replace_with);
|
||
}
|
||
{
|
||
let mut indices_for_removal: Vec<usize> = Vec::with_capacity(1);
|
||
for param_name in ["parent"].iter() {
|
||
if let Some(index) = params.iter().position(|t| &t.0 == param_name) {
|
||
indices_for_removal.push(index);
|
||
}
|
||
}
|
||
for &index in indices_for_removal.iter() {
|
||
params.remove(index);
|
||
}
|
||
}
|
||
|
||
let url = url::Url::parse_with_params(&url, params).unwrap();
|
||
|
||
let mut json_mime_type: mime::Mime = "application/json".parse().unwrap();
|
||
let mut request_value_reader =
|
||
{
|
||
let mut value = json::value::to_value(&self._request).expect("serde to work");
|
||
client::remove_json_null_values(&mut value);
|
||
let mut dst = io::Cursor::new(Vec::with_capacity(128));
|
||
json::to_writer(&mut dst, &value).unwrap();
|
||
dst
|
||
};
|
||
let request_size = request_value_reader.seek(io::SeekFrom::End(0)).unwrap();
|
||
request_value_reader.seek(io::SeekFrom::Start(0)).unwrap();
|
||
|
||
|
||
loop {
|
||
let token = match self.hub.auth.token(&self._scopes.keys().collect::<Vec<_>>()[..]).await {
|
||
Ok(token) => token.clone(),
|
||
Err(err) => {
|
||
match dlg.token(&err) {
|
||
Some(token) => token,
|
||
None => {
|
||
dlg.finished(false);
|
||
return Err(client::Error::MissingToken(err))
|
||
}
|
||
}
|
||
}
|
||
};
|
||
request_value_reader.seek(io::SeekFrom::Start(0)).unwrap();
|
||
let mut req_result = {
|
||
let client = &self.hub.client;
|
||
dlg.pre_request();
|
||
let mut req_builder = hyper::Request::builder().method(hyper::Method::POST).uri(url.clone().into_string())
|
||
.header(USER_AGENT, self.hub._user_agent.clone()) .header(AUTHORIZATION, format!("Bearer {}", token.as_str()));
|
||
|
||
|
||
let request = req_builder
|
||
.header(CONTENT_TYPE, format!("{}", json_mime_type.to_string()))
|
||
.header(CONTENT_LENGTH, request_size as u64)
|
||
.body(hyper::body::Body::from(request_value_reader.get_ref().clone()));
|
||
|
||
client.request(request.unwrap()).await
|
||
|
||
};
|
||
|
||
match req_result {
|
||
Err(err) => {
|
||
if let client::Retry::After(d) = dlg.http_error(&err) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return Err(client::Error::HttpError(err))
|
||
}
|
||
Ok(mut res) => {
|
||
if !res.status().is_success() {
|
||
let res_body_string = client::get_body_as_string(res.body_mut()).await;
|
||
let (parts, _) = res.into_parts();
|
||
let body = hyper::Body::from(res_body_string.clone());
|
||
let restored_response = hyper::Response::from_parts(parts, body);
|
||
|
||
let server_response = json::from_str::<serde_json::Value>(&res_body_string).ok();
|
||
|
||
if let client::Retry::After(d) = dlg.http_failure(&restored_response, server_response.clone()) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
|
||
dlg.finished(false);
|
||
|
||
return match server_response {
|
||
Some(error_value) => Err(client::Error::BadRequest(error_value)),
|
||
None => Err(client::Error::Failure(restored_response)),
|
||
}
|
||
}
|
||
let result_value = {
|
||
let res_body_string = client::get_body_as_string(res.body_mut()).await;
|
||
|
||
match json::from_str(&res_body_string) {
|
||
Ok(decoded) => (res, decoded),
|
||
Err(err) => {
|
||
dlg.response_json_decode_error(&res_body_string, &err);
|
||
return Err(client::Error::JsonDecodeError(res_body_string, err));
|
||
}
|
||
}
|
||
};
|
||
|
||
dlg.finished(true);
|
||
return Ok(result_value)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
///
|
||
/// Sets the *request* property to the given value.
|
||
///
|
||
/// Even though the property as already been set when instantiating this call,
|
||
/// we provide this method for API completeness.
|
||
pub fn request(mut self, new_value: BatchCreatePermissionsRequest) -> NotePermissionBatchCreateCall<'a> {
|
||
self._request = new_value;
|
||
self
|
||
}
|
||
/// 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.
|
||
///
|
||
/// Sets the *parent* path property to the given value.
|
||
///
|
||
/// Even though the property as already been set when instantiating this call,
|
||
/// we provide this method for API completeness.
|
||
pub fn parent(mut self, new_value: &str) -> NotePermissionBatchCreateCall<'a> {
|
||
self._parent = new_value.to_string();
|
||
self
|
||
}
|
||
/// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
|
||
/// while executing the actual API request.
|
||
///
|
||
/// It should be used to handle progress information, and to implement a certain level of resilience.
|
||
///
|
||
/// Sets the *delegate* property to the given value.
|
||
pub fn delegate(mut self, new_value: &'a mut dyn client::Delegate) -> NotePermissionBatchCreateCall<'a> {
|
||
self._delegate = Some(new_value);
|
||
self
|
||
}
|
||
|
||
/// Set any additional parameter of the query string used in the request.
|
||
/// It should be used to set parameters which are not yet available through their own
|
||
/// setters.
|
||
///
|
||
/// Please note that this method must not be used to set any of the known parameters
|
||
/// which have their own setter method. If done anyway, the request will fail.
|
||
///
|
||
/// # Additional Parameters
|
||
///
|
||
/// * *$.xgafv* (query-string) - V1 error format.
|
||
/// * *access_token* (query-string) - OAuth access token.
|
||
/// * *alt* (query-string) - Data format for response.
|
||
/// * *callback* (query-string) - JSONP
|
||
/// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
|
||
/// * *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.
|
||
/// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
|
||
/// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
|
||
/// * *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.
|
||
/// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
|
||
/// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
|
||
pub fn param<T>(mut self, name: T, value: T) -> NotePermissionBatchCreateCall<'a>
|
||
where T: AsRef<str> {
|
||
self._additional_params.insert(name.as_ref().to_string(), value.as_ref().to_string());
|
||
self
|
||
}
|
||
|
||
/// Identifies the authorization scope for the method you are building.
|
||
///
|
||
/// Use this method to actively specify which scope should be used, instead the default `Scope` variant
|
||
/// `Scope::Full`.
|
||
///
|
||
/// The `scope` will be added to a set of scopes. This is important as one can maintain access
|
||
/// tokens for more than one scope.
|
||
/// If `None` is specified, then all scopes will be removed and no default scope will be used either.
|
||
/// In that case, you have to specify your API-key using the `key` parameter (see the `param()`
|
||
/// function for details).
|
||
///
|
||
/// Usually there is more than one suitable scope to authorize an operation, some of which may
|
||
/// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
|
||
/// sufficient, a read-write scope will do as well.
|
||
pub fn add_scope<T, S>(mut self, scope: T) -> NotePermissionBatchCreateCall<'a>
|
||
where T: Into<Option<S>>,
|
||
S: AsRef<str> {
|
||
match scope.into() {
|
||
Some(scope) => self._scopes.insert(scope.as_ref().to_string(), ()),
|
||
None => None,
|
||
};
|
||
self
|
||
}
|
||
}
|
||
|
||
|
||
/// 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.
|
||
///
|
||
/// A builder for the *permissions.batchDelete* method supported by a *note* resource.
|
||
/// It is not used directly, but through a `NoteMethods` instance.
|
||
///
|
||
/// # Example
|
||
///
|
||
/// Instantiate a resource method builder
|
||
///
|
||
/// ```test_harness,no_run
|
||
/// # extern crate hyper;
|
||
/// # extern crate hyper_rustls;
|
||
/// # extern crate google_keep1 as keep1;
|
||
/// use keep1::api::BatchDeletePermissionsRequest;
|
||
/// # async fn dox() {
|
||
/// # use std::default::Default;
|
||
/// # use keep1::{Keep, oauth2, hyper, hyper_rustls};
|
||
///
|
||
/// # let secret: oauth2::ApplicationSecret = Default::default();
|
||
/// # let auth = oauth2::InstalledFlowAuthenticator::builder(
|
||
/// # secret,
|
||
/// # oauth2::InstalledFlowReturnMethod::HTTPRedirect,
|
||
/// # ).build().await.unwrap();
|
||
/// # let mut hub = Keep::new(hyper::Client::builder().build(hyper_rustls::HttpsConnector::with_native_roots().https_or_http().enable_http1().enable_http2().build()), auth);
|
||
/// // As the method needs a request, you would usually fill it with the desired information
|
||
/// // into the respective structure. Some of the parts shown here might not be applicable !
|
||
/// // Values shown here are possibly random and not representative !
|
||
/// let mut req = BatchDeletePermissionsRequest::default();
|
||
///
|
||
/// // You can configure optional parameters by calling the respective setters at will, and
|
||
/// // execute the final call using `doit()`.
|
||
/// // Values shown here are possibly random and not representative !
|
||
/// let result = hub.notes().permissions_batch_delete(req, "parent")
|
||
/// .doit().await;
|
||
/// # }
|
||
/// ```
|
||
pub struct NotePermissionBatchDeleteCall<'a>
|
||
where {
|
||
|
||
hub: &'a Keep<>,
|
||
_request: BatchDeletePermissionsRequest,
|
||
_parent: String,
|
||
_delegate: Option<&'a mut dyn client::Delegate>,
|
||
_additional_params: HashMap<String, String>,
|
||
_scopes: BTreeMap<String, ()>
|
||
}
|
||
|
||
impl<'a> client::CallBuilder for NotePermissionBatchDeleteCall<'a> {}
|
||
|
||
impl<'a> NotePermissionBatchDeleteCall<'a> {
|
||
|
||
|
||
/// Perform the operation you have build so far.
|
||
pub async fn doit(mut self) -> client::Result<(hyper::Response<hyper::body::Body>, Empty)> {
|
||
use url::percent_encoding::{percent_encode, DEFAULT_ENCODE_SET};
|
||
use std::io::{Read, Seek};
|
||
use hyper::header::{CONTENT_TYPE, CONTENT_LENGTH, AUTHORIZATION, USER_AGENT, LOCATION};
|
||
use client::ToParts;
|
||
let mut dd = client::DefaultDelegate;
|
||
let mut dlg: &mut dyn client::Delegate = match self._delegate {
|
||
Some(d) => d,
|
||
None => &mut dd
|
||
};
|
||
dlg.begin(client::MethodInfo { id: "keep.notes.permissions.batchDelete",
|
||
http_method: hyper::Method::POST });
|
||
let mut params: Vec<(&str, String)> = Vec::with_capacity(4 + self._additional_params.len());
|
||
params.push(("parent", self._parent.to_string()));
|
||
for &field in ["alt", "parent"].iter() {
|
||
if self._additional_params.contains_key(field) {
|
||
dlg.finished(false);
|
||
return Err(client::Error::FieldClash(field));
|
||
}
|
||
}
|
||
for (name, value) in self._additional_params.iter() {
|
||
params.push((&name, value.clone()));
|
||
}
|
||
|
||
params.push(("alt", "json".to_string()));
|
||
|
||
let mut url = self.hub._base_url.clone() + "v1/{+parent}/permissions:batchDelete";
|
||
if self._scopes.len() == 0 {
|
||
self._scopes.insert(Scope::Full.as_ref().to_string(), ());
|
||
}
|
||
|
||
for &(find_this, param_name) in [("{+parent}", "parent")].iter() {
|
||
let mut replace_with = String::new();
|
||
for &(name, ref value) in params.iter() {
|
||
if name == param_name {
|
||
replace_with = value.to_string();
|
||
break;
|
||
}
|
||
}
|
||
if find_this.as_bytes()[1] == '+' as u8 {
|
||
replace_with = percent_encode(replace_with.as_bytes(), DEFAULT_ENCODE_SET).to_string();
|
||
}
|
||
url = url.replace(find_this, &replace_with);
|
||
}
|
||
{
|
||
let mut indices_for_removal: Vec<usize> = Vec::with_capacity(1);
|
||
for param_name in ["parent"].iter() {
|
||
if let Some(index) = params.iter().position(|t| &t.0 == param_name) {
|
||
indices_for_removal.push(index);
|
||
}
|
||
}
|
||
for &index in indices_for_removal.iter() {
|
||
params.remove(index);
|
||
}
|
||
}
|
||
|
||
let url = url::Url::parse_with_params(&url, params).unwrap();
|
||
|
||
let mut json_mime_type: mime::Mime = "application/json".parse().unwrap();
|
||
let mut request_value_reader =
|
||
{
|
||
let mut value = json::value::to_value(&self._request).expect("serde to work");
|
||
client::remove_json_null_values(&mut value);
|
||
let mut dst = io::Cursor::new(Vec::with_capacity(128));
|
||
json::to_writer(&mut dst, &value).unwrap();
|
||
dst
|
||
};
|
||
let request_size = request_value_reader.seek(io::SeekFrom::End(0)).unwrap();
|
||
request_value_reader.seek(io::SeekFrom::Start(0)).unwrap();
|
||
|
||
|
||
loop {
|
||
let token = match self.hub.auth.token(&self._scopes.keys().collect::<Vec<_>>()[..]).await {
|
||
Ok(token) => token.clone(),
|
||
Err(err) => {
|
||
match dlg.token(&err) {
|
||
Some(token) => token,
|
||
None => {
|
||
dlg.finished(false);
|
||
return Err(client::Error::MissingToken(err))
|
||
}
|
||
}
|
||
}
|
||
};
|
||
request_value_reader.seek(io::SeekFrom::Start(0)).unwrap();
|
||
let mut req_result = {
|
||
let client = &self.hub.client;
|
||
dlg.pre_request();
|
||
let mut req_builder = hyper::Request::builder().method(hyper::Method::POST).uri(url.clone().into_string())
|
||
.header(USER_AGENT, self.hub._user_agent.clone()) .header(AUTHORIZATION, format!("Bearer {}", token.as_str()));
|
||
|
||
|
||
let request = req_builder
|
||
.header(CONTENT_TYPE, format!("{}", json_mime_type.to_string()))
|
||
.header(CONTENT_LENGTH, request_size as u64)
|
||
.body(hyper::body::Body::from(request_value_reader.get_ref().clone()));
|
||
|
||
client.request(request.unwrap()).await
|
||
|
||
};
|
||
|
||
match req_result {
|
||
Err(err) => {
|
||
if let client::Retry::After(d) = dlg.http_error(&err) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return Err(client::Error::HttpError(err))
|
||
}
|
||
Ok(mut res) => {
|
||
if !res.status().is_success() {
|
||
let res_body_string = client::get_body_as_string(res.body_mut()).await;
|
||
let (parts, _) = res.into_parts();
|
||
let body = hyper::Body::from(res_body_string.clone());
|
||
let restored_response = hyper::Response::from_parts(parts, body);
|
||
|
||
let server_response = json::from_str::<serde_json::Value>(&res_body_string).ok();
|
||
|
||
if let client::Retry::After(d) = dlg.http_failure(&restored_response, server_response.clone()) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
|
||
dlg.finished(false);
|
||
|
||
return match server_response {
|
||
Some(error_value) => Err(client::Error::BadRequest(error_value)),
|
||
None => Err(client::Error::Failure(restored_response)),
|
||
}
|
||
}
|
||
let result_value = {
|
||
let res_body_string = client::get_body_as_string(res.body_mut()).await;
|
||
|
||
match json::from_str(&res_body_string) {
|
||
Ok(decoded) => (res, decoded),
|
||
Err(err) => {
|
||
dlg.response_json_decode_error(&res_body_string, &err);
|
||
return Err(client::Error::JsonDecodeError(res_body_string, err));
|
||
}
|
||
}
|
||
};
|
||
|
||
dlg.finished(true);
|
||
return Ok(result_value)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
///
|
||
/// Sets the *request* property to the given value.
|
||
///
|
||
/// Even though the property as already been set when instantiating this call,
|
||
/// we provide this method for API completeness.
|
||
pub fn request(mut self, new_value: BatchDeletePermissionsRequest) -> NotePermissionBatchDeleteCall<'a> {
|
||
self._request = new_value;
|
||
self
|
||
}
|
||
/// 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.
|
||
///
|
||
/// Sets the *parent* path property to the given value.
|
||
///
|
||
/// Even though the property as already been set when instantiating this call,
|
||
/// we provide this method for API completeness.
|
||
pub fn parent(mut self, new_value: &str) -> NotePermissionBatchDeleteCall<'a> {
|
||
self._parent = new_value.to_string();
|
||
self
|
||
}
|
||
/// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
|
||
/// while executing the actual API request.
|
||
///
|
||
/// It should be used to handle progress information, and to implement a certain level of resilience.
|
||
///
|
||
/// Sets the *delegate* property to the given value.
|
||
pub fn delegate(mut self, new_value: &'a mut dyn client::Delegate) -> NotePermissionBatchDeleteCall<'a> {
|
||
self._delegate = Some(new_value);
|
||
self
|
||
}
|
||
|
||
/// Set any additional parameter of the query string used in the request.
|
||
/// It should be used to set parameters which are not yet available through their own
|
||
/// setters.
|
||
///
|
||
/// Please note that this method must not be used to set any of the known parameters
|
||
/// which have their own setter method. If done anyway, the request will fail.
|
||
///
|
||
/// # Additional Parameters
|
||
///
|
||
/// * *$.xgafv* (query-string) - V1 error format.
|
||
/// * *access_token* (query-string) - OAuth access token.
|
||
/// * *alt* (query-string) - Data format for response.
|
||
/// * *callback* (query-string) - JSONP
|
||
/// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
|
||
/// * *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.
|
||
/// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
|
||
/// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
|
||
/// * *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.
|
||
/// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
|
||
/// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
|
||
pub fn param<T>(mut self, name: T, value: T) -> NotePermissionBatchDeleteCall<'a>
|
||
where T: AsRef<str> {
|
||
self._additional_params.insert(name.as_ref().to_string(), value.as_ref().to_string());
|
||
self
|
||
}
|
||
|
||
/// Identifies the authorization scope for the method you are building.
|
||
///
|
||
/// Use this method to actively specify which scope should be used, instead the default `Scope` variant
|
||
/// `Scope::Full`.
|
||
///
|
||
/// The `scope` will be added to a set of scopes. This is important as one can maintain access
|
||
/// tokens for more than one scope.
|
||
/// If `None` is specified, then all scopes will be removed and no default scope will be used either.
|
||
/// In that case, you have to specify your API-key using the `key` parameter (see the `param()`
|
||
/// function for details).
|
||
///
|
||
/// Usually there is more than one suitable scope to authorize an operation, some of which may
|
||
/// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
|
||
/// sufficient, a read-write scope will do as well.
|
||
pub fn add_scope<T, S>(mut self, scope: T) -> NotePermissionBatchDeleteCall<'a>
|
||
where T: Into<Option<S>>,
|
||
S: AsRef<str> {
|
||
match scope.into() {
|
||
Some(scope) => self._scopes.insert(scope.as_ref().to_string(), ()),
|
||
None => None,
|
||
};
|
||
self
|
||
}
|
||
}
|
||
|
||
|
||
/// Creates a new note.
|
||
///
|
||
/// A builder for the *create* method supported by a *note* resource.
|
||
/// It is not used directly, but through a `NoteMethods` instance.
|
||
///
|
||
/// # Example
|
||
///
|
||
/// Instantiate a resource method builder
|
||
///
|
||
/// ```test_harness,no_run
|
||
/// # extern crate hyper;
|
||
/// # extern crate hyper_rustls;
|
||
/// # extern crate google_keep1 as keep1;
|
||
/// use keep1::api::Note;
|
||
/// # async fn dox() {
|
||
/// # use std::default::Default;
|
||
/// # use keep1::{Keep, oauth2, hyper, hyper_rustls};
|
||
///
|
||
/// # let secret: oauth2::ApplicationSecret = Default::default();
|
||
/// # let auth = oauth2::InstalledFlowAuthenticator::builder(
|
||
/// # secret,
|
||
/// # oauth2::InstalledFlowReturnMethod::HTTPRedirect,
|
||
/// # ).build().await.unwrap();
|
||
/// # let mut hub = Keep::new(hyper::Client::builder().build(hyper_rustls::HttpsConnector::with_native_roots().https_or_http().enable_http1().enable_http2().build()), auth);
|
||
/// // As the method needs a request, you would usually fill it with the desired information
|
||
/// // into the respective structure. Some of the parts shown here might not be applicable !
|
||
/// // Values shown here are possibly random and not representative !
|
||
/// let mut req = Note::default();
|
||
///
|
||
/// // You can configure optional parameters by calling the respective setters at will, and
|
||
/// // execute the final call using `doit()`.
|
||
/// // Values shown here are possibly random and not representative !
|
||
/// let result = hub.notes().create(req)
|
||
/// .doit().await;
|
||
/// # }
|
||
/// ```
|
||
pub struct NoteCreateCall<'a>
|
||
where {
|
||
|
||
hub: &'a Keep<>,
|
||
_request: Note,
|
||
_delegate: Option<&'a mut dyn client::Delegate>,
|
||
_additional_params: HashMap<String, String>,
|
||
_scopes: BTreeMap<String, ()>
|
||
}
|
||
|
||
impl<'a> client::CallBuilder for NoteCreateCall<'a> {}
|
||
|
||
impl<'a> NoteCreateCall<'a> {
|
||
|
||
|
||
/// Perform the operation you have build so far.
|
||
pub async fn doit(mut self) -> client::Result<(hyper::Response<hyper::body::Body>, Note)> {
|
||
use std::io::{Read, Seek};
|
||
use hyper::header::{CONTENT_TYPE, CONTENT_LENGTH, AUTHORIZATION, USER_AGENT, LOCATION};
|
||
use client::ToParts;
|
||
let mut dd = client::DefaultDelegate;
|
||
let mut dlg: &mut dyn client::Delegate = match self._delegate {
|
||
Some(d) => d,
|
||
None => &mut dd
|
||
};
|
||
dlg.begin(client::MethodInfo { id: "keep.notes.create",
|
||
http_method: hyper::Method::POST });
|
||
let mut params: Vec<(&str, String)> = Vec::with_capacity(3 + self._additional_params.len());
|
||
for &field in ["alt"].iter() {
|
||
if self._additional_params.contains_key(field) {
|
||
dlg.finished(false);
|
||
return Err(client::Error::FieldClash(field));
|
||
}
|
||
}
|
||
for (name, value) in self._additional_params.iter() {
|
||
params.push((&name, value.clone()));
|
||
}
|
||
|
||
params.push(("alt", "json".to_string()));
|
||
|
||
let mut url = self.hub._base_url.clone() + "v1/notes";
|
||
if self._scopes.len() == 0 {
|
||
self._scopes.insert(Scope::Full.as_ref().to_string(), ());
|
||
}
|
||
|
||
|
||
let url = url::Url::parse_with_params(&url, params).unwrap();
|
||
|
||
let mut json_mime_type: mime::Mime = "application/json".parse().unwrap();
|
||
let mut request_value_reader =
|
||
{
|
||
let mut value = json::value::to_value(&self._request).expect("serde to work");
|
||
client::remove_json_null_values(&mut value);
|
||
let mut dst = io::Cursor::new(Vec::with_capacity(128));
|
||
json::to_writer(&mut dst, &value).unwrap();
|
||
dst
|
||
};
|
||
let request_size = request_value_reader.seek(io::SeekFrom::End(0)).unwrap();
|
||
request_value_reader.seek(io::SeekFrom::Start(0)).unwrap();
|
||
|
||
|
||
loop {
|
||
let token = match self.hub.auth.token(&self._scopes.keys().collect::<Vec<_>>()[..]).await {
|
||
Ok(token) => token.clone(),
|
||
Err(err) => {
|
||
match dlg.token(&err) {
|
||
Some(token) => token,
|
||
None => {
|
||
dlg.finished(false);
|
||
return Err(client::Error::MissingToken(err))
|
||
}
|
||
}
|
||
}
|
||
};
|
||
request_value_reader.seek(io::SeekFrom::Start(0)).unwrap();
|
||
let mut req_result = {
|
||
let client = &self.hub.client;
|
||
dlg.pre_request();
|
||
let mut req_builder = hyper::Request::builder().method(hyper::Method::POST).uri(url.clone().into_string())
|
||
.header(USER_AGENT, self.hub._user_agent.clone()) .header(AUTHORIZATION, format!("Bearer {}", token.as_str()));
|
||
|
||
|
||
let request = req_builder
|
||
.header(CONTENT_TYPE, format!("{}", json_mime_type.to_string()))
|
||
.header(CONTENT_LENGTH, request_size as u64)
|
||
.body(hyper::body::Body::from(request_value_reader.get_ref().clone()));
|
||
|
||
client.request(request.unwrap()).await
|
||
|
||
};
|
||
|
||
match req_result {
|
||
Err(err) => {
|
||
if let client::Retry::After(d) = dlg.http_error(&err) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return Err(client::Error::HttpError(err))
|
||
}
|
||
Ok(mut res) => {
|
||
if !res.status().is_success() {
|
||
let res_body_string = client::get_body_as_string(res.body_mut()).await;
|
||
let (parts, _) = res.into_parts();
|
||
let body = hyper::Body::from(res_body_string.clone());
|
||
let restored_response = hyper::Response::from_parts(parts, body);
|
||
|
||
let server_response = json::from_str::<serde_json::Value>(&res_body_string).ok();
|
||
|
||
if let client::Retry::After(d) = dlg.http_failure(&restored_response, server_response.clone()) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
|
||
dlg.finished(false);
|
||
|
||
return match server_response {
|
||
Some(error_value) => Err(client::Error::BadRequest(error_value)),
|
||
None => Err(client::Error::Failure(restored_response)),
|
||
}
|
||
}
|
||
let result_value = {
|
||
let res_body_string = client::get_body_as_string(res.body_mut()).await;
|
||
|
||
match json::from_str(&res_body_string) {
|
||
Ok(decoded) => (res, decoded),
|
||
Err(err) => {
|
||
dlg.response_json_decode_error(&res_body_string, &err);
|
||
return Err(client::Error::JsonDecodeError(res_body_string, err));
|
||
}
|
||
}
|
||
};
|
||
|
||
dlg.finished(true);
|
||
return Ok(result_value)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
///
|
||
/// Sets the *request* property to the given value.
|
||
///
|
||
/// Even though the property as already been set when instantiating this call,
|
||
/// we provide this method for API completeness.
|
||
pub fn request(mut self, new_value: Note) -> NoteCreateCall<'a> {
|
||
self._request = new_value;
|
||
self
|
||
}
|
||
/// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
|
||
/// while executing the actual API request.
|
||
///
|
||
/// It should be used to handle progress information, and to implement a certain level of resilience.
|
||
///
|
||
/// Sets the *delegate* property to the given value.
|
||
pub fn delegate(mut self, new_value: &'a mut dyn client::Delegate) -> NoteCreateCall<'a> {
|
||
self._delegate = Some(new_value);
|
||
self
|
||
}
|
||
|
||
/// Set any additional parameter of the query string used in the request.
|
||
/// It should be used to set parameters which are not yet available through their own
|
||
/// setters.
|
||
///
|
||
/// Please note that this method must not be used to set any of the known parameters
|
||
/// which have their own setter method. If done anyway, the request will fail.
|
||
///
|
||
/// # Additional Parameters
|
||
///
|
||
/// * *$.xgafv* (query-string) - V1 error format.
|
||
/// * *access_token* (query-string) - OAuth access token.
|
||
/// * *alt* (query-string) - Data format for response.
|
||
/// * *callback* (query-string) - JSONP
|
||
/// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
|
||
/// * *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.
|
||
/// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
|
||
/// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
|
||
/// * *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.
|
||
/// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
|
||
/// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
|
||
pub fn param<T>(mut self, name: T, value: T) -> NoteCreateCall<'a>
|
||
where T: AsRef<str> {
|
||
self._additional_params.insert(name.as_ref().to_string(), value.as_ref().to_string());
|
||
self
|
||
}
|
||
|
||
/// Identifies the authorization scope for the method you are building.
|
||
///
|
||
/// Use this method to actively specify which scope should be used, instead the default `Scope` variant
|
||
/// `Scope::Full`.
|
||
///
|
||
/// The `scope` will be added to a set of scopes. This is important as one can maintain access
|
||
/// tokens for more than one scope.
|
||
/// If `None` is specified, then all scopes will be removed and no default scope will be used either.
|
||
/// In that case, you have to specify your API-key using the `key` parameter (see the `param()`
|
||
/// function for details).
|
||
///
|
||
/// Usually there is more than one suitable scope to authorize an operation, some of which may
|
||
/// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
|
||
/// sufficient, a read-write scope will do as well.
|
||
pub fn add_scope<T, S>(mut self, scope: T) -> NoteCreateCall<'a>
|
||
where T: Into<Option<S>>,
|
||
S: AsRef<str> {
|
||
match scope.into() {
|
||
Some(scope) => self._scopes.insert(scope.as_ref().to_string(), ()),
|
||
None => None,
|
||
};
|
||
self
|
||
}
|
||
}
|
||
|
||
|
||
/// 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.
|
||
///
|
||
/// A builder for the *delete* method supported by a *note* resource.
|
||
/// It is not used directly, but through a `NoteMethods` instance.
|
||
///
|
||
/// # Example
|
||
///
|
||
/// Instantiate a resource method builder
|
||
///
|
||
/// ```test_harness,no_run
|
||
/// # extern crate hyper;
|
||
/// # extern crate hyper_rustls;
|
||
/// # extern crate google_keep1 as keep1;
|
||
/// # async fn dox() {
|
||
/// # use std::default::Default;
|
||
/// # use keep1::{Keep, oauth2, hyper, hyper_rustls};
|
||
///
|
||
/// # let secret: oauth2::ApplicationSecret = Default::default();
|
||
/// # let auth = oauth2::InstalledFlowAuthenticator::builder(
|
||
/// # secret,
|
||
/// # oauth2::InstalledFlowReturnMethod::HTTPRedirect,
|
||
/// # ).build().await.unwrap();
|
||
/// # let mut hub = Keep::new(hyper::Client::builder().build(hyper_rustls::HttpsConnector::with_native_roots().https_or_http().enable_http1().enable_http2().build()), auth);
|
||
/// // You can configure optional parameters by calling the respective setters at will, and
|
||
/// // execute the final call using `doit()`.
|
||
/// // Values shown here are possibly random and not representative !
|
||
/// let result = hub.notes().delete("name")
|
||
/// .doit().await;
|
||
/// # }
|
||
/// ```
|
||
pub struct NoteDeleteCall<'a>
|
||
where {
|
||
|
||
hub: &'a Keep<>,
|
||
_name: String,
|
||
_delegate: Option<&'a mut dyn client::Delegate>,
|
||
_additional_params: HashMap<String, String>,
|
||
_scopes: BTreeMap<String, ()>
|
||
}
|
||
|
||
impl<'a> client::CallBuilder for NoteDeleteCall<'a> {}
|
||
|
||
impl<'a> NoteDeleteCall<'a> {
|
||
|
||
|
||
/// Perform the operation you have build so far.
|
||
pub async fn doit(mut self) -> client::Result<(hyper::Response<hyper::body::Body>, Empty)> {
|
||
use url::percent_encoding::{percent_encode, DEFAULT_ENCODE_SET};
|
||
use std::io::{Read, Seek};
|
||
use hyper::header::{CONTENT_TYPE, CONTENT_LENGTH, AUTHORIZATION, USER_AGENT, LOCATION};
|
||
use client::ToParts;
|
||
let mut dd = client::DefaultDelegate;
|
||
let mut dlg: &mut dyn client::Delegate = match self._delegate {
|
||
Some(d) => d,
|
||
None => &mut dd
|
||
};
|
||
dlg.begin(client::MethodInfo { id: "keep.notes.delete",
|
||
http_method: hyper::Method::DELETE });
|
||
let mut params: Vec<(&str, String)> = Vec::with_capacity(3 + self._additional_params.len());
|
||
params.push(("name", self._name.to_string()));
|
||
for &field in ["alt", "name"].iter() {
|
||
if self._additional_params.contains_key(field) {
|
||
dlg.finished(false);
|
||
return Err(client::Error::FieldClash(field));
|
||
}
|
||
}
|
||
for (name, value) in self._additional_params.iter() {
|
||
params.push((&name, value.clone()));
|
||
}
|
||
|
||
params.push(("alt", "json".to_string()));
|
||
|
||
let mut url = self.hub._base_url.clone() + "v1/{+name}";
|
||
if self._scopes.len() == 0 {
|
||
self._scopes.insert(Scope::Full.as_ref().to_string(), ());
|
||
}
|
||
|
||
for &(find_this, param_name) in [("{+name}", "name")].iter() {
|
||
let mut replace_with = String::new();
|
||
for &(name, ref value) in params.iter() {
|
||
if name == param_name {
|
||
replace_with = value.to_string();
|
||
break;
|
||
}
|
||
}
|
||
if find_this.as_bytes()[1] == '+' as u8 {
|
||
replace_with = percent_encode(replace_with.as_bytes(), DEFAULT_ENCODE_SET).to_string();
|
||
}
|
||
url = url.replace(find_this, &replace_with);
|
||
}
|
||
{
|
||
let mut indices_for_removal: Vec<usize> = Vec::with_capacity(1);
|
||
for param_name in ["name"].iter() {
|
||
if let Some(index) = params.iter().position(|t| &t.0 == param_name) {
|
||
indices_for_removal.push(index);
|
||
}
|
||
}
|
||
for &index in indices_for_removal.iter() {
|
||
params.remove(index);
|
||
}
|
||
}
|
||
|
||
let url = url::Url::parse_with_params(&url, params).unwrap();
|
||
|
||
|
||
|
||
loop {
|
||
let token = match self.hub.auth.token(&self._scopes.keys().collect::<Vec<_>>()[..]).await {
|
||
Ok(token) => token.clone(),
|
||
Err(err) => {
|
||
match dlg.token(&err) {
|
||
Some(token) => token,
|
||
None => {
|
||
dlg.finished(false);
|
||
return Err(client::Error::MissingToken(err))
|
||
}
|
||
}
|
||
}
|
||
};
|
||
let mut req_result = {
|
||
let client = &self.hub.client;
|
||
dlg.pre_request();
|
||
let mut req_builder = hyper::Request::builder().method(hyper::Method::DELETE).uri(url.clone().into_string())
|
||
.header(USER_AGENT, self.hub._user_agent.clone()) .header(AUTHORIZATION, format!("Bearer {}", token.as_str()));
|
||
|
||
|
||
let request = req_builder
|
||
.body(hyper::body::Body::empty());
|
||
|
||
client.request(request.unwrap()).await
|
||
|
||
};
|
||
|
||
match req_result {
|
||
Err(err) => {
|
||
if let client::Retry::After(d) = dlg.http_error(&err) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return Err(client::Error::HttpError(err))
|
||
}
|
||
Ok(mut res) => {
|
||
if !res.status().is_success() {
|
||
let res_body_string = client::get_body_as_string(res.body_mut()).await;
|
||
let (parts, _) = res.into_parts();
|
||
let body = hyper::Body::from(res_body_string.clone());
|
||
let restored_response = hyper::Response::from_parts(parts, body);
|
||
|
||
let server_response = json::from_str::<serde_json::Value>(&res_body_string).ok();
|
||
|
||
if let client::Retry::After(d) = dlg.http_failure(&restored_response, server_response.clone()) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
|
||
dlg.finished(false);
|
||
|
||
return match server_response {
|
||
Some(error_value) => Err(client::Error::BadRequest(error_value)),
|
||
None => Err(client::Error::Failure(restored_response)),
|
||
}
|
||
}
|
||
let result_value = {
|
||
let res_body_string = client::get_body_as_string(res.body_mut()).await;
|
||
|
||
match json::from_str(&res_body_string) {
|
||
Ok(decoded) => (res, decoded),
|
||
Err(err) => {
|
||
dlg.response_json_decode_error(&res_body_string, &err);
|
||
return Err(client::Error::JsonDecodeError(res_body_string, err));
|
||
}
|
||
}
|
||
};
|
||
|
||
dlg.finished(true);
|
||
return Ok(result_value)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
/// Required. Name of the note to delete.
|
||
///
|
||
/// Sets the *name* path property to the given value.
|
||
///
|
||
/// Even though the property as already been set when instantiating this call,
|
||
/// we provide this method for API completeness.
|
||
pub fn name(mut self, new_value: &str) -> NoteDeleteCall<'a> {
|
||
self._name = new_value.to_string();
|
||
self
|
||
}
|
||
/// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
|
||
/// while executing the actual API request.
|
||
///
|
||
/// It should be used to handle progress information, and to implement a certain level of resilience.
|
||
///
|
||
/// Sets the *delegate* property to the given value.
|
||
pub fn delegate(mut self, new_value: &'a mut dyn client::Delegate) -> NoteDeleteCall<'a> {
|
||
self._delegate = Some(new_value);
|
||
self
|
||
}
|
||
|
||
/// Set any additional parameter of the query string used in the request.
|
||
/// It should be used to set parameters which are not yet available through their own
|
||
/// setters.
|
||
///
|
||
/// Please note that this method must not be used to set any of the known parameters
|
||
/// which have their own setter method. If done anyway, the request will fail.
|
||
///
|
||
/// # Additional Parameters
|
||
///
|
||
/// * *$.xgafv* (query-string) - V1 error format.
|
||
/// * *access_token* (query-string) - OAuth access token.
|
||
/// * *alt* (query-string) - Data format for response.
|
||
/// * *callback* (query-string) - JSONP
|
||
/// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
|
||
/// * *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.
|
||
/// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
|
||
/// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
|
||
/// * *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.
|
||
/// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
|
||
/// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
|
||
pub fn param<T>(mut self, name: T, value: T) -> NoteDeleteCall<'a>
|
||
where T: AsRef<str> {
|
||
self._additional_params.insert(name.as_ref().to_string(), value.as_ref().to_string());
|
||
self
|
||
}
|
||
|
||
/// Identifies the authorization scope for the method you are building.
|
||
///
|
||
/// Use this method to actively specify which scope should be used, instead the default `Scope` variant
|
||
/// `Scope::Full`.
|
||
///
|
||
/// The `scope` will be added to a set of scopes. This is important as one can maintain access
|
||
/// tokens for more than one scope.
|
||
/// If `None` is specified, then all scopes will be removed and no default scope will be used either.
|
||
/// In that case, you have to specify your API-key using the `key` parameter (see the `param()`
|
||
/// function for details).
|
||
///
|
||
/// Usually there is more than one suitable scope to authorize an operation, some of which may
|
||
/// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
|
||
/// sufficient, a read-write scope will do as well.
|
||
pub fn add_scope<T, S>(mut self, scope: T) -> NoteDeleteCall<'a>
|
||
where T: Into<Option<S>>,
|
||
S: AsRef<str> {
|
||
match scope.into() {
|
||
Some(scope) => self._scopes.insert(scope.as_ref().to_string(), ()),
|
||
None => None,
|
||
};
|
||
self
|
||
}
|
||
}
|
||
|
||
|
||
/// Gets a note.
|
||
///
|
||
/// A builder for the *get* method supported by a *note* resource.
|
||
/// It is not used directly, but through a `NoteMethods` instance.
|
||
///
|
||
/// # Example
|
||
///
|
||
/// Instantiate a resource method builder
|
||
///
|
||
/// ```test_harness,no_run
|
||
/// # extern crate hyper;
|
||
/// # extern crate hyper_rustls;
|
||
/// # extern crate google_keep1 as keep1;
|
||
/// # async fn dox() {
|
||
/// # use std::default::Default;
|
||
/// # use keep1::{Keep, oauth2, hyper, hyper_rustls};
|
||
///
|
||
/// # let secret: oauth2::ApplicationSecret = Default::default();
|
||
/// # let auth = oauth2::InstalledFlowAuthenticator::builder(
|
||
/// # secret,
|
||
/// # oauth2::InstalledFlowReturnMethod::HTTPRedirect,
|
||
/// # ).build().await.unwrap();
|
||
/// # let mut hub = Keep::new(hyper::Client::builder().build(hyper_rustls::HttpsConnector::with_native_roots().https_or_http().enable_http1().enable_http2().build()), auth);
|
||
/// // You can configure optional parameters by calling the respective setters at will, and
|
||
/// // execute the final call using `doit()`.
|
||
/// // Values shown here are possibly random and not representative !
|
||
/// let result = hub.notes().get("name")
|
||
/// .doit().await;
|
||
/// # }
|
||
/// ```
|
||
pub struct NoteGetCall<'a>
|
||
where {
|
||
|
||
hub: &'a Keep<>,
|
||
_name: String,
|
||
_delegate: Option<&'a mut dyn client::Delegate>,
|
||
_additional_params: HashMap<String, String>,
|
||
_scopes: BTreeMap<String, ()>
|
||
}
|
||
|
||
impl<'a> client::CallBuilder for NoteGetCall<'a> {}
|
||
|
||
impl<'a> NoteGetCall<'a> {
|
||
|
||
|
||
/// Perform the operation you have build so far.
|
||
pub async fn doit(mut self) -> client::Result<(hyper::Response<hyper::body::Body>, Note)> {
|
||
use url::percent_encoding::{percent_encode, DEFAULT_ENCODE_SET};
|
||
use std::io::{Read, Seek};
|
||
use hyper::header::{CONTENT_TYPE, CONTENT_LENGTH, AUTHORIZATION, USER_AGENT, LOCATION};
|
||
use client::ToParts;
|
||
let mut dd = client::DefaultDelegate;
|
||
let mut dlg: &mut dyn client::Delegate = match self._delegate {
|
||
Some(d) => d,
|
||
None => &mut dd
|
||
};
|
||
dlg.begin(client::MethodInfo { id: "keep.notes.get",
|
||
http_method: hyper::Method::GET });
|
||
let mut params: Vec<(&str, String)> = Vec::with_capacity(3 + self._additional_params.len());
|
||
params.push(("name", self._name.to_string()));
|
||
for &field in ["alt", "name"].iter() {
|
||
if self._additional_params.contains_key(field) {
|
||
dlg.finished(false);
|
||
return Err(client::Error::FieldClash(field));
|
||
}
|
||
}
|
||
for (name, value) in self._additional_params.iter() {
|
||
params.push((&name, value.clone()));
|
||
}
|
||
|
||
params.push(("alt", "json".to_string()));
|
||
|
||
let mut url = self.hub._base_url.clone() + "v1/{+name}";
|
||
if self._scopes.len() == 0 {
|
||
self._scopes.insert(Scope::Readonly.as_ref().to_string(), ());
|
||
}
|
||
|
||
for &(find_this, param_name) in [("{+name}", "name")].iter() {
|
||
let mut replace_with = String::new();
|
||
for &(name, ref value) in params.iter() {
|
||
if name == param_name {
|
||
replace_with = value.to_string();
|
||
break;
|
||
}
|
||
}
|
||
if find_this.as_bytes()[1] == '+' as u8 {
|
||
replace_with = percent_encode(replace_with.as_bytes(), DEFAULT_ENCODE_SET).to_string();
|
||
}
|
||
url = url.replace(find_this, &replace_with);
|
||
}
|
||
{
|
||
let mut indices_for_removal: Vec<usize> = Vec::with_capacity(1);
|
||
for param_name in ["name"].iter() {
|
||
if let Some(index) = params.iter().position(|t| &t.0 == param_name) {
|
||
indices_for_removal.push(index);
|
||
}
|
||
}
|
||
for &index in indices_for_removal.iter() {
|
||
params.remove(index);
|
||
}
|
||
}
|
||
|
||
let url = url::Url::parse_with_params(&url, params).unwrap();
|
||
|
||
|
||
|
||
loop {
|
||
let token = match self.hub.auth.token(&self._scopes.keys().collect::<Vec<_>>()[..]).await {
|
||
Ok(token) => token.clone(),
|
||
Err(err) => {
|
||
match dlg.token(&err) {
|
||
Some(token) => token,
|
||
None => {
|
||
dlg.finished(false);
|
||
return Err(client::Error::MissingToken(err))
|
||
}
|
||
}
|
||
}
|
||
};
|
||
let mut req_result = {
|
||
let client = &self.hub.client;
|
||
dlg.pre_request();
|
||
let mut req_builder = hyper::Request::builder().method(hyper::Method::GET).uri(url.clone().into_string())
|
||
.header(USER_AGENT, self.hub._user_agent.clone()) .header(AUTHORIZATION, format!("Bearer {}", token.as_str()));
|
||
|
||
|
||
let request = req_builder
|
||
.body(hyper::body::Body::empty());
|
||
|
||
client.request(request.unwrap()).await
|
||
|
||
};
|
||
|
||
match req_result {
|
||
Err(err) => {
|
||
if let client::Retry::After(d) = dlg.http_error(&err) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return Err(client::Error::HttpError(err))
|
||
}
|
||
Ok(mut res) => {
|
||
if !res.status().is_success() {
|
||
let res_body_string = client::get_body_as_string(res.body_mut()).await;
|
||
let (parts, _) = res.into_parts();
|
||
let body = hyper::Body::from(res_body_string.clone());
|
||
let restored_response = hyper::Response::from_parts(parts, body);
|
||
|
||
let server_response = json::from_str::<serde_json::Value>(&res_body_string).ok();
|
||
|
||
if let client::Retry::After(d) = dlg.http_failure(&restored_response, server_response.clone()) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
|
||
dlg.finished(false);
|
||
|
||
return match server_response {
|
||
Some(error_value) => Err(client::Error::BadRequest(error_value)),
|
||
None => Err(client::Error::Failure(restored_response)),
|
||
}
|
||
}
|
||
let result_value = {
|
||
let res_body_string = client::get_body_as_string(res.body_mut()).await;
|
||
|
||
match json::from_str(&res_body_string) {
|
||
Ok(decoded) => (res, decoded),
|
||
Err(err) => {
|
||
dlg.response_json_decode_error(&res_body_string, &err);
|
||
return Err(client::Error::JsonDecodeError(res_body_string, err));
|
||
}
|
||
}
|
||
};
|
||
|
||
dlg.finished(true);
|
||
return Ok(result_value)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
/// Required. Name of the resource.
|
||
///
|
||
/// Sets the *name* path property to the given value.
|
||
///
|
||
/// Even though the property as already been set when instantiating this call,
|
||
/// we provide this method for API completeness.
|
||
pub fn name(mut self, new_value: &str) -> NoteGetCall<'a> {
|
||
self._name = new_value.to_string();
|
||
self
|
||
}
|
||
/// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
|
||
/// while executing the actual API request.
|
||
///
|
||
/// It should be used to handle progress information, and to implement a certain level of resilience.
|
||
///
|
||
/// Sets the *delegate* property to the given value.
|
||
pub fn delegate(mut self, new_value: &'a mut dyn client::Delegate) -> NoteGetCall<'a> {
|
||
self._delegate = Some(new_value);
|
||
self
|
||
}
|
||
|
||
/// Set any additional parameter of the query string used in the request.
|
||
/// It should be used to set parameters which are not yet available through their own
|
||
/// setters.
|
||
///
|
||
/// Please note that this method must not be used to set any of the known parameters
|
||
/// which have their own setter method. If done anyway, the request will fail.
|
||
///
|
||
/// # Additional Parameters
|
||
///
|
||
/// * *$.xgafv* (query-string) - V1 error format.
|
||
/// * *access_token* (query-string) - OAuth access token.
|
||
/// * *alt* (query-string) - Data format for response.
|
||
/// * *callback* (query-string) - JSONP
|
||
/// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
|
||
/// * *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.
|
||
/// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
|
||
/// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
|
||
/// * *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.
|
||
/// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
|
||
/// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
|
||
pub fn param<T>(mut self, name: T, value: T) -> NoteGetCall<'a>
|
||
where T: AsRef<str> {
|
||
self._additional_params.insert(name.as_ref().to_string(), value.as_ref().to_string());
|
||
self
|
||
}
|
||
|
||
/// Identifies the authorization scope for the method you are building.
|
||
///
|
||
/// Use this method to actively specify which scope should be used, instead the default `Scope` variant
|
||
/// `Scope::Readonly`.
|
||
///
|
||
/// The `scope` will be added to a set of scopes. This is important as one can maintain access
|
||
/// tokens for more than one scope.
|
||
/// If `None` is specified, then all scopes will be removed and no default scope will be used either.
|
||
/// In that case, you have to specify your API-key using the `key` parameter (see the `param()`
|
||
/// function for details).
|
||
///
|
||
/// Usually there is more than one suitable scope to authorize an operation, some of which may
|
||
/// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
|
||
/// sufficient, a read-write scope will do as well.
|
||
pub fn add_scope<T, S>(mut self, scope: T) -> NoteGetCall<'a>
|
||
where T: Into<Option<S>>,
|
||
S: AsRef<str> {
|
||
match scope.into() {
|
||
Some(scope) => self._scopes.insert(scope.as_ref().to_string(), ()),
|
||
None => None,
|
||
};
|
||
self
|
||
}
|
||
}
|
||
|
||
|
||
/// 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.
|
||
///
|
||
/// A builder for the *list* method supported by a *note* resource.
|
||
/// It is not used directly, but through a `NoteMethods` instance.
|
||
///
|
||
/// # Example
|
||
///
|
||
/// Instantiate a resource method builder
|
||
///
|
||
/// ```test_harness,no_run
|
||
/// # extern crate hyper;
|
||
/// # extern crate hyper_rustls;
|
||
/// # extern crate google_keep1 as keep1;
|
||
/// # async fn dox() {
|
||
/// # use std::default::Default;
|
||
/// # use keep1::{Keep, oauth2, hyper, hyper_rustls};
|
||
///
|
||
/// # let secret: oauth2::ApplicationSecret = Default::default();
|
||
/// # let auth = oauth2::InstalledFlowAuthenticator::builder(
|
||
/// # secret,
|
||
/// # oauth2::InstalledFlowReturnMethod::HTTPRedirect,
|
||
/// # ).build().await.unwrap();
|
||
/// # let mut hub = Keep::new(hyper::Client::builder().build(hyper_rustls::HttpsConnector::with_native_roots().https_or_http().enable_http1().enable_http2().build()), auth);
|
||
/// // You can configure optional parameters by calling the respective setters at will, and
|
||
/// // execute the final call using `doit()`.
|
||
/// // Values shown here are possibly random and not representative !
|
||
/// let result = hub.notes().list()
|
||
/// .page_token("gubergren")
|
||
/// .page_size(-75)
|
||
/// .filter("dolor")
|
||
/// .doit().await;
|
||
/// # }
|
||
/// ```
|
||
pub struct NoteListCall<'a>
|
||
where {
|
||
|
||
hub: &'a Keep<>,
|
||
_page_token: Option<String>,
|
||
_page_size: Option<i32>,
|
||
_filter: Option<String>,
|
||
_delegate: Option<&'a mut dyn client::Delegate>,
|
||
_additional_params: HashMap<String, String>,
|
||
_scopes: BTreeMap<String, ()>
|
||
}
|
||
|
||
impl<'a> client::CallBuilder for NoteListCall<'a> {}
|
||
|
||
impl<'a> NoteListCall<'a> {
|
||
|
||
|
||
/// Perform the operation you have build so far.
|
||
pub async fn doit(mut self) -> client::Result<(hyper::Response<hyper::body::Body>, ListNotesResponse)> {
|
||
use std::io::{Read, Seek};
|
||
use hyper::header::{CONTENT_TYPE, CONTENT_LENGTH, AUTHORIZATION, USER_AGENT, LOCATION};
|
||
use client::ToParts;
|
||
let mut dd = client::DefaultDelegate;
|
||
let mut dlg: &mut dyn client::Delegate = match self._delegate {
|
||
Some(d) => d,
|
||
None => &mut dd
|
||
};
|
||
dlg.begin(client::MethodInfo { id: "keep.notes.list",
|
||
http_method: hyper::Method::GET });
|
||
let mut params: Vec<(&str, String)> = Vec::with_capacity(5 + self._additional_params.len());
|
||
if let Some(value) = self._page_token {
|
||
params.push(("pageToken", value.to_string()));
|
||
}
|
||
if let Some(value) = self._page_size {
|
||
params.push(("pageSize", value.to_string()));
|
||
}
|
||
if let Some(value) = self._filter {
|
||
params.push(("filter", value.to_string()));
|
||
}
|
||
for &field in ["alt", "pageToken", "pageSize", "filter"].iter() {
|
||
if self._additional_params.contains_key(field) {
|
||
dlg.finished(false);
|
||
return Err(client::Error::FieldClash(field));
|
||
}
|
||
}
|
||
for (name, value) in self._additional_params.iter() {
|
||
params.push((&name, value.clone()));
|
||
}
|
||
|
||
params.push(("alt", "json".to_string()));
|
||
|
||
let mut url = self.hub._base_url.clone() + "v1/notes";
|
||
if self._scopes.len() == 0 {
|
||
self._scopes.insert(Scope::Readonly.as_ref().to_string(), ());
|
||
}
|
||
|
||
|
||
let url = url::Url::parse_with_params(&url, params).unwrap();
|
||
|
||
|
||
|
||
loop {
|
||
let token = match self.hub.auth.token(&self._scopes.keys().collect::<Vec<_>>()[..]).await {
|
||
Ok(token) => token.clone(),
|
||
Err(err) => {
|
||
match dlg.token(&err) {
|
||
Some(token) => token,
|
||
None => {
|
||
dlg.finished(false);
|
||
return Err(client::Error::MissingToken(err))
|
||
}
|
||
}
|
||
}
|
||
};
|
||
let mut req_result = {
|
||
let client = &self.hub.client;
|
||
dlg.pre_request();
|
||
let mut req_builder = hyper::Request::builder().method(hyper::Method::GET).uri(url.clone().into_string())
|
||
.header(USER_AGENT, self.hub._user_agent.clone()) .header(AUTHORIZATION, format!("Bearer {}", token.as_str()));
|
||
|
||
|
||
let request = req_builder
|
||
.body(hyper::body::Body::empty());
|
||
|
||
client.request(request.unwrap()).await
|
||
|
||
};
|
||
|
||
match req_result {
|
||
Err(err) => {
|
||
if let client::Retry::After(d) = dlg.http_error(&err) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return Err(client::Error::HttpError(err))
|
||
}
|
||
Ok(mut res) => {
|
||
if !res.status().is_success() {
|
||
let res_body_string = client::get_body_as_string(res.body_mut()).await;
|
||
let (parts, _) = res.into_parts();
|
||
let body = hyper::Body::from(res_body_string.clone());
|
||
let restored_response = hyper::Response::from_parts(parts, body);
|
||
|
||
let server_response = json::from_str::<serde_json::Value>(&res_body_string).ok();
|
||
|
||
if let client::Retry::After(d) = dlg.http_failure(&restored_response, server_response.clone()) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
|
||
dlg.finished(false);
|
||
|
||
return match server_response {
|
||
Some(error_value) => Err(client::Error::BadRequest(error_value)),
|
||
None => Err(client::Error::Failure(restored_response)),
|
||
}
|
||
}
|
||
let result_value = {
|
||
let res_body_string = client::get_body_as_string(res.body_mut()).await;
|
||
|
||
match json::from_str(&res_body_string) {
|
||
Ok(decoded) => (res, decoded),
|
||
Err(err) => {
|
||
dlg.response_json_decode_error(&res_body_string, &err);
|
||
return Err(client::Error::JsonDecodeError(res_body_string, err));
|
||
}
|
||
}
|
||
};
|
||
|
||
dlg.finished(true);
|
||
return Ok(result_value)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
/// The previous page's `next_page_token` field.
|
||
///
|
||
/// Sets the *page token* query property to the given value.
|
||
pub fn page_token(mut self, new_value: &str) -> NoteListCall<'a> {
|
||
self._page_token = Some(new_value.to_string());
|
||
self
|
||
}
|
||
/// The maximum number of results to return.
|
||
///
|
||
/// Sets the *page size* query property to the given value.
|
||
pub fn page_size(mut self, new_value: i32) -> NoteListCall<'a> {
|
||
self._page_size = Some(new_value);
|
||
self
|
||
}
|
||
/// 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).
|
||
///
|
||
/// Sets the *filter* query property to the given value.
|
||
pub fn filter(mut self, new_value: &str) -> NoteListCall<'a> {
|
||
self._filter = Some(new_value.to_string());
|
||
self
|
||
}
|
||
/// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
|
||
/// while executing the actual API request.
|
||
///
|
||
/// It should be used to handle progress information, and to implement a certain level of resilience.
|
||
///
|
||
/// Sets the *delegate* property to the given value.
|
||
pub fn delegate(mut self, new_value: &'a mut dyn client::Delegate) -> NoteListCall<'a> {
|
||
self._delegate = Some(new_value);
|
||
self
|
||
}
|
||
|
||
/// Set any additional parameter of the query string used in the request.
|
||
/// It should be used to set parameters which are not yet available through their own
|
||
/// setters.
|
||
///
|
||
/// Please note that this method must not be used to set any of the known parameters
|
||
/// which have their own setter method. If done anyway, the request will fail.
|
||
///
|
||
/// # Additional Parameters
|
||
///
|
||
/// * *$.xgafv* (query-string) - V1 error format.
|
||
/// * *access_token* (query-string) - OAuth access token.
|
||
/// * *alt* (query-string) - Data format for response.
|
||
/// * *callback* (query-string) - JSONP
|
||
/// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
|
||
/// * *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.
|
||
/// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
|
||
/// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
|
||
/// * *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.
|
||
/// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
|
||
/// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
|
||
pub fn param<T>(mut self, name: T, value: T) -> NoteListCall<'a>
|
||
where T: AsRef<str> {
|
||
self._additional_params.insert(name.as_ref().to_string(), value.as_ref().to_string());
|
||
self
|
||
}
|
||
|
||
/// Identifies the authorization scope for the method you are building.
|
||
///
|
||
/// Use this method to actively specify which scope should be used, instead the default `Scope` variant
|
||
/// `Scope::Readonly`.
|
||
///
|
||
/// The `scope` will be added to a set of scopes. This is important as one can maintain access
|
||
/// tokens for more than one scope.
|
||
/// If `None` is specified, then all scopes will be removed and no default scope will be used either.
|
||
/// In that case, you have to specify your API-key using the `key` parameter (see the `param()`
|
||
/// function for details).
|
||
///
|
||
/// Usually there is more than one suitable scope to authorize an operation, some of which may
|
||
/// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
|
||
/// sufficient, a read-write scope will do as well.
|
||
pub fn add_scope<T, S>(mut self, scope: T) -> NoteListCall<'a>
|
||
where T: Into<Option<S>>,
|
||
S: AsRef<str> {
|
||
match scope.into() {
|
||
Some(scope) => self._scopes.insert(scope.as_ref().to_string(), ()),
|
||
None => None,
|
||
};
|
||
self
|
||
}
|
||
}
|
||
|
||
|