mirror of
https://github.com/OMGeeky/google-apis-rs.git
synced 2026-02-23 15:49:49 +01:00
7819 lines
335 KiB
Rust
7819 lines
335 KiB
Rust
// DO NOT EDIT !
|
||
// This file was generated automatically from 'src/mako/api/lib.rs.mako'
|
||
// DO NOT EDIT !
|
||
|
||
//! This documentation was generated from *mirror* crate version *1.0.4+20170419*, where *20170419* is the exact revision of the *mirror:v1* schema built by the [mako](http://www.makotemplates.org/) code generator *v1.0.4*.
|
||
//!
|
||
//! Everything else about the *mirror* *v1* API can be found at the
|
||
//! [official documentation site](https://developers.google.com/glass).
|
||
//! The original source code is [on github](https://github.com/Byron/google-apis-rs/tree/master/gen/mirror1).
|
||
//! # Features
|
||
//!
|
||
//! Handle the following *Resources* with ease from the central [hub](struct.Mirror.html) ...
|
||
//!
|
||
//! * [accounts](struct.Account.html)
|
||
//! * [*insert*](struct.AccountInsertCall.html)
|
||
//! * [contacts](struct.Contact.html)
|
||
//! * [*delete*](struct.ContactDeleteCall.html), [*get*](struct.ContactGetCall.html), [*insert*](struct.ContactInsertCall.html), [*list*](struct.ContactListCall.html), [*patch*](struct.ContactPatchCall.html) and [*update*](struct.ContactUpdateCall.html)
|
||
//! * [locations](struct.Location.html)
|
||
//! * [*get*](struct.LocationGetCall.html) and [*list*](struct.LocationListCall.html)
|
||
//! * [settings](struct.Setting.html)
|
||
//! * [*get*](struct.SettingGetCall.html)
|
||
//! * [subscriptions](struct.Subscription.html)
|
||
//! * [*delete*](struct.SubscriptionDeleteCall.html), [*insert*](struct.SubscriptionInsertCall.html), [*list*](struct.SubscriptionListCall.html) and [*update*](struct.SubscriptionUpdateCall.html)
|
||
//! * timeline
|
||
//! * [*attachments delete*](struct.TimelineAttachmentDeleteCall.html), [*attachments get*](struct.TimelineAttachmentGetCall.html), [*attachments insert*](struct.TimelineAttachmentInsertCall.html), [*attachments list*](struct.TimelineAttachmentListCall.html), [*delete*](struct.TimelineDeleteCall.html), [*get*](struct.TimelineGetCall.html), [*insert*](struct.TimelineInsertCall.html), [*list*](struct.TimelineListCall.html), [*patch*](struct.TimelinePatchCall.html) and [*update*](struct.TimelineUpdateCall.html)
|
||
//!
|
||
//!
|
||
//! Upload supported by ...
|
||
//!
|
||
//! * [*update timeline*](struct.TimelineUpdateCall.html)
|
||
//! * [*insert timeline*](struct.TimelineInsertCall.html)
|
||
//! * [*attachments insert timeline*](struct.TimelineAttachmentInsertCall.html)
|
||
//!
|
||
//! Download supported by ...
|
||
//!
|
||
//! * [*attachments get timeline*](struct.TimelineAttachmentGetCall.html)
|
||
//!
|
||
//!
|
||
//!
|
||
//! Not what you are looking for ? Find all other Google APIs in their Rust [documentation index](http://byron.github.io/google-apis-rs).
|
||
//!
|
||
//! # Structure of this Library
|
||
//!
|
||
//! The API is structured into the following primary items:
|
||
//!
|
||
//! * **[Hub](struct.Mirror.html)**
|
||
//! * a central object to maintain state and allow accessing all *Activities*
|
||
//! * creates [*Method Builders*](trait.MethodsBuilder.html) which in turn
|
||
//! allow access to individual [*Call Builders*](trait.CallBuilder.html)
|
||
//! * **[Resources](trait.Resource.html)**
|
||
//! * primary types that you can apply *Activities* to
|
||
//! * a collection of properties and *Parts*
|
||
//! * **[Parts](trait.Part.html)**
|
||
//! * a collection of properties
|
||
//! * never directly used in *Activities*
|
||
//! * **[Activities](trait.CallBuilder.html)**
|
||
//! * operations to apply to *Resources*
|
||
//!
|
||
//! All *structures* are marked with applicable traits to further categorize them and ease browsing.
|
||
//!
|
||
//! Generally speaking, you can invoke *Activities* like this:
|
||
//!
|
||
//! ```Rust,ignore
|
||
//! let r = hub.resource().activity(...).doit()
|
||
//! ```
|
||
//!
|
||
//! Or specifically ...
|
||
//!
|
||
//! ```ignore
|
||
//! let r = hub.contacts().insert(...).doit()
|
||
//! let r = hub.contacts().delete(...).doit()
|
||
//! let r = hub.contacts().list(...).doit()
|
||
//! let r = hub.contacts().update(...).doit()
|
||
//! let r = hub.contacts().patch(...).doit()
|
||
//! let r = hub.contacts().get(...).doit()
|
||
//! ```
|
||
//!
|
||
//! The `resource()` and `activity(...)` calls create [builders][builder-pattern]. The second one dealing with `Activities`
|
||
//! supports various methods to configure the impending operation (not shown here). It is made such that all required arguments have to be
|
||
//! specified right away (i.e. `(...)`), whereas all optional ones can be [build up][builder-pattern] as desired.
|
||
//! The `doit()` method performs the actual communication with the server and returns the respective result.
|
||
//!
|
||
//! # Usage
|
||
//!
|
||
//! ## Setting up your Project
|
||
//!
|
||
//! To use this library, you would put the following lines into your `Cargo.toml` file:
|
||
//!
|
||
//! ```toml
|
||
//! [dependencies]
|
||
//! google-mirror1 = "*"
|
||
//! ```
|
||
//!
|
||
//! ## A complete example
|
||
//!
|
||
//! ```test_harness,no_run
|
||
//! extern crate hyper;
|
||
//! extern crate yup_oauth2 as oauth2;
|
||
//! extern crate google_mirror1 as mirror1;
|
||
//! use mirror1::Contact;
|
||
//! use mirror1::{Result, Error};
|
||
//! # #[test] fn egal() {
|
||
//! use std::default::Default;
|
||
//! use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage};
|
||
//! use mirror1::Mirror;
|
||
//!
|
||
//! // Get an ApplicationSecret instance by some means. It contains the `client_id` and
|
||
//! // `client_secret`, among other things.
|
||
//! let secret: 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 = Authenticator::new(&secret, DefaultAuthenticatorDelegate,
|
||
//! hyper::Client::new(),
|
||
//! <MemoryStorage as Default>::default(), None);
|
||
//! let mut hub = Mirror::new(hyper::Client::new(), 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 = Contact::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.contacts().update(req, "id")
|
||
//! .doit();
|
||
//!
|
||
//! 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::MissingAPIKey
|
||
//! |Error::MissingToken(_)
|
||
//! |Error::Cancelled
|
||
//! |Error::UploadSizeLimitExceeded(_, _)
|
||
//! |Error::Failure(_)
|
||
//! |Error::BadRequest(_)
|
||
//! |Error::FieldClash(_)
|
||
//! |Error::JsonDecodeError(_, _) => println!("{}", e),
|
||
//! },
|
||
//! Ok(res) => println!("Success: {:?}", res),
|
||
//! }
|
||
//! # }
|
||
//! ```
|
||
//! ## Handling Errors
|
||
//!
|
||
//! All errors produced by the system are provided either as [Result](enum.Result.html) enumeration as return value of
|
||
//! the doit() methods, or handed as possibly intermediate results to either the
|
||
//! [Hub Delegate](trait.Delegate.html), or the [Authenticator Delegate](https://docs.rs/yup-oauth2/*/yup_oauth2/trait.AuthenticatorDelegate.html).
|
||
//!
|
||
//! When delegates handle errors or intermediate values, they may have a chance to instruct the system to retry. This
|
||
//! makes the system potentially resilient to all kinds of errors.
|
||
//!
|
||
//! ## Uploads and Downloads
|
||
//! If a method supports downloads, the response body, which is part of the [Result](enum.Result.html), should be
|
||
//! read by you to obtain the media.
|
||
//! If such a method also supports a [Response Result](trait.ResponseResult.html), it will return that by default.
|
||
//! You can see it as meta-data for the actual media. To trigger a media download, you will have to set up the builder by making
|
||
//! this call: `.param("alt", "media")`.
|
||
//!
|
||
//! Methods supporting uploads can do so using up to 2 different protocols:
|
||
//! *simple* and *resumable*. The distinctiveness of each is represented by customized
|
||
//! `doit(...)` methods, which are then named `upload(...)` and `upload_resumable(...)` respectively.
|
||
//!
|
||
//! ## Customization and Callbacks
|
||
//!
|
||
//! You may alter the way an `doit()` method is called by providing a [delegate](trait.Delegate.html) to the
|
||
//! [Method Builder](trait.CallBuilder.html) before making the final `doit()` call.
|
||
//! Respective methods will be called to provide progress information, as well as determine whether the system should
|
||
//! retry on failure.
|
||
//!
|
||
//! The [delegate trait](trait.Delegate.html) is default-implemented, allowing you to customize it with minimal effort.
|
||
//!
|
||
//! ## Optional Parts in Server-Requests
|
||
//!
|
||
//! All structures provided by this library are made to be [enocodable](trait.RequestValue.html) and
|
||
//! [decodable](trait.ResponseResult.html) via *json*. Optionals are used to indicate that partial requests are responses
|
||
//! are valid.
|
||
//! Most optionals are are considered [Parts](trait.Part.html) which are identifiable by name, which will be sent to
|
||
//! the server to indicate either the set parts of the request or the desired parts in the response.
|
||
//!
|
||
//! ## Builder Arguments
|
||
//!
|
||
//! Using [method builders](trait.CallBuilder.html), you are able to prepare an action call by repeatedly calling it's methods.
|
||
//! These will always take a single argument, for which the following statements are true.
|
||
//!
|
||
//! * [PODs][wiki-pod] are handed by copy
|
||
//! * strings are passed as `&str`
|
||
//! * [request values](trait.RequestValue.html) are moved
|
||
//!
|
||
//! Arguments will always be copied or cloned into the builder, to make them independent of their original life times.
|
||
//!
|
||
//! [wiki-pod]: http://en.wikipedia.org/wiki/Plain_old_data_structure
|
||
//! [builder-pattern]: http://en.wikipedia.org/wiki/Builder_pattern
|
||
//! [google-go-api]: https://github.com/google/google-api-go-client
|
||
//!
|
||
//!
|
||
|
||
// Unused attributes happen thanks to defined, but unused structures
|
||
// We don't warn about this, as depending on the API, some data structures or facilities are never used.
|
||
// Instead of pre-determining this, we just disable the lint. It's manually tuned to not have any
|
||
// unused imports in fully featured APIs. Same with unused_mut ... .
|
||
#![allow(unused_imports, unused_mut, dead_code)]
|
||
|
||
// DO NOT EDIT !
|
||
// This file was generated automatically from 'src/mako/api/lib.rs.mako'
|
||
// DO NOT EDIT !
|
||
|
||
#[macro_use]
|
||
extern crate serde_derive;
|
||
|
||
extern crate hyper;
|
||
extern crate serde;
|
||
extern crate serde_json;
|
||
extern crate yup_oauth2 as oauth2;
|
||
extern crate mime;
|
||
extern crate url;
|
||
|
||
mod cmn;
|
||
|
||
use std::collections::HashMap;
|
||
use std::cell::RefCell;
|
||
use std::borrow::BorrowMut;
|
||
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 std::time::Duration;
|
||
|
||
pub use cmn::{MultiPartReader, ToParts, MethodInfo, Result, Error, CallBuilder, Hub, ReadSeek, Part,
|
||
ResponseResult, RequestValue, NestedType, Delegate, DefaultDelegate, MethodsBuilder,
|
||
Resource, ErrorResponse, remove_json_null_values};
|
||
|
||
|
||
// ##############
|
||
// 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 {
|
||
/// View and manage your Glass timeline
|
||
GlasTimeline,
|
||
|
||
/// View your location
|
||
GlasLocation,
|
||
}
|
||
|
||
impl AsRef<str> for Scope {
|
||
fn as_ref(&self) -> &str {
|
||
match *self {
|
||
Scope::GlasTimeline => "https://www.googleapis.com/auth/glass.timeline",
|
||
Scope::GlasLocation => "https://www.googleapis.com/auth/glass.location",
|
||
}
|
||
}
|
||
}
|
||
|
||
impl Default for Scope {
|
||
fn default() -> Scope {
|
||
Scope::GlasTimeline
|
||
}
|
||
}
|
||
|
||
|
||
|
||
// ########
|
||
// HUB ###
|
||
// ######
|
||
|
||
/// Central instance to access all Mirror related resource activities
|
||
///
|
||
/// # Examples
|
||
///
|
||
/// Instantiate a new hub
|
||
///
|
||
/// ```test_harness,no_run
|
||
/// extern crate hyper;
|
||
/// extern crate yup_oauth2 as oauth2;
|
||
/// extern crate google_mirror1 as mirror1;
|
||
/// use mirror1::Contact;
|
||
/// use mirror1::{Result, Error};
|
||
/// # #[test] fn egal() {
|
||
/// use std::default::Default;
|
||
/// use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage};
|
||
/// use mirror1::Mirror;
|
||
///
|
||
/// // Get an ApplicationSecret instance by some means. It contains the `client_id` and
|
||
/// // `client_secret`, among other things.
|
||
/// let secret: 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 = Authenticator::new(&secret, DefaultAuthenticatorDelegate,
|
||
/// hyper::Client::new(),
|
||
/// <MemoryStorage as Default>::default(), None);
|
||
/// let mut hub = Mirror::new(hyper::Client::new(), 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 = Contact::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.contacts().update(req, "id")
|
||
/// .doit();
|
||
///
|
||
/// 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::MissingAPIKey
|
||
/// |Error::MissingToken(_)
|
||
/// |Error::Cancelled
|
||
/// |Error::UploadSizeLimitExceeded(_, _)
|
||
/// |Error::Failure(_)
|
||
/// |Error::BadRequest(_)
|
||
/// |Error::FieldClash(_)
|
||
/// |Error::JsonDecodeError(_, _) => println!("{}", e),
|
||
/// },
|
||
/// Ok(res) => println!("Success: {:?}", res),
|
||
/// }
|
||
/// # }
|
||
/// ```
|
||
pub struct Mirror<C, A> {
|
||
client: RefCell<C>,
|
||
auth: RefCell<A>,
|
||
_user_agent: String,
|
||
_base_url: String,
|
||
_root_url: String,
|
||
}
|
||
|
||
impl<'a, C, A> Hub for Mirror<C, A> {}
|
||
|
||
impl<'a, C, A> Mirror<C, A>
|
||
where C: BorrowMut<hyper::Client>, A: oauth2::GetToken {
|
||
|
||
pub fn new(client: C, authenticator: A) -> Mirror<C, A> {
|
||
Mirror {
|
||
client: RefCell::new(client),
|
||
auth: RefCell::new(authenticator),
|
||
_user_agent: "google-api-rust-client/1.0.4".to_string(),
|
||
_base_url: "https://www.googleapis.com/mirror/v1/".to_string(),
|
||
_root_url: "https://www.googleapis.com/".to_string(),
|
||
}
|
||
}
|
||
|
||
pub fn accounts(&'a self) -> AccountMethods<'a, C, A> {
|
||
AccountMethods { hub: &self }
|
||
}
|
||
pub fn contacts(&'a self) -> ContactMethods<'a, C, A> {
|
||
ContactMethods { hub: &self }
|
||
}
|
||
pub fn locations(&'a self) -> LocationMethods<'a, C, A> {
|
||
LocationMethods { hub: &self }
|
||
}
|
||
pub fn settings(&'a self) -> SettingMethods<'a, C, A> {
|
||
SettingMethods { hub: &self }
|
||
}
|
||
pub fn subscriptions(&'a self) -> SubscriptionMethods<'a, C, A> {
|
||
SubscriptionMethods { hub: &self }
|
||
}
|
||
pub fn timeline(&'a self) -> TimelineMethods<'a, C, A> {
|
||
TimelineMethods { hub: &self }
|
||
}
|
||
|
||
/// Set the user-agent header field to use in all requests to the server.
|
||
/// It defaults to `google-api-rust-client/1.0.4`.
|
||
///
|
||
/// 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://www.googleapis.com/mirror/v1/`.
|
||
///
|
||
/// 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://www.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 ###
|
||
// ##########
|
||
/// Represents an action taken by the user that triggered a notification.
|
||
///
|
||
/// This type is not used in any activity, and only used as *part* of another schema.
|
||
///
|
||
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
|
||
pub struct UserAction {
|
||
/// The type of action. The value of this can be:
|
||
/// - SHARE - the user shared an item.
|
||
/// - REPLY - the user replied to an item.
|
||
/// - REPLY_ALL - the user replied to all recipients of an item.
|
||
/// - CUSTOM - the user selected a custom menu item on the timeline item.
|
||
/// - DELETE - the user deleted the item.
|
||
/// - PIN - the user pinned the item.
|
||
/// - UNPIN - the user unpinned the item.
|
||
/// - LAUNCH - the user initiated a voice command. In the future, additional types may be added. UserActions with unrecognized types should be ignored.
|
||
#[serde(rename="type")]
|
||
pub type_: Option<String>,
|
||
/// An optional payload for the action.
|
||
///
|
||
/// For actions of type CUSTOM, this is the ID of the custom menu item that was selected.
|
||
pub payload: Option<String>,
|
||
}
|
||
|
||
impl Part for UserAction {}
|
||
|
||
|
||
/// Represents an account passed into the Account Manager on Glass.
|
||
///
|
||
/// # 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*).
|
||
///
|
||
/// * [insert accounts](struct.AccountInsertCall.html) (request|response)
|
||
///
|
||
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
|
||
pub struct Account {
|
||
/// no description provided
|
||
#[serde(rename="userData")]
|
||
pub user_data: Option<Vec<UserData>>,
|
||
/// no description provided
|
||
#[serde(rename="authTokens")]
|
||
pub auth_tokens: Option<Vec<AuthToken>>,
|
||
/// no description provided
|
||
pub password: Option<String>,
|
||
/// no description provided
|
||
pub features: Option<Vec<String>>,
|
||
}
|
||
|
||
impl RequestValue for Account {}
|
||
impl Resource for Account {}
|
||
impl ResponseResult for Account {}
|
||
|
||
|
||
/// Represents media content, such as a photo, that can be attached to a timeline item.
|
||
///
|
||
/// # 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*).
|
||
///
|
||
/// * [attachments insert timeline](struct.TimelineAttachmentInsertCall.html) (response)
|
||
/// * [attachments get timeline](struct.TimelineAttachmentGetCall.html) (response)
|
||
///
|
||
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
|
||
pub struct Attachment {
|
||
/// The URL for the content.
|
||
#[serde(rename="contentUrl")]
|
||
pub content_url: Option<String>,
|
||
/// The MIME type of the attachment.
|
||
#[serde(rename="contentType")]
|
||
pub content_type: Option<String>,
|
||
/// The ID of the attachment.
|
||
pub id: Option<String>,
|
||
/// Indicates that the contentUrl is not available because the attachment content is still being processed. If the caller wishes to retrieve the content, it should try again later.
|
||
#[serde(rename="isProcessingContent")]
|
||
pub is_processing_content: Option<bool>,
|
||
}
|
||
|
||
impl ResponseResult for Attachment {}
|
||
|
||
|
||
/// A notification delivered by the API.
|
||
///
|
||
/// This type is not used in any activity, and only used as *part* of another schema.
|
||
///
|
||
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
|
||
pub struct Notification {
|
||
/// The ID of the item that generated the notification.
|
||
#[serde(rename="itemId")]
|
||
pub item_id: Option<String>,
|
||
/// The secret verify token provided by the service when it subscribed for notifications.
|
||
#[serde(rename="verifyToken")]
|
||
pub verify_token: Option<String>,
|
||
/// A list of actions taken by the user that triggered the notification.
|
||
#[serde(rename="userActions")]
|
||
pub user_actions: Option<Vec<UserAction>>,
|
||
/// The user token provided by the service when it subscribed for notifications.
|
||
#[serde(rename="userToken")]
|
||
pub user_token: Option<String>,
|
||
/// The type of operation that generated the notification.
|
||
pub operation: Option<String>,
|
||
/// The collection that generated the notification.
|
||
pub collection: Option<String>,
|
||
}
|
||
|
||
impl Part for Notification {}
|
||
|
||
|
||
/// A list of timeline items. This is the response from the server to GET requests on the timeline collection.
|
||
///
|
||
/// # 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 timeline](struct.TimelineListCall.html) (response)
|
||
///
|
||
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
|
||
pub struct TimelineListResponse {
|
||
/// The next page token. Provide this as the pageToken parameter in the request to retrieve the next page of results.
|
||
#[serde(rename="nextPageToken")]
|
||
pub next_page_token: Option<String>,
|
||
/// Items in the timeline.
|
||
pub items: Option<Vec<TimelineItem>>,
|
||
/// The type of resource. This is always mirror#timeline.
|
||
pub kind: Option<String>,
|
||
}
|
||
|
||
impl ResponseResult for TimelineListResponse {}
|
||
|
||
|
||
/// A list of Contacts representing contacts. This is the response from the server to GET requests on the contacts collection.
|
||
///
|
||
/// # 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 contacts](struct.ContactListCall.html) (response)
|
||
///
|
||
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
|
||
pub struct ContactsListResponse {
|
||
/// Contact list.
|
||
pub items: Option<Vec<Contact>>,
|
||
/// The type of resource. This is always mirror#contacts.
|
||
pub kind: Option<String>,
|
||
}
|
||
|
||
impl ResponseResult for ContactsListResponse {}
|
||
|
||
|
||
/// Each item in the user's timeline is represented as a TimelineItem JSON structure, described below.
|
||
///
|
||
/// # 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*).
|
||
///
|
||
/// * [patch timeline](struct.TimelinePatchCall.html) (request|response)
|
||
/// * [insert timeline](struct.TimelineInsertCall.html) (request|response)
|
||
/// * [get timeline](struct.TimelineGetCall.html) (response)
|
||
/// * [update timeline](struct.TimelineUpdateCall.html) (request|response)
|
||
///
|
||
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
|
||
pub struct TimelineItem {
|
||
/// If this item was generated as a reply to another item, this field will be set to the ID of the item being replied to. This can be used to attach a reply to the appropriate conversation or post.
|
||
#[serde(rename="inReplyTo")]
|
||
pub in_reply_to: Option<String>,
|
||
/// The time at which this item was last modified, formatted according to RFC 3339.
|
||
pub updated: Option<String>,
|
||
/// A list of media attachments associated with this item. As a convenience, you can refer to attachments in your HTML payloads with the attachment or cid scheme. For example:
|
||
/// - attachment: <img src="attachment:attachment_index"> where attachment_index is the 0-based index of this array.
|
||
/// - cid: <img src="cid:attachment_id"> where attachment_id is the ID of the attachment.
|
||
pub attachments: Option<Vec<Attachment>>,
|
||
/// The time that should be displayed when this item is viewed in the timeline, formatted according to RFC 3339. This user's timeline is sorted chronologically on display time, so this will also determine where the item is displayed in the timeline. If not set by the service, the display time defaults to the updated time.
|
||
#[serde(rename="displayTime")]
|
||
pub display_time: Option<String>,
|
||
/// The user or group that created this item.
|
||
pub creator: Option<Contact>,
|
||
/// Text content of this item.
|
||
pub text: Option<String>,
|
||
/// A list of menu items that will be presented to the user when this item is selected in the timeline.
|
||
#[serde(rename="menuItems")]
|
||
pub menu_items: Option<Vec<MenuItem>>,
|
||
/// Whether this item is a bundle cover.
|
||
///
|
||
/// If an item is marked as a bundle cover, it will be the entry point to the bundle of items that have the same bundleId as that item. It will be shown only on the main timeline — not within the opened bundle.
|
||
///
|
||
/// On the main timeline, items that are shown are:
|
||
/// - Items that have isBundleCover set to true
|
||
/// - Items that do not have a bundleId In a bundle sub-timeline, items that are shown are:
|
||
/// - Items that have the bundleId in question AND isBundleCover set to false
|
||
#[serde(rename="isBundleCover")]
|
||
pub is_bundle_cover: Option<bool>,
|
||
/// A URL that can be used to retrieve this item.
|
||
#[serde(rename="selfLink")]
|
||
pub self_link: Option<String>,
|
||
/// The ID of the timeline item. This is unique within a user's timeline.
|
||
pub id: Option<String>,
|
||
/// When true, indicates this item is deleted, and only the ID property is set.
|
||
#[serde(rename="isDeleted")]
|
||
pub is_deleted: Option<bool>,
|
||
/// The bundle ID for this item. Services can specify a bundleId to group many items together. They appear under a single top-level item on the device.
|
||
#[serde(rename="bundleId")]
|
||
pub bundle_id: Option<String>,
|
||
/// The type of resource. This is always mirror#timelineItem.
|
||
pub kind: Option<String>,
|
||
/// A list of users or groups that this item has been shared with.
|
||
pub recipients: Option<Vec<Contact>>,
|
||
/// When true, indicates this item is pinned, which means it's grouped alongside "active" items like navigation and hangouts, on the opposite side of the home screen from historical (non-pinned) timeline items. You can allow the user to toggle the value of this property with the TOGGLE_PINNED built-in menu item.
|
||
#[serde(rename="isPinned")]
|
||
pub is_pinned: Option<bool>,
|
||
/// The title of this item.
|
||
pub title: Option<String>,
|
||
/// Controls how notifications for this item are presented on the device. If this is missing, no notification will be generated.
|
||
pub notification: Option<NotificationConfig>,
|
||
/// The time at which this item was created, formatted according to RFC 3339.
|
||
pub created: Option<String>,
|
||
/// HTML content for this item. If both text and html are provided for an item, the html will be rendered in the timeline.
|
||
/// Allowed HTML elements - You can use these elements in your timeline cards.
|
||
///
|
||
/// - Headers: h1, h2, h3, h4, h5, h6
|
||
/// - Images: img
|
||
/// - Lists: li, ol, ul
|
||
/// - HTML5 semantics: article, aside, details, figure, figcaption, footer, header, nav, section, summary, time
|
||
/// - Structural: blockquote, br, div, hr, p, span
|
||
/// - Style: b, big, center, em, i, u, s, small, strike, strong, style, sub, sup
|
||
/// - Tables: table, tbody, td, tfoot, th, thead, tr
|
||
/// Blocked HTML elements: These elements and their contents are removed from HTML payloads.
|
||
///
|
||
/// - Document headers: head, title
|
||
/// - Embeds: audio, embed, object, source, video
|
||
/// - Frames: frame, frameset
|
||
/// - Scripting: applet, script
|
||
/// Other elements: Any elements that aren't listed are removed, but their contents are preserved.
|
||
pub html: Option<String>,
|
||
/// The speakable version of the content of this item. Along with the READ_ALOUD menu item, use this field to provide text that would be clearer when read aloud, or to provide extended information to what is displayed visually on Glass.
|
||
///
|
||
/// Glassware should also specify the speakableType field, which will be spoken before this text in cases where the additional context is useful, for example when the user requests that the item be read aloud following a notification.
|
||
#[serde(rename="speakableText")]
|
||
pub speakable_text: Option<String>,
|
||
/// ETag for this item.
|
||
pub etag: Option<String>,
|
||
/// The geographic location associated with this item.
|
||
pub location: Option<Location>,
|
||
/// For pinned items, this determines the order in which the item is displayed in the timeline, with a higher score appearing closer to the clock. Note: setting this field is currently not supported.
|
||
#[serde(rename="pinScore")]
|
||
pub pin_score: Option<i32>,
|
||
/// A speakable description of the type of this item. This will be announced to the user prior to reading the content of the item in cases where the additional context is useful, for example when the user requests that the item be read aloud following a notification.
|
||
///
|
||
/// This should be a short, simple noun phrase such as "Email", "Text message", or "Daily Planet News Update".
|
||
///
|
||
/// Glassware are encouraged to populate this field for every timeline item, even if the item does not contain speakableText or text so that the user can learn the type of the item without looking at the screen.
|
||
#[serde(rename="speakableType")]
|
||
pub speakable_type: Option<String>,
|
||
/// A canonical URL pointing to the canonical/high quality version of the data represented by the timeline item.
|
||
#[serde(rename="canonicalUrl")]
|
||
pub canonical_url: Option<String>,
|
||
/// Opaque string you can use to map a timeline item to data in your own service.
|
||
#[serde(rename="sourceItemId")]
|
||
pub source_item_id: Option<String>,
|
||
}
|
||
|
||
impl RequestValue for TimelineItem {}
|
||
impl ResponseResult for TimelineItem {}
|
||
|
||
|
||
/// A person or group that can be used as a creator or a contact.
|
||
///
|
||
/// # 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*).
|
||
///
|
||
/// * [insert contacts](struct.ContactInsertCall.html) (request|response)
|
||
/// * [delete contacts](struct.ContactDeleteCall.html) (none)
|
||
/// * [list contacts](struct.ContactListCall.html) (none)
|
||
/// * [update contacts](struct.ContactUpdateCall.html) (request|response)
|
||
/// * [patch contacts](struct.ContactPatchCall.html) (request|response)
|
||
/// * [get contacts](struct.ContactGetCall.html) (response)
|
||
///
|
||
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
|
||
pub struct Contact {
|
||
/// The type of resource. This is always mirror#contact.
|
||
pub kind: Option<String>,
|
||
/// The name to display for this contact.
|
||
#[serde(rename="displayName")]
|
||
pub display_name: Option<String>,
|
||
/// A list of MIME types that a contact supports. The contact will be shown to the user if any of its acceptTypes matches any of the types of the attachments on the item. If no acceptTypes are given, the contact will be shown for all items.
|
||
#[serde(rename="acceptTypes")]
|
||
pub accept_types: Option<Vec<String>>,
|
||
/// A list of voice menu commands that a contact can handle. Glass shows up to three contacts for each voice menu command. If there are more than that, the three contacts with the highest priority are shown for that particular command.
|
||
#[serde(rename="acceptCommands")]
|
||
pub accept_commands: Option<Vec<Command>>,
|
||
/// Priority for the contact to determine ordering in a list of contacts. Contacts with higher priorities will be shown before ones with lower priorities.
|
||
pub priority: Option<u32>,
|
||
/// The ID of the application that created this contact. This is populated by the API
|
||
pub source: Option<String>,
|
||
/// Primary phone number for the contact. This can be a fully-qualified number, with country calling code and area code, or a local number.
|
||
#[serde(rename="phoneNumber")]
|
||
pub phone_number: Option<String>,
|
||
/// A list of sharing features that a contact can handle. Allowed values are:
|
||
/// - ADD_CAPTION
|
||
#[serde(rename="sharingFeatures")]
|
||
pub sharing_features: Option<Vec<String>>,
|
||
/// The type for this contact. This is used for sorting in UIs. Allowed values are:
|
||
/// - INDIVIDUAL - Represents a single person. This is the default.
|
||
/// - GROUP - Represents more than a single person.
|
||
#[serde(rename="type")]
|
||
pub type_: Option<String>,
|
||
/// Set of image URLs to display for a contact. Most contacts will have a single image, but a "group" contact may include up to 8 image URLs and they will be resized and cropped into a mosaic on the client.
|
||
#[serde(rename="imageUrls")]
|
||
pub image_urls: Option<Vec<String>>,
|
||
/// An ID for this contact. This is generated by the application and is treated as an opaque token.
|
||
pub id: Option<String>,
|
||
/// Name of this contact as it should be pronounced. If this contact's name must be spoken as part of a voice disambiguation menu, this name is used as the expected pronunciation. This is useful for contact names with unpronounceable characters or whose display spelling is otherwise not phonetic.
|
||
#[serde(rename="speakableName")]
|
||
pub speakable_name: Option<String>,
|
||
}
|
||
|
||
impl RequestValue for Contact {}
|
||
impl Resource for Contact {}
|
||
impl ResponseResult for Contact {}
|
||
|
||
|
||
/// A single menu command that is part of a Contact.
|
||
///
|
||
/// This type is not used in any activity, and only used as *part* of another schema.
|
||
///
|
||
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
|
||
pub struct Command {
|
||
/// The type of operation this command corresponds to. Allowed values are:
|
||
/// - TAKE_A_NOTE - Shares a timeline item with the transcription of user speech from the "Take a note" voice menu command.
|
||
/// - POST_AN_UPDATE - Shares a timeline item with the transcription of user speech from the "Post an update" voice menu command.
|
||
#[serde(rename="type")]
|
||
pub type_: Option<String>,
|
||
}
|
||
|
||
impl Part for Command {}
|
||
|
||
|
||
/// A geographic location that can be associated with a timeline item.
|
||
///
|
||
/// # 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*).
|
||
///
|
||
/// * [get locations](struct.LocationGetCall.html) (response)
|
||
/// * [list locations](struct.LocationListCall.html) (none)
|
||
///
|
||
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
|
||
pub struct Location {
|
||
/// The type of resource. This is always mirror#location.
|
||
pub kind: Option<String>,
|
||
/// The name to be displayed. This may be a business name or a user-defined place, such as "Home".
|
||
#[serde(rename="displayName")]
|
||
pub display_name: Option<String>,
|
||
/// The time at which this location was captured, formatted according to RFC 3339.
|
||
pub timestamp: Option<String>,
|
||
/// The longitude, in degrees.
|
||
pub longitude: Option<f64>,
|
||
/// The full address of the location.
|
||
pub address: Option<String>,
|
||
/// The latitude, in degrees.
|
||
pub latitude: Option<f64>,
|
||
/// The ID of the location.
|
||
pub id: Option<String>,
|
||
/// The accuracy of the location fix in meters.
|
||
pub accuracy: Option<f64>,
|
||
}
|
||
|
||
impl Resource for Location {}
|
||
impl ResponseResult for Location {}
|
||
|
||
|
||
/// A list of Subscriptions. This is the response from the server to GET requests on the subscription collection.
|
||
///
|
||
/// # 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 subscriptions](struct.SubscriptionListCall.html) (response)
|
||
///
|
||
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
|
||
pub struct SubscriptionsListResponse {
|
||
/// The list of subscriptions.
|
||
pub items: Option<Vec<Subscription>>,
|
||
/// The type of resource. This is always mirror#subscriptionsList.
|
||
pub kind: Option<String>,
|
||
}
|
||
|
||
impl ResponseResult for SubscriptionsListResponse {}
|
||
|
||
|
||
/// There is no detailed description.
|
||
///
|
||
/// This type is not used in any activity, and only used as *part* of another schema.
|
||
///
|
||
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
|
||
pub struct AuthToken {
|
||
/// no description provided
|
||
#[serde(rename="authToken")]
|
||
pub auth_token: Option<String>,
|
||
/// no description provided
|
||
#[serde(rename="type")]
|
||
pub type_: Option<String>,
|
||
}
|
||
|
||
impl Part for AuthToken {}
|
||
|
||
|
||
/// There is no detailed description.
|
||
///
|
||
/// This type is not used in any activity, and only used as *part* of another schema.
|
||
///
|
||
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
|
||
pub struct UserData {
|
||
/// no description provided
|
||
pub key: Option<String>,
|
||
/// no description provided
|
||
pub value: Option<String>,
|
||
}
|
||
|
||
impl Part for UserData {}
|
||
|
||
|
||
/// A list of Attachments. This is the response from the server to GET requests on the attachments collection.
|
||
///
|
||
/// # 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*).
|
||
///
|
||
/// * [attachments list timeline](struct.TimelineAttachmentListCall.html) (response)
|
||
///
|
||
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
|
||
pub struct AttachmentsListResponse {
|
||
/// The list of attachments.
|
||
pub items: Option<Vec<Attachment>>,
|
||
/// The type of resource. This is always mirror#attachmentsList.
|
||
pub kind: Option<String>,
|
||
}
|
||
|
||
impl ResponseResult for AttachmentsListResponse {}
|
||
|
||
|
||
/// Controls how notifications for a timeline item are presented to the 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 NotificationConfig {
|
||
/// The time at which the notification should be delivered.
|
||
#[serde(rename="deliveryTime")]
|
||
pub delivery_time: Option<String>,
|
||
/// Describes how important the notification is. Allowed values are:
|
||
/// - DEFAULT - Notifications of default importance. A chime will be played to alert users.
|
||
pub level: Option<String>,
|
||
}
|
||
|
||
impl Part for NotificationConfig {}
|
||
|
||
|
||
/// A setting for Glass.
|
||
///
|
||
/// # 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*).
|
||
///
|
||
/// * [get settings](struct.SettingGetCall.html) (response)
|
||
///
|
||
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
|
||
pub struct Setting {
|
||
/// The type of resource. This is always mirror#setting.
|
||
pub kind: Option<String>,
|
||
/// The setting's ID. The following IDs are valid:
|
||
/// - locale - The key to the user’s language/locale (BCP 47 identifier) that Glassware should use to render localized content.
|
||
/// - timezone - The key to the user’s current time zone region as defined in the tz database. Example: America/Los_Angeles.
|
||
pub id: Option<String>,
|
||
/// The setting value, as a string.
|
||
pub value: Option<String>,
|
||
}
|
||
|
||
impl Resource for Setting {}
|
||
impl ResponseResult for Setting {}
|
||
|
||
|
||
/// A custom menu item that can be presented to the user by a timeline 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 MenuItem {
|
||
/// The ContextualMenus.Command associated with this MenuItem (e.g. READ_ALOUD). The voice label for this command will be displayed in the voice menu and the touch label will be displayed in the touch menu. Note that the default menu value's display name will be overriden if you specify this property. Values that do not correspond to a ContextualMenus.Command name will be ignored.
|
||
pub contextual_command: Option<String>,
|
||
/// For CUSTOM items, a list of values controlling the appearance of the menu item in each of its states. A value for the DEFAULT state must be provided. If the PENDING or CONFIRMED states are missing, they will not be shown.
|
||
pub values: Option<Vec<MenuValue>>,
|
||
/// If set to true on a CUSTOM menu item, that item will be removed from the menu after it is selected.
|
||
#[serde(rename="removeWhenSelected")]
|
||
pub remove_when_selected: Option<bool>,
|
||
/// Controls the behavior when the user picks the menu option. Allowed values are:
|
||
/// - CUSTOM - Custom action set by the service. When the user selects this menuItem, the API triggers a notification to your callbackUrl with the userActions.type set to CUSTOM and the userActions.payload set to the ID of this menu item. This is the default value.
|
||
/// - Built-in actions:
|
||
/// - REPLY - Initiate a reply to the timeline item using the voice recording UI. The creator attribute must be set in the timeline item for this menu to be available.
|
||
/// - REPLY_ALL - Same behavior as REPLY. The original timeline item's recipients will be added to the reply item.
|
||
/// - DELETE - Delete the timeline item.
|
||
/// - SHARE - Share the timeline item with the available contacts.
|
||
/// - READ_ALOUD - Read the timeline item's speakableText aloud; if this field is not set, read the text field; if none of those fields are set, this menu item is ignored.
|
||
/// - GET_MEDIA_INPUT - Allow users to provide media payloads to Glassware from a menu item (currently, only transcribed text from voice input is supported). Subscribe to notifications when users invoke this menu item to receive the timeline item ID. Retrieve the media from the timeline item in the payload property.
|
||
/// - VOICE_CALL - Initiate a phone call using the timeline item's creator.phoneNumber attribute as recipient.
|
||
/// - NAVIGATE - Navigate to the timeline item's location.
|
||
/// - TOGGLE_PINNED - Toggle the isPinned state of the timeline item.
|
||
/// - OPEN_URI - Open the payload of the menu item in the browser.
|
||
/// - PLAY_VIDEO - Open the payload of the menu item in the Glass video player.
|
||
/// - SEND_MESSAGE - Initiate sending a message to the timeline item's creator:
|
||
/// - If the creator.phoneNumber is set and Glass is connected to an Android phone, the message is an SMS.
|
||
/// - Otherwise, if the creator.email is set, the message is an email.
|
||
pub action: Option<String>,
|
||
/// A generic payload whose meaning changes depending on this MenuItem's action.
|
||
/// - When the action is OPEN_URI, the payload is the URL of the website to view.
|
||
/// - When the action is PLAY_VIDEO, the payload is the streaming URL of the video
|
||
/// - When the action is GET_MEDIA_INPUT, the payload is the text transcription of a user's speech input
|
||
pub payload: Option<String>,
|
||
/// The ID for this menu item. This is generated by the application and is treated as an opaque token.
|
||
pub id: Option<String>,
|
||
}
|
||
|
||
impl Part for MenuItem {}
|
||
|
||
|
||
/// A list of Locations. This is the response from the server to GET requests on the locations collection.
|
||
///
|
||
/// # 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 locations](struct.LocationListCall.html) (response)
|
||
///
|
||
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
|
||
pub struct LocationsListResponse {
|
||
/// The list of locations.
|
||
pub items: Option<Vec<Location>>,
|
||
/// The type of resource. This is always mirror#locationsList.
|
||
pub kind: Option<String>,
|
||
}
|
||
|
||
impl ResponseResult for LocationsListResponse {}
|
||
|
||
|
||
/// A single value that is part of a MenuItem.
|
||
///
|
||
/// This type is not used in any activity, and only used as *part* of another schema.
|
||
///
|
||
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
|
||
pub struct MenuValue {
|
||
/// URL of an icon to display with the menu item.
|
||
#[serde(rename="iconUrl")]
|
||
pub icon_url: Option<String>,
|
||
/// The state that this value applies to. Allowed values are:
|
||
/// - DEFAULT - Default value shown when displayed in the menuItems list.
|
||
/// - PENDING - Value shown when the menuItem has been selected by the user but can still be cancelled.
|
||
/// - CONFIRMED - Value shown when the menuItem has been selected by the user and can no longer be cancelled.
|
||
pub state: Option<String>,
|
||
/// The name to display for the menu item. If you specify this property for a built-in menu item, the default contextual voice command for that menu item is not shown.
|
||
#[serde(rename="displayName")]
|
||
pub display_name: Option<String>,
|
||
}
|
||
|
||
impl Part for MenuValue {}
|
||
|
||
|
||
/// A subscription to events on a collection.
|
||
///
|
||
/// # 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*).
|
||
///
|
||
/// * [insert subscriptions](struct.SubscriptionInsertCall.html) (request|response)
|
||
/// * [delete subscriptions](struct.SubscriptionDeleteCall.html) (none)
|
||
/// * [list subscriptions](struct.SubscriptionListCall.html) (none)
|
||
/// * [update subscriptions](struct.SubscriptionUpdateCall.html) (request|response)
|
||
///
|
||
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
|
||
pub struct Subscription {
|
||
/// The type of resource. This is always mirror#subscription.
|
||
pub kind: Option<String>,
|
||
/// Container object for notifications. This is not populated in the Subscription resource.
|
||
pub notification: Option<Notification>,
|
||
/// The time at which this subscription was last modified, formatted according to RFC 3339.
|
||
pub updated: Option<String>,
|
||
/// The collection to subscribe to. Allowed values are:
|
||
/// - timeline - Changes in the timeline including insertion, deletion, and updates.
|
||
/// - locations - Location updates.
|
||
/// - settings - Settings updates.
|
||
pub collection: Option<String>,
|
||
/// A secret token sent to the subscriber in notifications so that it can verify that the notification was generated by Google.
|
||
#[serde(rename="verifyToken")]
|
||
pub verify_token: Option<String>,
|
||
/// An opaque token sent to the subscriber in notifications so that it can determine the ID of the user.
|
||
#[serde(rename="userToken")]
|
||
pub user_token: Option<String>,
|
||
/// A list of operations that should be subscribed to. An empty list indicates that all operations on the collection should be subscribed to. Allowed values are:
|
||
/// - UPDATE - The item has been updated.
|
||
/// - INSERT - A new item has been inserted.
|
||
/// - DELETE - The item has been deleted.
|
||
/// - MENU_ACTION - A custom menu item has been triggered by the user.
|
||
pub operation: Option<Vec<String>>,
|
||
/// The ID of the subscription.
|
||
pub id: Option<String>,
|
||
/// The URL where notifications should be delivered (must start with https://).
|
||
#[serde(rename="callbackUrl")]
|
||
pub callback_url: Option<String>,
|
||
}
|
||
|
||
impl RequestValue for Subscription {}
|
||
impl Resource for Subscription {}
|
||
impl ResponseResult for Subscription {}
|
||
|
||
|
||
|
||
// ###################
|
||
// MethodBuilders ###
|
||
// #################
|
||
|
||
/// A builder providing access to all methods supported on *subscription* resources.
|
||
/// It is not used directly, but through the `Mirror` hub.
|
||
///
|
||
/// # Example
|
||
///
|
||
/// Instantiate a resource builder
|
||
///
|
||
/// ```test_harness,no_run
|
||
/// extern crate hyper;
|
||
/// extern crate yup_oauth2 as oauth2;
|
||
/// extern crate google_mirror1 as mirror1;
|
||
///
|
||
/// # #[test] fn egal() {
|
||
/// use std::default::Default;
|
||
/// use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage};
|
||
/// use mirror1::Mirror;
|
||
///
|
||
/// let secret: ApplicationSecret = Default::default();
|
||
/// let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate,
|
||
/// hyper::Client::new(),
|
||
/// <MemoryStorage as Default>::default(), None);
|
||
/// let mut hub = Mirror::new(hyper::Client::new(), auth);
|
||
/// // Usually you wouldn't bind this to a variable, but keep calling *CallBuilders*
|
||
/// // like `delete(...)`, `insert(...)`, `list(...)` and `update(...)`
|
||
/// // to build up your call.
|
||
/// let rb = hub.subscriptions();
|
||
/// # }
|
||
/// ```
|
||
pub struct SubscriptionMethods<'a, C, A>
|
||
where C: 'a, A: 'a {
|
||
|
||
hub: &'a Mirror<C, A>,
|
||
}
|
||
|
||
impl<'a, C, A> MethodsBuilder for SubscriptionMethods<'a, C, A> {}
|
||
|
||
impl<'a, C, A> SubscriptionMethods<'a, C, A> {
|
||
|
||
/// Create a builder to help you perform the following task:
|
||
///
|
||
/// Creates a new subscription.
|
||
///
|
||
/// # Arguments
|
||
///
|
||
/// * `request` - No description provided.
|
||
pub fn insert(&self, request: Subscription) -> SubscriptionInsertCall<'a, C, A> {
|
||
SubscriptionInsertCall {
|
||
hub: self.hub,
|
||
_request: request,
|
||
_delegate: Default::default(),
|
||
_scopes: Default::default(),
|
||
_additional_params: Default::default(),
|
||
}
|
||
}
|
||
|
||
/// Create a builder to help you perform the following task:
|
||
///
|
||
/// Deletes a subscription.
|
||
///
|
||
/// # Arguments
|
||
///
|
||
/// * `id` - The ID of the subscription.
|
||
pub fn delete(&self, id: &str) -> SubscriptionDeleteCall<'a, C, A> {
|
||
SubscriptionDeleteCall {
|
||
hub: self.hub,
|
||
_id: id.to_string(),
|
||
_delegate: Default::default(),
|
||
_scopes: Default::default(),
|
||
_additional_params: Default::default(),
|
||
}
|
||
}
|
||
|
||
/// Create a builder to help you perform the following task:
|
||
///
|
||
/// Updates an existing subscription in place.
|
||
///
|
||
/// # Arguments
|
||
///
|
||
/// * `request` - No description provided.
|
||
/// * `id` - The ID of the subscription.
|
||
pub fn update(&self, request: Subscription, id: &str) -> SubscriptionUpdateCall<'a, C, A> {
|
||
SubscriptionUpdateCall {
|
||
hub: self.hub,
|
||
_request: request,
|
||
_id: id.to_string(),
|
||
_delegate: Default::default(),
|
||
_scopes: Default::default(),
|
||
_additional_params: Default::default(),
|
||
}
|
||
}
|
||
|
||
/// Create a builder to help you perform the following task:
|
||
///
|
||
/// Retrieves a list of subscriptions for the authenticated user and service.
|
||
pub fn list(&self) -> SubscriptionListCall<'a, C, A> {
|
||
SubscriptionListCall {
|
||
hub: self.hub,
|
||
_delegate: Default::default(),
|
||
_scopes: Default::default(),
|
||
_additional_params: Default::default(),
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
|
||
/// A builder providing access to all methods supported on *timeline* resources.
|
||
/// It is not used directly, but through the `Mirror` hub.
|
||
///
|
||
/// # Example
|
||
///
|
||
/// Instantiate a resource builder
|
||
///
|
||
/// ```test_harness,no_run
|
||
/// extern crate hyper;
|
||
/// extern crate yup_oauth2 as oauth2;
|
||
/// extern crate google_mirror1 as mirror1;
|
||
///
|
||
/// # #[test] fn egal() {
|
||
/// use std::default::Default;
|
||
/// use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage};
|
||
/// use mirror1::Mirror;
|
||
///
|
||
/// let secret: ApplicationSecret = Default::default();
|
||
/// let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate,
|
||
/// hyper::Client::new(),
|
||
/// <MemoryStorage as Default>::default(), None);
|
||
/// let mut hub = Mirror::new(hyper::Client::new(), auth);
|
||
/// // Usually you wouldn't bind this to a variable, but keep calling *CallBuilders*
|
||
/// // like `attachments_delete(...)`, `attachments_get(...)`, `attachments_insert(...)`, `attachments_list(...)`, `delete(...)`, `get(...)`, `insert(...)`, `list(...)`, `patch(...)` and `update(...)`
|
||
/// // to build up your call.
|
||
/// let rb = hub.timeline();
|
||
/// # }
|
||
/// ```
|
||
pub struct TimelineMethods<'a, C, A>
|
||
where C: 'a, A: 'a {
|
||
|
||
hub: &'a Mirror<C, A>,
|
||
}
|
||
|
||
impl<'a, C, A> MethodsBuilder for TimelineMethods<'a, C, A> {}
|
||
|
||
impl<'a, C, A> TimelineMethods<'a, C, A> {
|
||
|
||
/// Create a builder to help you perform the following task:
|
||
///
|
||
/// Returns a list of attachments for a timeline item.
|
||
///
|
||
/// # Arguments
|
||
///
|
||
/// * `itemId` - The ID of the timeline item whose attachments should be listed.
|
||
pub fn attachments_list(&self, item_id: &str) -> TimelineAttachmentListCall<'a, C, A> {
|
||
TimelineAttachmentListCall {
|
||
hub: self.hub,
|
||
_item_id: item_id.to_string(),
|
||
_delegate: Default::default(),
|
||
_scopes: Default::default(),
|
||
_additional_params: Default::default(),
|
||
}
|
||
}
|
||
|
||
/// Create a builder to help you perform the following task:
|
||
///
|
||
/// Inserts a new item into the timeline.
|
||
///
|
||
/// # Arguments
|
||
///
|
||
/// * `request` - No description provided.
|
||
pub fn insert(&self, request: TimelineItem) -> TimelineInsertCall<'a, C, A> {
|
||
TimelineInsertCall {
|
||
hub: self.hub,
|
||
_request: request,
|
||
_delegate: Default::default(),
|
||
_scopes: Default::default(),
|
||
_additional_params: Default::default(),
|
||
}
|
||
}
|
||
|
||
/// Create a builder to help you perform the following task:
|
||
///
|
||
/// Updates a timeline item in place. This method supports patch semantics.
|
||
///
|
||
/// # Arguments
|
||
///
|
||
/// * `request` - No description provided.
|
||
/// * `id` - The ID of the timeline item.
|
||
pub fn patch(&self, request: TimelineItem, id: &str) -> TimelinePatchCall<'a, C, A> {
|
||
TimelinePatchCall {
|
||
hub: self.hub,
|
||
_request: request,
|
||
_id: id.to_string(),
|
||
_delegate: Default::default(),
|
||
_scopes: Default::default(),
|
||
_additional_params: Default::default(),
|
||
}
|
||
}
|
||
|
||
/// Create a builder to help you perform the following task:
|
||
///
|
||
/// Retrieves a list of timeline items for the authenticated user.
|
||
pub fn list(&self) -> TimelineListCall<'a, C, A> {
|
||
TimelineListCall {
|
||
hub: self.hub,
|
||
_source_item_id: Default::default(),
|
||
_pinned_only: Default::default(),
|
||
_page_token: Default::default(),
|
||
_order_by: Default::default(),
|
||
_max_results: Default::default(),
|
||
_include_deleted: Default::default(),
|
||
_bundle_id: Default::default(),
|
||
_delegate: Default::default(),
|
||
_scopes: Default::default(),
|
||
_additional_params: Default::default(),
|
||
}
|
||
}
|
||
|
||
/// Create a builder to help you perform the following task:
|
||
///
|
||
/// Adds a new attachment to a timeline item.
|
||
///
|
||
/// # Arguments
|
||
///
|
||
/// * `itemId` - The ID of the timeline item the attachment belongs to.
|
||
pub fn attachments_insert(&self, item_id: &str) -> TimelineAttachmentInsertCall<'a, C, A> {
|
||
TimelineAttachmentInsertCall {
|
||
hub: self.hub,
|
||
_item_id: item_id.to_string(),
|
||
_delegate: Default::default(),
|
||
_scopes: Default::default(),
|
||
_additional_params: Default::default(),
|
||
}
|
||
}
|
||
|
||
/// Create a builder to help you perform the following task:
|
||
///
|
||
/// Deletes an attachment from a timeline item.
|
||
///
|
||
/// # Arguments
|
||
///
|
||
/// * `itemId` - The ID of the timeline item the attachment belongs to.
|
||
/// * `attachmentId` - The ID of the attachment.
|
||
pub fn attachments_delete(&self, item_id: &str, attachment_id: &str) -> TimelineAttachmentDeleteCall<'a, C, A> {
|
||
TimelineAttachmentDeleteCall {
|
||
hub: self.hub,
|
||
_item_id: item_id.to_string(),
|
||
_attachment_id: attachment_id.to_string(),
|
||
_delegate: Default::default(),
|
||
_scopes: Default::default(),
|
||
_additional_params: Default::default(),
|
||
}
|
||
}
|
||
|
||
/// Create a builder to help you perform the following task:
|
||
///
|
||
/// Deletes a timeline item.
|
||
///
|
||
/// # Arguments
|
||
///
|
||
/// * `id` - The ID of the timeline item.
|
||
pub fn delete(&self, id: &str) -> TimelineDeleteCall<'a, C, A> {
|
||
TimelineDeleteCall {
|
||
hub: self.hub,
|
||
_id: id.to_string(),
|
||
_delegate: Default::default(),
|
||
_scopes: Default::default(),
|
||
_additional_params: Default::default(),
|
||
}
|
||
}
|
||
|
||
/// Create a builder to help you perform the following task:
|
||
///
|
||
/// Updates a timeline item in place.
|
||
///
|
||
/// # Arguments
|
||
///
|
||
/// * `request` - No description provided.
|
||
/// * `id` - The ID of the timeline item.
|
||
pub fn update(&self, request: TimelineItem, id: &str) -> TimelineUpdateCall<'a, C, A> {
|
||
TimelineUpdateCall {
|
||
hub: self.hub,
|
||
_request: request,
|
||
_id: id.to_string(),
|
||
_delegate: Default::default(),
|
||
_scopes: Default::default(),
|
||
_additional_params: Default::default(),
|
||
}
|
||
}
|
||
|
||
/// Create a builder to help you perform the following task:
|
||
///
|
||
/// Retrieves an attachment on a timeline item by item ID and attachment ID.
|
||
///
|
||
/// # Arguments
|
||
///
|
||
/// * `itemId` - The ID of the timeline item the attachment belongs to.
|
||
/// * `attachmentId` - The ID of the attachment.
|
||
pub fn attachments_get(&self, item_id: &str, attachment_id: &str) -> TimelineAttachmentGetCall<'a, C, A> {
|
||
TimelineAttachmentGetCall {
|
||
hub: self.hub,
|
||
_item_id: item_id.to_string(),
|
||
_attachment_id: attachment_id.to_string(),
|
||
_delegate: Default::default(),
|
||
_scopes: Default::default(),
|
||
_additional_params: Default::default(),
|
||
}
|
||
}
|
||
|
||
/// Create a builder to help you perform the following task:
|
||
///
|
||
/// Gets a single timeline item by ID.
|
||
///
|
||
/// # Arguments
|
||
///
|
||
/// * `id` - The ID of the timeline item.
|
||
pub fn get(&self, id: &str) -> TimelineGetCall<'a, C, A> {
|
||
TimelineGetCall {
|
||
hub: self.hub,
|
||
_id: id.to_string(),
|
||
_delegate: Default::default(),
|
||
_scopes: Default::default(),
|
||
_additional_params: Default::default(),
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
|
||
/// A builder providing access to all methods supported on *setting* resources.
|
||
/// It is not used directly, but through the `Mirror` hub.
|
||
///
|
||
/// # Example
|
||
///
|
||
/// Instantiate a resource builder
|
||
///
|
||
/// ```test_harness,no_run
|
||
/// extern crate hyper;
|
||
/// extern crate yup_oauth2 as oauth2;
|
||
/// extern crate google_mirror1 as mirror1;
|
||
///
|
||
/// # #[test] fn egal() {
|
||
/// use std::default::Default;
|
||
/// use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage};
|
||
/// use mirror1::Mirror;
|
||
///
|
||
/// let secret: ApplicationSecret = Default::default();
|
||
/// let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate,
|
||
/// hyper::Client::new(),
|
||
/// <MemoryStorage as Default>::default(), None);
|
||
/// let mut hub = Mirror::new(hyper::Client::new(), auth);
|
||
/// // Usually you wouldn't bind this to a variable, but keep calling *CallBuilders*
|
||
/// // like `get(...)`
|
||
/// // to build up your call.
|
||
/// let rb = hub.settings();
|
||
/// # }
|
||
/// ```
|
||
pub struct SettingMethods<'a, C, A>
|
||
where C: 'a, A: 'a {
|
||
|
||
hub: &'a Mirror<C, A>,
|
||
}
|
||
|
||
impl<'a, C, A> MethodsBuilder for SettingMethods<'a, C, A> {}
|
||
|
||
impl<'a, C, A> SettingMethods<'a, C, A> {
|
||
|
||
/// Create a builder to help you perform the following task:
|
||
///
|
||
/// Gets a single setting by ID.
|
||
///
|
||
/// # Arguments
|
||
///
|
||
/// * `id` - The ID of the setting. The following IDs are valid:
|
||
/// - locale - The key to the user’s language/locale (BCP 47 identifier) that Glassware should use to render localized content.
|
||
/// - timezone - The key to the user’s current time zone region as defined in the tz database. Example: America/Los_Angeles.
|
||
pub fn get(&self, id: &str) -> SettingGetCall<'a, C, A> {
|
||
SettingGetCall {
|
||
hub: self.hub,
|
||
_id: id.to_string(),
|
||
_delegate: Default::default(),
|
||
_scopes: Default::default(),
|
||
_additional_params: Default::default(),
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
|
||
/// A builder providing access to all methods supported on *location* resources.
|
||
/// It is not used directly, but through the `Mirror` hub.
|
||
///
|
||
/// # Example
|
||
///
|
||
/// Instantiate a resource builder
|
||
///
|
||
/// ```test_harness,no_run
|
||
/// extern crate hyper;
|
||
/// extern crate yup_oauth2 as oauth2;
|
||
/// extern crate google_mirror1 as mirror1;
|
||
///
|
||
/// # #[test] fn egal() {
|
||
/// use std::default::Default;
|
||
/// use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage};
|
||
/// use mirror1::Mirror;
|
||
///
|
||
/// let secret: ApplicationSecret = Default::default();
|
||
/// let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate,
|
||
/// hyper::Client::new(),
|
||
/// <MemoryStorage as Default>::default(), None);
|
||
/// let mut hub = Mirror::new(hyper::Client::new(), auth);
|
||
/// // Usually you wouldn't bind this to a variable, but keep calling *CallBuilders*
|
||
/// // like `get(...)` and `list(...)`
|
||
/// // to build up your call.
|
||
/// let rb = hub.locations();
|
||
/// # }
|
||
/// ```
|
||
pub struct LocationMethods<'a, C, A>
|
||
where C: 'a, A: 'a {
|
||
|
||
hub: &'a Mirror<C, A>,
|
||
}
|
||
|
||
impl<'a, C, A> MethodsBuilder for LocationMethods<'a, C, A> {}
|
||
|
||
impl<'a, C, A> LocationMethods<'a, C, A> {
|
||
|
||
/// Create a builder to help you perform the following task:
|
||
///
|
||
/// Gets a single location by ID.
|
||
///
|
||
/// # Arguments
|
||
///
|
||
/// * `id` - The ID of the location or latest for the last known location.
|
||
pub fn get(&self, id: &str) -> LocationGetCall<'a, C, A> {
|
||
LocationGetCall {
|
||
hub: self.hub,
|
||
_id: id.to_string(),
|
||
_delegate: Default::default(),
|
||
_scopes: Default::default(),
|
||
_additional_params: Default::default(),
|
||
}
|
||
}
|
||
|
||
/// Create a builder to help you perform the following task:
|
||
///
|
||
/// Retrieves a list of locations for the user.
|
||
pub fn list(&self) -> LocationListCall<'a, C, A> {
|
||
LocationListCall {
|
||
hub: self.hub,
|
||
_delegate: Default::default(),
|
||
_scopes: Default::default(),
|
||
_additional_params: Default::default(),
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
|
||
/// A builder providing access to all methods supported on *account* resources.
|
||
/// It is not used directly, but through the `Mirror` hub.
|
||
///
|
||
/// # Example
|
||
///
|
||
/// Instantiate a resource builder
|
||
///
|
||
/// ```test_harness,no_run
|
||
/// extern crate hyper;
|
||
/// extern crate yup_oauth2 as oauth2;
|
||
/// extern crate google_mirror1 as mirror1;
|
||
///
|
||
/// # #[test] fn egal() {
|
||
/// use std::default::Default;
|
||
/// use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage};
|
||
/// use mirror1::Mirror;
|
||
///
|
||
/// let secret: ApplicationSecret = Default::default();
|
||
/// let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate,
|
||
/// hyper::Client::new(),
|
||
/// <MemoryStorage as Default>::default(), None);
|
||
/// let mut hub = Mirror::new(hyper::Client::new(), auth);
|
||
/// // Usually you wouldn't bind this to a variable, but keep calling *CallBuilders*
|
||
/// // like `insert(...)`
|
||
/// // to build up your call.
|
||
/// let rb = hub.accounts();
|
||
/// # }
|
||
/// ```
|
||
pub struct AccountMethods<'a, C, A>
|
||
where C: 'a, A: 'a {
|
||
|
||
hub: &'a Mirror<C, A>,
|
||
}
|
||
|
||
impl<'a, C, A> MethodsBuilder for AccountMethods<'a, C, A> {}
|
||
|
||
impl<'a, C, A> AccountMethods<'a, C, A> {
|
||
|
||
/// Create a builder to help you perform the following task:
|
||
///
|
||
/// Inserts a new account for a user
|
||
///
|
||
/// # Arguments
|
||
///
|
||
/// * `request` - No description provided.
|
||
/// * `userToken` - The ID for the user.
|
||
/// * `accountType` - Account type to be passed to Android Account Manager.
|
||
/// * `accountName` - The name of the account to be passed to the Android Account Manager.
|
||
pub fn insert(&self, request: Account, user_token: &str, account_type: &str, account_name: &str) -> AccountInsertCall<'a, C, A> {
|
||
AccountInsertCall {
|
||
hub: self.hub,
|
||
_request: request,
|
||
_user_token: user_token.to_string(),
|
||
_account_type: account_type.to_string(),
|
||
_account_name: account_name.to_string(),
|
||
_delegate: Default::default(),
|
||
_additional_params: Default::default(),
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
|
||
/// A builder providing access to all methods supported on *contact* resources.
|
||
/// It is not used directly, but through the `Mirror` hub.
|
||
///
|
||
/// # Example
|
||
///
|
||
/// Instantiate a resource builder
|
||
///
|
||
/// ```test_harness,no_run
|
||
/// extern crate hyper;
|
||
/// extern crate yup_oauth2 as oauth2;
|
||
/// extern crate google_mirror1 as mirror1;
|
||
///
|
||
/// # #[test] fn egal() {
|
||
/// use std::default::Default;
|
||
/// use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage};
|
||
/// use mirror1::Mirror;
|
||
///
|
||
/// let secret: ApplicationSecret = Default::default();
|
||
/// let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate,
|
||
/// hyper::Client::new(),
|
||
/// <MemoryStorage as Default>::default(), None);
|
||
/// let mut hub = Mirror::new(hyper::Client::new(), auth);
|
||
/// // Usually you wouldn't bind this to a variable, but keep calling *CallBuilders*
|
||
/// // like `delete(...)`, `get(...)`, `insert(...)`, `list(...)`, `patch(...)` and `update(...)`
|
||
/// // to build up your call.
|
||
/// let rb = hub.contacts();
|
||
/// # }
|
||
/// ```
|
||
pub struct ContactMethods<'a, C, A>
|
||
where C: 'a, A: 'a {
|
||
|
||
hub: &'a Mirror<C, A>,
|
||
}
|
||
|
||
impl<'a, C, A> MethodsBuilder for ContactMethods<'a, C, A> {}
|
||
|
||
impl<'a, C, A> ContactMethods<'a, C, A> {
|
||
|
||
/// Create a builder to help you perform the following task:
|
||
///
|
||
/// Gets a single contact by ID.
|
||
///
|
||
/// # Arguments
|
||
///
|
||
/// * `id` - The ID of the contact.
|
||
pub fn get(&self, id: &str) -> ContactGetCall<'a, C, A> {
|
||
ContactGetCall {
|
||
hub: self.hub,
|
||
_id: id.to_string(),
|
||
_delegate: Default::default(),
|
||
_scopes: Default::default(),
|
||
_additional_params: Default::default(),
|
||
}
|
||
}
|
||
|
||
/// Create a builder to help you perform the following task:
|
||
///
|
||
/// Deletes a contact.
|
||
///
|
||
/// # Arguments
|
||
///
|
||
/// * `id` - The ID of the contact.
|
||
pub fn delete(&self, id: &str) -> ContactDeleteCall<'a, C, A> {
|
||
ContactDeleteCall {
|
||
hub: self.hub,
|
||
_id: id.to_string(),
|
||
_delegate: Default::default(),
|
||
_scopes: Default::default(),
|
||
_additional_params: Default::default(),
|
||
}
|
||
}
|
||
|
||
/// Create a builder to help you perform the following task:
|
||
///
|
||
/// Inserts a new contact.
|
||
///
|
||
/// # Arguments
|
||
///
|
||
/// * `request` - No description provided.
|
||
pub fn insert(&self, request: Contact) -> ContactInsertCall<'a, C, A> {
|
||
ContactInsertCall {
|
||
hub: self.hub,
|
||
_request: request,
|
||
_delegate: Default::default(),
|
||
_scopes: Default::default(),
|
||
_additional_params: Default::default(),
|
||
}
|
||
}
|
||
|
||
/// Create a builder to help you perform the following task:
|
||
///
|
||
/// Updates a contact in place. This method supports patch semantics.
|
||
///
|
||
/// # Arguments
|
||
///
|
||
/// * `request` - No description provided.
|
||
/// * `id` - The ID of the contact.
|
||
pub fn patch(&self, request: Contact, id: &str) -> ContactPatchCall<'a, C, A> {
|
||
ContactPatchCall {
|
||
hub: self.hub,
|
||
_request: request,
|
||
_id: id.to_string(),
|
||
_delegate: Default::default(),
|
||
_scopes: Default::default(),
|
||
_additional_params: Default::default(),
|
||
}
|
||
}
|
||
|
||
/// Create a builder to help you perform the following task:
|
||
///
|
||
/// Retrieves a list of contacts for the authenticated user.
|
||
pub fn list(&self) -> ContactListCall<'a, C, A> {
|
||
ContactListCall {
|
||
hub: self.hub,
|
||
_delegate: Default::default(),
|
||
_scopes: Default::default(),
|
||
_additional_params: Default::default(),
|
||
}
|
||
}
|
||
|
||
/// Create a builder to help you perform the following task:
|
||
///
|
||
/// Updates a contact in place.
|
||
///
|
||
/// # Arguments
|
||
///
|
||
/// * `request` - No description provided.
|
||
/// * `id` - The ID of the contact.
|
||
pub fn update(&self, request: Contact, id: &str) -> ContactUpdateCall<'a, C, A> {
|
||
ContactUpdateCall {
|
||
hub: self.hub,
|
||
_request: request,
|
||
_id: id.to_string(),
|
||
_delegate: Default::default(),
|
||
_scopes: Default::default(),
|
||
_additional_params: Default::default(),
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
// ###################
|
||
// CallBuilders ###
|
||
// #################
|
||
|
||
/// Creates a new subscription.
|
||
///
|
||
/// A builder for the *insert* method supported by a *subscription* resource.
|
||
/// It is not used directly, but through a `SubscriptionMethods` instance.
|
||
///
|
||
/// # Example
|
||
///
|
||
/// Instantiate a resource method builder
|
||
///
|
||
/// ```test_harness,no_run
|
||
/// # extern crate hyper;
|
||
/// # extern crate yup_oauth2 as oauth2;
|
||
/// # extern crate google_mirror1 as mirror1;
|
||
/// use mirror1::Subscription;
|
||
/// # #[test] fn egal() {
|
||
/// # use std::default::Default;
|
||
/// # use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage};
|
||
/// # use mirror1::Mirror;
|
||
///
|
||
/// # let secret: ApplicationSecret = Default::default();
|
||
/// # let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate,
|
||
/// # hyper::Client::new(),
|
||
/// # <MemoryStorage as Default>::default(), None);
|
||
/// # let mut hub = Mirror::new(hyper::Client::new(), 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 = Subscription::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.subscriptions().insert(req)
|
||
/// .doit();
|
||
/// # }
|
||
/// ```
|
||
pub struct SubscriptionInsertCall<'a, C, A>
|
||
where C: 'a, A: 'a {
|
||
|
||
hub: &'a Mirror<C, A>,
|
||
_request: Subscription,
|
||
_delegate: Option<&'a mut Delegate>,
|
||
_additional_params: HashMap<String, String>,
|
||
_scopes: BTreeMap<String, ()>
|
||
}
|
||
|
||
impl<'a, C, A> CallBuilder for SubscriptionInsertCall<'a, C, A> {}
|
||
|
||
impl<'a, C, A> SubscriptionInsertCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oauth2::GetToken {
|
||
|
||
|
||
/// Perform the operation you have build so far.
|
||
pub fn doit(mut self) -> Result<(hyper::client::Response, Subscription)> {
|
||
use std::io::{Read, Seek};
|
||
use hyper::header::{ContentType, ContentLength, Authorization, Bearer, UserAgent, Location};
|
||
let mut dd = DefaultDelegate;
|
||
let mut dlg: &mut Delegate = match self._delegate {
|
||
Some(d) => d,
|
||
None => &mut dd
|
||
};
|
||
dlg.begin(MethodInfo { id: "mirror.subscriptions.insert",
|
||
http_method: hyper::method::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(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() + "subscriptions";
|
||
if self._scopes.len() == 0 {
|
||
self._scopes.insert(Scope::GlasTimeline.as_ref().to_string(), ());
|
||
}
|
||
|
||
|
||
if params.len() > 0 {
|
||
url.push('?');
|
||
url.push_str(&url::form_urlencoded::serialize(params));
|
||
}
|
||
|
||
let mut json_mime_type = mime::Mime(mime::TopLevel::Application, mime::SubLevel::Json, Default::default());
|
||
let mut request_value_reader =
|
||
{
|
||
let mut value = json::value::to_value(&self._request).expect("serde to work");
|
||
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.borrow_mut().token(self._scopes.keys()) {
|
||
Ok(token) => token,
|
||
Err(err) => {
|
||
match dlg.token(&*err) {
|
||
Some(token) => token,
|
||
None => {
|
||
dlg.finished(false);
|
||
return Err(Error::MissingToken(err))
|
||
}
|
||
}
|
||
}
|
||
};
|
||
let auth_header = Authorization(Bearer { token: token.access_token });
|
||
request_value_reader.seek(io::SeekFrom::Start(0)).unwrap();
|
||
let mut req_result = {
|
||
let mut client = &mut *self.hub.client.borrow_mut();
|
||
let mut req = client.borrow_mut().request(hyper::method::Method::Post, &url)
|
||
.header(UserAgent(self.hub._user_agent.clone()))
|
||
.header(auth_header.clone())
|
||
.header(ContentType(json_mime_type.clone()))
|
||
.header(ContentLength(request_size as u64))
|
||
.body(&mut request_value_reader);
|
||
|
||
dlg.pre_request();
|
||
req.send()
|
||
};
|
||
|
||
match req_result {
|
||
Err(err) => {
|
||
if let oauth2::Retry::After(d) = dlg.http_error(&err) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return Err(Error::HttpError(err))
|
||
}
|
||
Ok(mut res) => {
|
||
if !res.status.is_success() {
|
||
let mut json_err = String::new();
|
||
res.read_to_string(&mut json_err).unwrap();
|
||
if let oauth2::Retry::After(d) = dlg.http_failure(&res,
|
||
json::from_str(&json_err).ok(),
|
||
json::from_str(&json_err).ok()) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return match json::from_str::<ErrorResponse>(&json_err){
|
||
Err(_) => Err(Error::Failure(res)),
|
||
Ok(serr) => Err(Error::BadRequest(serr))
|
||
}
|
||
}
|
||
let result_value = {
|
||
let mut json_response = String::new();
|
||
res.read_to_string(&mut json_response).unwrap();
|
||
match json::from_str(&json_response) {
|
||
Ok(decoded) => (res, decoded),
|
||
Err(err) => {
|
||
dlg.response_json_decode_error(&json_response, &err);
|
||
return Err(Error::JsonDecodeError(json_response, 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: Subscription) -> SubscriptionInsertCall<'a, C, 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 Delegate) -> SubscriptionInsertCall<'a, C, 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 paramters
|
||
/// which have their own setter method. If done anyway, the request will fail.
|
||
///
|
||
/// # Additional Parameters
|
||
///
|
||
/// * *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. Overrides userIp if both are provided.
|
||
/// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
|
||
/// * *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.
|
||
/// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
|
||
/// * *userIp* (query-string) - IP address of the site where the request originates. Use this if you want to enforce per-user limits.
|
||
/// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
|
||
/// * *alt* (query-string) - Data format for the response.
|
||
pub fn param<T>(mut self, name: T, value: T) -> SubscriptionInsertCall<'a, C, 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::GlasTimeline`.
|
||
///
|
||
/// The `scope` will be added to a set of scopes. This is important as one can maintain access
|
||
/// tokens for more than one scope.
|
||
///
|
||
/// 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>(mut self, scope: T) -> SubscriptionInsertCall<'a, C, A>
|
||
where T: AsRef<str> {
|
||
self._scopes.insert(scope.as_ref().to_string(), ());
|
||
self
|
||
}
|
||
}
|
||
|
||
|
||
/// Deletes a subscription.
|
||
///
|
||
/// A builder for the *delete* method supported by a *subscription* resource.
|
||
/// It is not used directly, but through a `SubscriptionMethods` instance.
|
||
///
|
||
/// # Example
|
||
///
|
||
/// Instantiate a resource method builder
|
||
///
|
||
/// ```test_harness,no_run
|
||
/// # extern crate hyper;
|
||
/// # extern crate yup_oauth2 as oauth2;
|
||
/// # extern crate google_mirror1 as mirror1;
|
||
/// # #[test] fn egal() {
|
||
/// # use std::default::Default;
|
||
/// # use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage};
|
||
/// # use mirror1::Mirror;
|
||
///
|
||
/// # let secret: ApplicationSecret = Default::default();
|
||
/// # let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate,
|
||
/// # hyper::Client::new(),
|
||
/// # <MemoryStorage as Default>::default(), None);
|
||
/// # let mut hub = Mirror::new(hyper::Client::new(), 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.subscriptions().delete("id")
|
||
/// .doit();
|
||
/// # }
|
||
/// ```
|
||
pub struct SubscriptionDeleteCall<'a, C, A>
|
||
where C: 'a, A: 'a {
|
||
|
||
hub: &'a Mirror<C, A>,
|
||
_id: String,
|
||
_delegate: Option<&'a mut Delegate>,
|
||
_additional_params: HashMap<String, String>,
|
||
_scopes: BTreeMap<String, ()>
|
||
}
|
||
|
||
impl<'a, C, A> CallBuilder for SubscriptionDeleteCall<'a, C, A> {}
|
||
|
||
impl<'a, C, A> SubscriptionDeleteCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oauth2::GetToken {
|
||
|
||
|
||
/// Perform the operation you have build so far.
|
||
pub fn doit(mut self) -> Result<hyper::client::Response> {
|
||
use std::io::{Read, Seek};
|
||
use hyper::header::{ContentType, ContentLength, Authorization, Bearer, UserAgent, Location};
|
||
let mut dd = DefaultDelegate;
|
||
let mut dlg: &mut Delegate = match self._delegate {
|
||
Some(d) => d,
|
||
None => &mut dd
|
||
};
|
||
dlg.begin(MethodInfo { id: "mirror.subscriptions.delete",
|
||
http_method: hyper::method::Method::Delete });
|
||
let mut params: Vec<(&str, String)> = Vec::with_capacity((2 + self._additional_params.len()));
|
||
params.push(("id", self._id.to_string()));
|
||
for &field in ["id"].iter() {
|
||
if self._additional_params.contains_key(field) {
|
||
dlg.finished(false);
|
||
return Err(Error::FieldClash(field));
|
||
}
|
||
}
|
||
for (name, value) in self._additional_params.iter() {
|
||
params.push((&name, value.clone()));
|
||
}
|
||
|
||
|
||
let mut url = self.hub._base_url.clone() + "subscriptions/{id}";
|
||
if self._scopes.len() == 0 {
|
||
self._scopes.insert(Scope::GlasTimeline.as_ref().to_string(), ());
|
||
}
|
||
|
||
for &(find_this, param_name) in [("{id}", "id")].iter() {
|
||
let mut replace_with: Option<&str> = None;
|
||
for &(name, ref value) in params.iter() {
|
||
if name == param_name {
|
||
replace_with = Some(value);
|
||
break;
|
||
}
|
||
}
|
||
url = url.replace(find_this, replace_with.expect("to find substitution value in params"));
|
||
}
|
||
{
|
||
let mut indices_for_removal: Vec<usize> = Vec::with_capacity(1);
|
||
for param_name in ["id"].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);
|
||
}
|
||
}
|
||
|
||
if params.len() > 0 {
|
||
url.push('?');
|
||
url.push_str(&url::form_urlencoded::serialize(params));
|
||
}
|
||
|
||
|
||
|
||
loop {
|
||
let token = match self.hub.auth.borrow_mut().token(self._scopes.keys()) {
|
||
Ok(token) => token,
|
||
Err(err) => {
|
||
match dlg.token(&*err) {
|
||
Some(token) => token,
|
||
None => {
|
||
dlg.finished(false);
|
||
return Err(Error::MissingToken(err))
|
||
}
|
||
}
|
||
}
|
||
};
|
||
let auth_header = Authorization(Bearer { token: token.access_token });
|
||
let mut req_result = {
|
||
let mut client = &mut *self.hub.client.borrow_mut();
|
||
let mut req = client.borrow_mut().request(hyper::method::Method::Delete, &url)
|
||
.header(UserAgent(self.hub._user_agent.clone()))
|
||
.header(auth_header.clone());
|
||
|
||
dlg.pre_request();
|
||
req.send()
|
||
};
|
||
|
||
match req_result {
|
||
Err(err) => {
|
||
if let oauth2::Retry::After(d) = dlg.http_error(&err) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return Err(Error::HttpError(err))
|
||
}
|
||
Ok(mut res) => {
|
||
if !res.status.is_success() {
|
||
let mut json_err = String::new();
|
||
res.read_to_string(&mut json_err).unwrap();
|
||
if let oauth2::Retry::After(d) = dlg.http_failure(&res,
|
||
json::from_str(&json_err).ok(),
|
||
json::from_str(&json_err).ok()) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return match json::from_str::<ErrorResponse>(&json_err){
|
||
Err(_) => Err(Error::Failure(res)),
|
||
Ok(serr) => Err(Error::BadRequest(serr))
|
||
}
|
||
}
|
||
let result_value = res;
|
||
|
||
dlg.finished(true);
|
||
return Ok(result_value)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
/// The ID of the subscription.
|
||
///
|
||
/// Sets the *id* 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 id(mut self, new_value: &str) -> SubscriptionDeleteCall<'a, C, A> {
|
||
self._id = 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 Delegate) -> SubscriptionDeleteCall<'a, C, 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 paramters
|
||
/// which have their own setter method. If done anyway, the request will fail.
|
||
///
|
||
/// # Additional Parameters
|
||
///
|
||
/// * *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. Overrides userIp if both are provided.
|
||
/// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
|
||
/// * *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.
|
||
/// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
|
||
/// * *userIp* (query-string) - IP address of the site where the request originates. Use this if you want to enforce per-user limits.
|
||
/// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
|
||
/// * *alt* (query-string) - Data format for the response.
|
||
pub fn param<T>(mut self, name: T, value: T) -> SubscriptionDeleteCall<'a, C, 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::GlasTimeline`.
|
||
///
|
||
/// The `scope` will be added to a set of scopes. This is important as one can maintain access
|
||
/// tokens for more than one scope.
|
||
///
|
||
/// 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>(mut self, scope: T) -> SubscriptionDeleteCall<'a, C, A>
|
||
where T: AsRef<str> {
|
||
self._scopes.insert(scope.as_ref().to_string(), ());
|
||
self
|
||
}
|
||
}
|
||
|
||
|
||
/// Updates an existing subscription in place.
|
||
///
|
||
/// A builder for the *update* method supported by a *subscription* resource.
|
||
/// It is not used directly, but through a `SubscriptionMethods` instance.
|
||
///
|
||
/// # Example
|
||
///
|
||
/// Instantiate a resource method builder
|
||
///
|
||
/// ```test_harness,no_run
|
||
/// # extern crate hyper;
|
||
/// # extern crate yup_oauth2 as oauth2;
|
||
/// # extern crate google_mirror1 as mirror1;
|
||
/// use mirror1::Subscription;
|
||
/// # #[test] fn egal() {
|
||
/// # use std::default::Default;
|
||
/// # use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage};
|
||
/// # use mirror1::Mirror;
|
||
///
|
||
/// # let secret: ApplicationSecret = Default::default();
|
||
/// # let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate,
|
||
/// # hyper::Client::new(),
|
||
/// # <MemoryStorage as Default>::default(), None);
|
||
/// # let mut hub = Mirror::new(hyper::Client::new(), 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 = Subscription::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.subscriptions().update(req, "id")
|
||
/// .doit();
|
||
/// # }
|
||
/// ```
|
||
pub struct SubscriptionUpdateCall<'a, C, A>
|
||
where C: 'a, A: 'a {
|
||
|
||
hub: &'a Mirror<C, A>,
|
||
_request: Subscription,
|
||
_id: String,
|
||
_delegate: Option<&'a mut Delegate>,
|
||
_additional_params: HashMap<String, String>,
|
||
_scopes: BTreeMap<String, ()>
|
||
}
|
||
|
||
impl<'a, C, A> CallBuilder for SubscriptionUpdateCall<'a, C, A> {}
|
||
|
||
impl<'a, C, A> SubscriptionUpdateCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oauth2::GetToken {
|
||
|
||
|
||
/// Perform the operation you have build so far.
|
||
pub fn doit(mut self) -> Result<(hyper::client::Response, Subscription)> {
|
||
use std::io::{Read, Seek};
|
||
use hyper::header::{ContentType, ContentLength, Authorization, Bearer, UserAgent, Location};
|
||
let mut dd = DefaultDelegate;
|
||
let mut dlg: &mut Delegate = match self._delegate {
|
||
Some(d) => d,
|
||
None => &mut dd
|
||
};
|
||
dlg.begin(MethodInfo { id: "mirror.subscriptions.update",
|
||
http_method: hyper::method::Method::Put });
|
||
let mut params: Vec<(&str, String)> = Vec::with_capacity((4 + self._additional_params.len()));
|
||
params.push(("id", self._id.to_string()));
|
||
for &field in ["alt", "id"].iter() {
|
||
if self._additional_params.contains_key(field) {
|
||
dlg.finished(false);
|
||
return Err(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() + "subscriptions/{id}";
|
||
if self._scopes.len() == 0 {
|
||
self._scopes.insert(Scope::GlasTimeline.as_ref().to_string(), ());
|
||
}
|
||
|
||
for &(find_this, param_name) in [("{id}", "id")].iter() {
|
||
let mut replace_with: Option<&str> = None;
|
||
for &(name, ref value) in params.iter() {
|
||
if name == param_name {
|
||
replace_with = Some(value);
|
||
break;
|
||
}
|
||
}
|
||
url = url.replace(find_this, replace_with.expect("to find substitution value in params"));
|
||
}
|
||
{
|
||
let mut indices_for_removal: Vec<usize> = Vec::with_capacity(1);
|
||
for param_name in ["id"].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);
|
||
}
|
||
}
|
||
|
||
if params.len() > 0 {
|
||
url.push('?');
|
||
url.push_str(&url::form_urlencoded::serialize(params));
|
||
}
|
||
|
||
let mut json_mime_type = mime::Mime(mime::TopLevel::Application, mime::SubLevel::Json, Default::default());
|
||
let mut request_value_reader =
|
||
{
|
||
let mut value = json::value::to_value(&self._request).expect("serde to work");
|
||
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.borrow_mut().token(self._scopes.keys()) {
|
||
Ok(token) => token,
|
||
Err(err) => {
|
||
match dlg.token(&*err) {
|
||
Some(token) => token,
|
||
None => {
|
||
dlg.finished(false);
|
||
return Err(Error::MissingToken(err))
|
||
}
|
||
}
|
||
}
|
||
};
|
||
let auth_header = Authorization(Bearer { token: token.access_token });
|
||
request_value_reader.seek(io::SeekFrom::Start(0)).unwrap();
|
||
let mut req_result = {
|
||
let mut client = &mut *self.hub.client.borrow_mut();
|
||
let mut req = client.borrow_mut().request(hyper::method::Method::Put, &url)
|
||
.header(UserAgent(self.hub._user_agent.clone()))
|
||
.header(auth_header.clone())
|
||
.header(ContentType(json_mime_type.clone()))
|
||
.header(ContentLength(request_size as u64))
|
||
.body(&mut request_value_reader);
|
||
|
||
dlg.pre_request();
|
||
req.send()
|
||
};
|
||
|
||
match req_result {
|
||
Err(err) => {
|
||
if let oauth2::Retry::After(d) = dlg.http_error(&err) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return Err(Error::HttpError(err))
|
||
}
|
||
Ok(mut res) => {
|
||
if !res.status.is_success() {
|
||
let mut json_err = String::new();
|
||
res.read_to_string(&mut json_err).unwrap();
|
||
if let oauth2::Retry::After(d) = dlg.http_failure(&res,
|
||
json::from_str(&json_err).ok(),
|
||
json::from_str(&json_err).ok()) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return match json::from_str::<ErrorResponse>(&json_err){
|
||
Err(_) => Err(Error::Failure(res)),
|
||
Ok(serr) => Err(Error::BadRequest(serr))
|
||
}
|
||
}
|
||
let result_value = {
|
||
let mut json_response = String::new();
|
||
res.read_to_string(&mut json_response).unwrap();
|
||
match json::from_str(&json_response) {
|
||
Ok(decoded) => (res, decoded),
|
||
Err(err) => {
|
||
dlg.response_json_decode_error(&json_response, &err);
|
||
return Err(Error::JsonDecodeError(json_response, 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: Subscription) -> SubscriptionUpdateCall<'a, C, A> {
|
||
self._request = new_value;
|
||
self
|
||
}
|
||
/// The ID of the subscription.
|
||
///
|
||
/// Sets the *id* 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 id(mut self, new_value: &str) -> SubscriptionUpdateCall<'a, C, A> {
|
||
self._id = 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 Delegate) -> SubscriptionUpdateCall<'a, C, 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 paramters
|
||
/// which have their own setter method. If done anyway, the request will fail.
|
||
///
|
||
/// # Additional Parameters
|
||
///
|
||
/// * *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. Overrides userIp if both are provided.
|
||
/// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
|
||
/// * *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.
|
||
/// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
|
||
/// * *userIp* (query-string) - IP address of the site where the request originates. Use this if you want to enforce per-user limits.
|
||
/// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
|
||
/// * *alt* (query-string) - Data format for the response.
|
||
pub fn param<T>(mut self, name: T, value: T) -> SubscriptionUpdateCall<'a, C, 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::GlasTimeline`.
|
||
///
|
||
/// The `scope` will be added to a set of scopes. This is important as one can maintain access
|
||
/// tokens for more than one scope.
|
||
///
|
||
/// 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>(mut self, scope: T) -> SubscriptionUpdateCall<'a, C, A>
|
||
where T: AsRef<str> {
|
||
self._scopes.insert(scope.as_ref().to_string(), ());
|
||
self
|
||
}
|
||
}
|
||
|
||
|
||
/// Retrieves a list of subscriptions for the authenticated user and service.
|
||
///
|
||
/// A builder for the *list* method supported by a *subscription* resource.
|
||
/// It is not used directly, but through a `SubscriptionMethods` instance.
|
||
///
|
||
/// # Example
|
||
///
|
||
/// Instantiate a resource method builder
|
||
///
|
||
/// ```test_harness,no_run
|
||
/// # extern crate hyper;
|
||
/// # extern crate yup_oauth2 as oauth2;
|
||
/// # extern crate google_mirror1 as mirror1;
|
||
/// # #[test] fn egal() {
|
||
/// # use std::default::Default;
|
||
/// # use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage};
|
||
/// # use mirror1::Mirror;
|
||
///
|
||
/// # let secret: ApplicationSecret = Default::default();
|
||
/// # let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate,
|
||
/// # hyper::Client::new(),
|
||
/// # <MemoryStorage as Default>::default(), None);
|
||
/// # let mut hub = Mirror::new(hyper::Client::new(), 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.subscriptions().list()
|
||
/// .doit();
|
||
/// # }
|
||
/// ```
|
||
pub struct SubscriptionListCall<'a, C, A>
|
||
where C: 'a, A: 'a {
|
||
|
||
hub: &'a Mirror<C, A>,
|
||
_delegate: Option<&'a mut Delegate>,
|
||
_additional_params: HashMap<String, String>,
|
||
_scopes: BTreeMap<String, ()>
|
||
}
|
||
|
||
impl<'a, C, A> CallBuilder for SubscriptionListCall<'a, C, A> {}
|
||
|
||
impl<'a, C, A> SubscriptionListCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oauth2::GetToken {
|
||
|
||
|
||
/// Perform the operation you have build so far.
|
||
pub fn doit(mut self) -> Result<(hyper::client::Response, SubscriptionsListResponse)> {
|
||
use std::io::{Read, Seek};
|
||
use hyper::header::{ContentType, ContentLength, Authorization, Bearer, UserAgent, Location};
|
||
let mut dd = DefaultDelegate;
|
||
let mut dlg: &mut Delegate = match self._delegate {
|
||
Some(d) => d,
|
||
None => &mut dd
|
||
};
|
||
dlg.begin(MethodInfo { id: "mirror.subscriptions.list",
|
||
http_method: hyper::method::Method::Get });
|
||
let mut params: Vec<(&str, String)> = Vec::with_capacity((2 + self._additional_params.len()));
|
||
for &field in ["alt"].iter() {
|
||
if self._additional_params.contains_key(field) {
|
||
dlg.finished(false);
|
||
return Err(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() + "subscriptions";
|
||
if self._scopes.len() == 0 {
|
||
self._scopes.insert(Scope::GlasTimeline.as_ref().to_string(), ());
|
||
}
|
||
|
||
|
||
if params.len() > 0 {
|
||
url.push('?');
|
||
url.push_str(&url::form_urlencoded::serialize(params));
|
||
}
|
||
|
||
|
||
|
||
loop {
|
||
let token = match self.hub.auth.borrow_mut().token(self._scopes.keys()) {
|
||
Ok(token) => token,
|
||
Err(err) => {
|
||
match dlg.token(&*err) {
|
||
Some(token) => token,
|
||
None => {
|
||
dlg.finished(false);
|
||
return Err(Error::MissingToken(err))
|
||
}
|
||
}
|
||
}
|
||
};
|
||
let auth_header = Authorization(Bearer { token: token.access_token });
|
||
let mut req_result = {
|
||
let mut client = &mut *self.hub.client.borrow_mut();
|
||
let mut req = client.borrow_mut().request(hyper::method::Method::Get, &url)
|
||
.header(UserAgent(self.hub._user_agent.clone()))
|
||
.header(auth_header.clone());
|
||
|
||
dlg.pre_request();
|
||
req.send()
|
||
};
|
||
|
||
match req_result {
|
||
Err(err) => {
|
||
if let oauth2::Retry::After(d) = dlg.http_error(&err) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return Err(Error::HttpError(err))
|
||
}
|
||
Ok(mut res) => {
|
||
if !res.status.is_success() {
|
||
let mut json_err = String::new();
|
||
res.read_to_string(&mut json_err).unwrap();
|
||
if let oauth2::Retry::After(d) = dlg.http_failure(&res,
|
||
json::from_str(&json_err).ok(),
|
||
json::from_str(&json_err).ok()) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return match json::from_str::<ErrorResponse>(&json_err){
|
||
Err(_) => Err(Error::Failure(res)),
|
||
Ok(serr) => Err(Error::BadRequest(serr))
|
||
}
|
||
}
|
||
let result_value = {
|
||
let mut json_response = String::new();
|
||
res.read_to_string(&mut json_response).unwrap();
|
||
match json::from_str(&json_response) {
|
||
Ok(decoded) => (res, decoded),
|
||
Err(err) => {
|
||
dlg.response_json_decode_error(&json_response, &err);
|
||
return Err(Error::JsonDecodeError(json_response, err));
|
||
}
|
||
}
|
||
};
|
||
|
||
dlg.finished(true);
|
||
return Ok(result_value)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
/// 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 Delegate) -> SubscriptionListCall<'a, C, 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 paramters
|
||
/// which have their own setter method. If done anyway, the request will fail.
|
||
///
|
||
/// # Additional Parameters
|
||
///
|
||
/// * *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. Overrides userIp if both are provided.
|
||
/// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
|
||
/// * *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.
|
||
/// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
|
||
/// * *userIp* (query-string) - IP address of the site where the request originates. Use this if you want to enforce per-user limits.
|
||
/// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
|
||
/// * *alt* (query-string) - Data format for the response.
|
||
pub fn param<T>(mut self, name: T, value: T) -> SubscriptionListCall<'a, C, 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::GlasTimeline`.
|
||
///
|
||
/// The `scope` will be added to a set of scopes. This is important as one can maintain access
|
||
/// tokens for more than one scope.
|
||
///
|
||
/// 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>(mut self, scope: T) -> SubscriptionListCall<'a, C, A>
|
||
where T: AsRef<str> {
|
||
self._scopes.insert(scope.as_ref().to_string(), ());
|
||
self
|
||
}
|
||
}
|
||
|
||
|
||
/// Returns a list of attachments for a timeline item.
|
||
///
|
||
/// A builder for the *attachments.list* method supported by a *timeline* resource.
|
||
/// It is not used directly, but through a `TimelineMethods` instance.
|
||
///
|
||
/// # Example
|
||
///
|
||
/// Instantiate a resource method builder
|
||
///
|
||
/// ```test_harness,no_run
|
||
/// # extern crate hyper;
|
||
/// # extern crate yup_oauth2 as oauth2;
|
||
/// # extern crate google_mirror1 as mirror1;
|
||
/// # #[test] fn egal() {
|
||
/// # use std::default::Default;
|
||
/// # use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage};
|
||
/// # use mirror1::Mirror;
|
||
///
|
||
/// # let secret: ApplicationSecret = Default::default();
|
||
/// # let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate,
|
||
/// # hyper::Client::new(),
|
||
/// # <MemoryStorage as Default>::default(), None);
|
||
/// # let mut hub = Mirror::new(hyper::Client::new(), 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.timeline().attachments_list("itemId")
|
||
/// .doit();
|
||
/// # }
|
||
/// ```
|
||
pub struct TimelineAttachmentListCall<'a, C, A>
|
||
where C: 'a, A: 'a {
|
||
|
||
hub: &'a Mirror<C, A>,
|
||
_item_id: String,
|
||
_delegate: Option<&'a mut Delegate>,
|
||
_additional_params: HashMap<String, String>,
|
||
_scopes: BTreeMap<String, ()>
|
||
}
|
||
|
||
impl<'a, C, A> CallBuilder for TimelineAttachmentListCall<'a, C, A> {}
|
||
|
||
impl<'a, C, A> TimelineAttachmentListCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oauth2::GetToken {
|
||
|
||
|
||
/// Perform the operation you have build so far.
|
||
pub fn doit(mut self) -> Result<(hyper::client::Response, AttachmentsListResponse)> {
|
||
use std::io::{Read, Seek};
|
||
use hyper::header::{ContentType, ContentLength, Authorization, Bearer, UserAgent, Location};
|
||
let mut dd = DefaultDelegate;
|
||
let mut dlg: &mut Delegate = match self._delegate {
|
||
Some(d) => d,
|
||
None => &mut dd
|
||
};
|
||
dlg.begin(MethodInfo { id: "mirror.timeline.attachments.list",
|
||
http_method: hyper::method::Method::Get });
|
||
let mut params: Vec<(&str, String)> = Vec::with_capacity((3 + self._additional_params.len()));
|
||
params.push(("itemId", self._item_id.to_string()));
|
||
for &field in ["alt", "itemId"].iter() {
|
||
if self._additional_params.contains_key(field) {
|
||
dlg.finished(false);
|
||
return Err(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() + "timeline/{itemId}/attachments";
|
||
if self._scopes.len() == 0 {
|
||
self._scopes.insert(Scope::GlasTimeline.as_ref().to_string(), ());
|
||
}
|
||
|
||
for &(find_this, param_name) in [("{itemId}", "itemId")].iter() {
|
||
let mut replace_with: Option<&str> = None;
|
||
for &(name, ref value) in params.iter() {
|
||
if name == param_name {
|
||
replace_with = Some(value);
|
||
break;
|
||
}
|
||
}
|
||
url = url.replace(find_this, replace_with.expect("to find substitution value in params"));
|
||
}
|
||
{
|
||
let mut indices_for_removal: Vec<usize> = Vec::with_capacity(1);
|
||
for param_name in ["itemId"].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);
|
||
}
|
||
}
|
||
|
||
if params.len() > 0 {
|
||
url.push('?');
|
||
url.push_str(&url::form_urlencoded::serialize(params));
|
||
}
|
||
|
||
|
||
|
||
loop {
|
||
let token = match self.hub.auth.borrow_mut().token(self._scopes.keys()) {
|
||
Ok(token) => token,
|
||
Err(err) => {
|
||
match dlg.token(&*err) {
|
||
Some(token) => token,
|
||
None => {
|
||
dlg.finished(false);
|
||
return Err(Error::MissingToken(err))
|
||
}
|
||
}
|
||
}
|
||
};
|
||
let auth_header = Authorization(Bearer { token: token.access_token });
|
||
let mut req_result = {
|
||
let mut client = &mut *self.hub.client.borrow_mut();
|
||
let mut req = client.borrow_mut().request(hyper::method::Method::Get, &url)
|
||
.header(UserAgent(self.hub._user_agent.clone()))
|
||
.header(auth_header.clone());
|
||
|
||
dlg.pre_request();
|
||
req.send()
|
||
};
|
||
|
||
match req_result {
|
||
Err(err) => {
|
||
if let oauth2::Retry::After(d) = dlg.http_error(&err) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return Err(Error::HttpError(err))
|
||
}
|
||
Ok(mut res) => {
|
||
if !res.status.is_success() {
|
||
let mut json_err = String::new();
|
||
res.read_to_string(&mut json_err).unwrap();
|
||
if let oauth2::Retry::After(d) = dlg.http_failure(&res,
|
||
json::from_str(&json_err).ok(),
|
||
json::from_str(&json_err).ok()) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return match json::from_str::<ErrorResponse>(&json_err){
|
||
Err(_) => Err(Error::Failure(res)),
|
||
Ok(serr) => Err(Error::BadRequest(serr))
|
||
}
|
||
}
|
||
let result_value = {
|
||
let mut json_response = String::new();
|
||
res.read_to_string(&mut json_response).unwrap();
|
||
match json::from_str(&json_response) {
|
||
Ok(decoded) => (res, decoded),
|
||
Err(err) => {
|
||
dlg.response_json_decode_error(&json_response, &err);
|
||
return Err(Error::JsonDecodeError(json_response, err));
|
||
}
|
||
}
|
||
};
|
||
|
||
dlg.finished(true);
|
||
return Ok(result_value)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
/// The ID of the timeline item whose attachments should be listed.
|
||
///
|
||
/// Sets the *item id* 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 item_id(mut self, new_value: &str) -> TimelineAttachmentListCall<'a, C, A> {
|
||
self._item_id = 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 Delegate) -> TimelineAttachmentListCall<'a, C, 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 paramters
|
||
/// which have their own setter method. If done anyway, the request will fail.
|
||
///
|
||
/// # Additional Parameters
|
||
///
|
||
/// * *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. Overrides userIp if both are provided.
|
||
/// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
|
||
/// * *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.
|
||
/// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
|
||
/// * *userIp* (query-string) - IP address of the site where the request originates. Use this if you want to enforce per-user limits.
|
||
/// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
|
||
/// * *alt* (query-string) - Data format for the response.
|
||
pub fn param<T>(mut self, name: T, value: T) -> TimelineAttachmentListCall<'a, C, 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::GlasTimeline`.
|
||
///
|
||
/// The `scope` will be added to a set of scopes. This is important as one can maintain access
|
||
/// tokens for more than one scope.
|
||
///
|
||
/// 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>(mut self, scope: T) -> TimelineAttachmentListCall<'a, C, A>
|
||
where T: AsRef<str> {
|
||
self._scopes.insert(scope.as_ref().to_string(), ());
|
||
self
|
||
}
|
||
}
|
||
|
||
|
||
/// Inserts a new item into the timeline.
|
||
///
|
||
/// A builder for the *insert* method supported by a *timeline* resource.
|
||
/// It is not used directly, but through a `TimelineMethods` instance.
|
||
///
|
||
/// # Example
|
||
///
|
||
/// Instantiate a resource method builder
|
||
///
|
||
/// ```test_harness,no_run
|
||
/// # extern crate hyper;
|
||
/// # extern crate yup_oauth2 as oauth2;
|
||
/// # extern crate google_mirror1 as mirror1;
|
||
/// use mirror1::TimelineItem;
|
||
/// use std::fs;
|
||
/// # #[test] fn egal() {
|
||
/// # use std::default::Default;
|
||
/// # use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage};
|
||
/// # use mirror1::Mirror;
|
||
///
|
||
/// # let secret: ApplicationSecret = Default::default();
|
||
/// # let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate,
|
||
/// # hyper::Client::new(),
|
||
/// # <MemoryStorage as Default>::default(), None);
|
||
/// # let mut hub = Mirror::new(hyper::Client::new(), 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 = TimelineItem::default();
|
||
///
|
||
/// // You can configure optional parameters by calling the respective setters at will, and
|
||
/// // execute the final call using `upload(...)`.
|
||
/// // Values shown here are possibly random and not representative !
|
||
/// let result = hub.timeline().insert(req)
|
||
/// .upload(fs::File::open("file.ext").unwrap(), "application/octet-stream".parse().unwrap());
|
||
/// # }
|
||
/// ```
|
||
pub struct TimelineInsertCall<'a, C, A>
|
||
where C: 'a, A: 'a {
|
||
|
||
hub: &'a Mirror<C, A>,
|
||
_request: TimelineItem,
|
||
_delegate: Option<&'a mut Delegate>,
|
||
_additional_params: HashMap<String, String>,
|
||
_scopes: BTreeMap<String, ()>
|
||
}
|
||
|
||
impl<'a, C, A> CallBuilder for TimelineInsertCall<'a, C, A> {}
|
||
|
||
impl<'a, C, A> TimelineInsertCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oauth2::GetToken {
|
||
|
||
|
||
/// Perform the operation you have build so far.
|
||
fn doit<RS>(mut self, mut reader: RS, reader_mime_type: mime::Mime, protocol: &'static str) -> Result<(hyper::client::Response, TimelineItem)>
|
||
where RS: ReadSeek {
|
||
use std::io::{Read, Seek};
|
||
use hyper::header::{ContentType, ContentLength, Authorization, Bearer, UserAgent, Location};
|
||
let mut dd = DefaultDelegate;
|
||
let mut dlg: &mut Delegate = match self._delegate {
|
||
Some(d) => d,
|
||
None => &mut dd
|
||
};
|
||
dlg.begin(MethodInfo { id: "mirror.timeline.insert",
|
||
http_method: hyper::method::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(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, upload_type) =
|
||
if protocol == "simple" {
|
||
(self.hub._root_url.clone() + "/upload/mirror/v1/timeline", "multipart")
|
||
} else if protocol == "resumable" {
|
||
(self.hub._root_url.clone() + "/resumable/upload/mirror/v1/timeline", "resumable")
|
||
} else {
|
||
unreachable!()
|
||
};
|
||
params.push(("uploadType", upload_type.to_string()));
|
||
if self._scopes.len() == 0 {
|
||
self._scopes.insert(Scope::GlasLocation.as_ref().to_string(), ());
|
||
}
|
||
|
||
|
||
if params.len() > 0 {
|
||
url.push('?');
|
||
url.push_str(&url::form_urlencoded::serialize(params));
|
||
}
|
||
|
||
let mut json_mime_type = mime::Mime(mime::TopLevel::Application, mime::SubLevel::Json, Default::default());
|
||
let mut request_value_reader =
|
||
{
|
||
let mut value = json::value::to_value(&self._request).expect("serde to work");
|
||
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();
|
||
|
||
let mut should_ask_dlg_for_url = false;
|
||
let mut upload_url_from_server;
|
||
let mut upload_url: Option<String> = None;
|
||
|
||
loop {
|
||
let token = match self.hub.auth.borrow_mut().token(self._scopes.keys()) {
|
||
Ok(token) => token,
|
||
Err(err) => {
|
||
match dlg.token(&*err) {
|
||
Some(token) => token,
|
||
None => {
|
||
dlg.finished(false);
|
||
return Err(Error::MissingToken(err))
|
||
}
|
||
}
|
||
}
|
||
};
|
||
let auth_header = Authorization(Bearer { token: token.access_token });
|
||
request_value_reader.seek(io::SeekFrom::Start(0)).unwrap();
|
||
let mut req_result = {
|
||
if should_ask_dlg_for_url && (upload_url = dlg.upload_url()) == () && upload_url.is_some() {
|
||
should_ask_dlg_for_url = false;
|
||
upload_url_from_server = false;
|
||
let url = upload_url.as_ref().and_then(|s| Some(hyper::Url::parse(s).unwrap())).unwrap();
|
||
hyper::client::Response::new(url, Box::new(cmn::DummyNetworkStream)).and_then(|mut res| {
|
||
res.status = hyper::status::StatusCode::Ok;
|
||
res.headers.set(Location(upload_url.as_ref().unwrap().clone()));
|
||
Ok(res)
|
||
})
|
||
} else {
|
||
let mut mp_reader: MultiPartReader = Default::default();
|
||
let (mut body_reader, content_type) = match protocol {
|
||
"simple" => {
|
||
mp_reader.reserve_exact(2);
|
||
let size = reader.seek(io::SeekFrom::End(0)).unwrap();
|
||
reader.seek(io::SeekFrom::Start(0)).unwrap();
|
||
if size > 10485760 {
|
||
return Err(Error::UploadSizeLimitExceeded(size, 10485760))
|
||
}
|
||
mp_reader.add_part(&mut request_value_reader, request_size, json_mime_type.clone())
|
||
.add_part(&mut reader, size, reader_mime_type.clone());
|
||
let mime_type = mp_reader.mime_type();
|
||
(&mut mp_reader as &mut io::Read, ContentType(mime_type))
|
||
},
|
||
_ => (&mut request_value_reader as &mut io::Read, ContentType(json_mime_type.clone())),
|
||
};
|
||
let mut client = &mut *self.hub.client.borrow_mut();
|
||
let mut req = client.borrow_mut().request(hyper::method::Method::Post, &url)
|
||
.header(UserAgent(self.hub._user_agent.clone()))
|
||
.header(auth_header.clone())
|
||
.header(content_type)
|
||
.body(&mut body_reader);
|
||
upload_url_from_server = true;
|
||
if protocol == "resumable" {
|
||
req = req.header(cmn::XUploadContentType(reader_mime_type.clone()));
|
||
}
|
||
|
||
dlg.pre_request();
|
||
req.send()
|
||
}
|
||
};
|
||
|
||
match req_result {
|
||
Err(err) => {
|
||
if let oauth2::Retry::After(d) = dlg.http_error(&err) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return Err(Error::HttpError(err))
|
||
}
|
||
Ok(mut res) => {
|
||
if !res.status.is_success() {
|
||
let mut json_err = String::new();
|
||
res.read_to_string(&mut json_err).unwrap();
|
||
if let oauth2::Retry::After(d) = dlg.http_failure(&res,
|
||
json::from_str(&json_err).ok(),
|
||
json::from_str(&json_err).ok()) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return match json::from_str::<ErrorResponse>(&json_err){
|
||
Err(_) => Err(Error::Failure(res)),
|
||
Ok(serr) => Err(Error::BadRequest(serr))
|
||
}
|
||
}
|
||
if protocol == "resumable" {
|
||
let size = reader.seek(io::SeekFrom::End(0)).unwrap();
|
||
reader.seek(io::SeekFrom::Start(0)).unwrap();
|
||
if size > 10485760 {
|
||
return Err(Error::UploadSizeLimitExceeded(size, 10485760))
|
||
}
|
||
let mut client = &mut *self.hub.client.borrow_mut();
|
||
let upload_result = {
|
||
let url_str = &res.headers.get::<Location>().expect("Location header is part of protocol").0;
|
||
if upload_url_from_server {
|
||
dlg.store_upload_url(Some(url_str));
|
||
}
|
||
|
||
cmn::ResumableUploadHelper {
|
||
client: &mut client.borrow_mut(),
|
||
delegate: dlg,
|
||
start_at: if upload_url_from_server { Some(0) } else { None },
|
||
auth: &mut *self.hub.auth.borrow_mut(),
|
||
user_agent: &self.hub._user_agent,
|
||
auth_header: auth_header.clone(),
|
||
url: url_str,
|
||
reader: &mut reader,
|
||
media_type: reader_mime_type.clone(),
|
||
content_length: size
|
||
}.upload()
|
||
};
|
||
match upload_result {
|
||
None => {
|
||
dlg.finished(false);
|
||
return Err(Error::Cancelled)
|
||
}
|
||
Some(Err(err)) => {
|
||
dlg.finished(false);
|
||
return Err(Error::HttpError(err))
|
||
}
|
||
Some(Ok(upload_result)) => {
|
||
res = upload_result;
|
||
if !res.status.is_success() {
|
||
dlg.store_upload_url(None);
|
||
dlg.finished(false);
|
||
return Err(Error::Failure(res))
|
||
}
|
||
}
|
||
}
|
||
}
|
||
let result_value = {
|
||
let mut json_response = String::new();
|
||
res.read_to_string(&mut json_response).unwrap();
|
||
match json::from_str(&json_response) {
|
||
Ok(decoded) => (res, decoded),
|
||
Err(err) => {
|
||
dlg.response_json_decode_error(&json_response, &err);
|
||
return Err(Error::JsonDecodeError(json_response, err));
|
||
}
|
||
}
|
||
};
|
||
|
||
dlg.finished(true);
|
||
return Ok(result_value)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
/// Upload media all at once.
|
||
/// If the upload fails for whichever reason, all progress is lost.
|
||
///
|
||
/// * *max size*: 10MB
|
||
/// * *multipart*: yes
|
||
/// * *valid mime types*: 'audio/*', 'image/*' and 'video/*'
|
||
pub fn upload<RS>(self, stream: RS, mime_type: mime::Mime) -> Result<(hyper::client::Response, TimelineItem)>
|
||
where RS: ReadSeek {
|
||
self.doit(stream, mime_type, "simple")
|
||
}
|
||
/// Upload media in a resumable fashion.
|
||
/// Even if the upload fails or is interrupted, it can be resumed for a
|
||
/// certain amount of time as the server maintains state temporarily.
|
||
///
|
||
/// The delegate will be asked for an `upload_url()`, and if not provided, will be asked to store an upload URL
|
||
/// that was provided by the server, using `store_upload_url(...)`. The upload will be done in chunks, the delegate
|
||
/// may specify the `chunk_size()` and may cancel the operation before each chunk is uploaded, using
|
||
/// `cancel_chunk_upload(...)`.
|
||
///
|
||
/// * *max size*: 10MB
|
||
/// * *multipart*: yes
|
||
/// * *valid mime types*: 'audio/*', 'image/*' and 'video/*'
|
||
pub fn upload_resumable<RS>(self, resumeable_stream: RS, mime_type: mime::Mime) -> Result<(hyper::client::Response, TimelineItem)>
|
||
where RS: ReadSeek {
|
||
self.doit(resumeable_stream, mime_type, "resumable")
|
||
}
|
||
|
||
///
|
||
/// 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: TimelineItem) -> TimelineInsertCall<'a, C, 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 Delegate) -> TimelineInsertCall<'a, C, 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 paramters
|
||
/// which have their own setter method. If done anyway, the request will fail.
|
||
///
|
||
/// # Additional Parameters
|
||
///
|
||
/// * *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. Overrides userIp if both are provided.
|
||
/// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
|
||
/// * *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.
|
||
/// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
|
||
/// * *userIp* (query-string) - IP address of the site where the request originates. Use this if you want to enforce per-user limits.
|
||
/// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
|
||
/// * *alt* (query-string) - Data format for the response.
|
||
pub fn param<T>(mut self, name: T, value: T) -> TimelineInsertCall<'a, C, 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::GlasLocation`.
|
||
///
|
||
/// The `scope` will be added to a set of scopes. This is important as one can maintain access
|
||
/// tokens for more than one scope.
|
||
///
|
||
/// 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>(mut self, scope: T) -> TimelineInsertCall<'a, C, A>
|
||
where T: AsRef<str> {
|
||
self._scopes.insert(scope.as_ref().to_string(), ());
|
||
self
|
||
}
|
||
}
|
||
|
||
|
||
/// Updates a timeline item in place. This method supports patch semantics.
|
||
///
|
||
/// A builder for the *patch* method supported by a *timeline* resource.
|
||
/// It is not used directly, but through a `TimelineMethods` instance.
|
||
///
|
||
/// # Example
|
||
///
|
||
/// Instantiate a resource method builder
|
||
///
|
||
/// ```test_harness,no_run
|
||
/// # extern crate hyper;
|
||
/// # extern crate yup_oauth2 as oauth2;
|
||
/// # extern crate google_mirror1 as mirror1;
|
||
/// use mirror1::TimelineItem;
|
||
/// # #[test] fn egal() {
|
||
/// # use std::default::Default;
|
||
/// # use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage};
|
||
/// # use mirror1::Mirror;
|
||
///
|
||
/// # let secret: ApplicationSecret = Default::default();
|
||
/// # let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate,
|
||
/// # hyper::Client::new(),
|
||
/// # <MemoryStorage as Default>::default(), None);
|
||
/// # let mut hub = Mirror::new(hyper::Client::new(), 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 = TimelineItem::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.timeline().patch(req, "id")
|
||
/// .doit();
|
||
/// # }
|
||
/// ```
|
||
pub struct TimelinePatchCall<'a, C, A>
|
||
where C: 'a, A: 'a {
|
||
|
||
hub: &'a Mirror<C, A>,
|
||
_request: TimelineItem,
|
||
_id: String,
|
||
_delegate: Option<&'a mut Delegate>,
|
||
_additional_params: HashMap<String, String>,
|
||
_scopes: BTreeMap<String, ()>
|
||
}
|
||
|
||
impl<'a, C, A> CallBuilder for TimelinePatchCall<'a, C, A> {}
|
||
|
||
impl<'a, C, A> TimelinePatchCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oauth2::GetToken {
|
||
|
||
|
||
/// Perform the operation you have build so far.
|
||
pub fn doit(mut self) -> Result<(hyper::client::Response, TimelineItem)> {
|
||
use std::io::{Read, Seek};
|
||
use hyper::header::{ContentType, ContentLength, Authorization, Bearer, UserAgent, Location};
|
||
let mut dd = DefaultDelegate;
|
||
let mut dlg: &mut Delegate = match self._delegate {
|
||
Some(d) => d,
|
||
None => &mut dd
|
||
};
|
||
dlg.begin(MethodInfo { id: "mirror.timeline.patch",
|
||
http_method: hyper::method::Method::Patch });
|
||
let mut params: Vec<(&str, String)> = Vec::with_capacity((4 + self._additional_params.len()));
|
||
params.push(("id", self._id.to_string()));
|
||
for &field in ["alt", "id"].iter() {
|
||
if self._additional_params.contains_key(field) {
|
||
dlg.finished(false);
|
||
return Err(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() + "timeline/{id}";
|
||
if self._scopes.len() == 0 {
|
||
self._scopes.insert(Scope::GlasLocation.as_ref().to_string(), ());
|
||
}
|
||
|
||
for &(find_this, param_name) in [("{id}", "id")].iter() {
|
||
let mut replace_with: Option<&str> = None;
|
||
for &(name, ref value) in params.iter() {
|
||
if name == param_name {
|
||
replace_with = Some(value);
|
||
break;
|
||
}
|
||
}
|
||
url = url.replace(find_this, replace_with.expect("to find substitution value in params"));
|
||
}
|
||
{
|
||
let mut indices_for_removal: Vec<usize> = Vec::with_capacity(1);
|
||
for param_name in ["id"].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);
|
||
}
|
||
}
|
||
|
||
if params.len() > 0 {
|
||
url.push('?');
|
||
url.push_str(&url::form_urlencoded::serialize(params));
|
||
}
|
||
|
||
let mut json_mime_type = mime::Mime(mime::TopLevel::Application, mime::SubLevel::Json, Default::default());
|
||
let mut request_value_reader =
|
||
{
|
||
let mut value = json::value::to_value(&self._request).expect("serde to work");
|
||
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.borrow_mut().token(self._scopes.keys()) {
|
||
Ok(token) => token,
|
||
Err(err) => {
|
||
match dlg.token(&*err) {
|
||
Some(token) => token,
|
||
None => {
|
||
dlg.finished(false);
|
||
return Err(Error::MissingToken(err))
|
||
}
|
||
}
|
||
}
|
||
};
|
||
let auth_header = Authorization(Bearer { token: token.access_token });
|
||
request_value_reader.seek(io::SeekFrom::Start(0)).unwrap();
|
||
let mut req_result = {
|
||
let mut client = &mut *self.hub.client.borrow_mut();
|
||
let mut req = client.borrow_mut().request(hyper::method::Method::Patch, &url)
|
||
.header(UserAgent(self.hub._user_agent.clone()))
|
||
.header(auth_header.clone())
|
||
.header(ContentType(json_mime_type.clone()))
|
||
.header(ContentLength(request_size as u64))
|
||
.body(&mut request_value_reader);
|
||
|
||
dlg.pre_request();
|
||
req.send()
|
||
};
|
||
|
||
match req_result {
|
||
Err(err) => {
|
||
if let oauth2::Retry::After(d) = dlg.http_error(&err) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return Err(Error::HttpError(err))
|
||
}
|
||
Ok(mut res) => {
|
||
if !res.status.is_success() {
|
||
let mut json_err = String::new();
|
||
res.read_to_string(&mut json_err).unwrap();
|
||
if let oauth2::Retry::After(d) = dlg.http_failure(&res,
|
||
json::from_str(&json_err).ok(),
|
||
json::from_str(&json_err).ok()) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return match json::from_str::<ErrorResponse>(&json_err){
|
||
Err(_) => Err(Error::Failure(res)),
|
||
Ok(serr) => Err(Error::BadRequest(serr))
|
||
}
|
||
}
|
||
let result_value = {
|
||
let mut json_response = String::new();
|
||
res.read_to_string(&mut json_response).unwrap();
|
||
match json::from_str(&json_response) {
|
||
Ok(decoded) => (res, decoded),
|
||
Err(err) => {
|
||
dlg.response_json_decode_error(&json_response, &err);
|
||
return Err(Error::JsonDecodeError(json_response, 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: TimelineItem) -> TimelinePatchCall<'a, C, A> {
|
||
self._request = new_value;
|
||
self
|
||
}
|
||
/// The ID of the timeline item.
|
||
///
|
||
/// Sets the *id* 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 id(mut self, new_value: &str) -> TimelinePatchCall<'a, C, A> {
|
||
self._id = 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 Delegate) -> TimelinePatchCall<'a, C, 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 paramters
|
||
/// which have their own setter method. If done anyway, the request will fail.
|
||
///
|
||
/// # Additional Parameters
|
||
///
|
||
/// * *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. Overrides userIp if both are provided.
|
||
/// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
|
||
/// * *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.
|
||
/// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
|
||
/// * *userIp* (query-string) - IP address of the site where the request originates. Use this if you want to enforce per-user limits.
|
||
/// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
|
||
/// * *alt* (query-string) - Data format for the response.
|
||
pub fn param<T>(mut self, name: T, value: T) -> TimelinePatchCall<'a, C, 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::GlasLocation`.
|
||
///
|
||
/// The `scope` will be added to a set of scopes. This is important as one can maintain access
|
||
/// tokens for more than one scope.
|
||
///
|
||
/// 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>(mut self, scope: T) -> TimelinePatchCall<'a, C, A>
|
||
where T: AsRef<str> {
|
||
self._scopes.insert(scope.as_ref().to_string(), ());
|
||
self
|
||
}
|
||
}
|
||
|
||
|
||
/// Retrieves a list of timeline items for the authenticated user.
|
||
///
|
||
/// A builder for the *list* method supported by a *timeline* resource.
|
||
/// It is not used directly, but through a `TimelineMethods` instance.
|
||
///
|
||
/// # Example
|
||
///
|
||
/// Instantiate a resource method builder
|
||
///
|
||
/// ```test_harness,no_run
|
||
/// # extern crate hyper;
|
||
/// # extern crate yup_oauth2 as oauth2;
|
||
/// # extern crate google_mirror1 as mirror1;
|
||
/// # #[test] fn egal() {
|
||
/// # use std::default::Default;
|
||
/// # use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage};
|
||
/// # use mirror1::Mirror;
|
||
///
|
||
/// # let secret: ApplicationSecret = Default::default();
|
||
/// # let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate,
|
||
/// # hyper::Client::new(),
|
||
/// # <MemoryStorage as Default>::default(), None);
|
||
/// # let mut hub = Mirror::new(hyper::Client::new(), 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.timeline().list()
|
||
/// .source_item_id("accusam")
|
||
/// .pinned_only(true)
|
||
/// .page_token("justo")
|
||
/// .order_by("amet.")
|
||
/// .max_results(20)
|
||
/// .include_deleted(true)
|
||
/// .bundle_id("sea")
|
||
/// .doit();
|
||
/// # }
|
||
/// ```
|
||
pub struct TimelineListCall<'a, C, A>
|
||
where C: 'a, A: 'a {
|
||
|
||
hub: &'a Mirror<C, A>,
|
||
_source_item_id: Option<String>,
|
||
_pinned_only: Option<bool>,
|
||
_page_token: Option<String>,
|
||
_order_by: Option<String>,
|
||
_max_results: Option<u32>,
|
||
_include_deleted: Option<bool>,
|
||
_bundle_id: Option<String>,
|
||
_delegate: Option<&'a mut Delegate>,
|
||
_additional_params: HashMap<String, String>,
|
||
_scopes: BTreeMap<String, ()>
|
||
}
|
||
|
||
impl<'a, C, A> CallBuilder for TimelineListCall<'a, C, A> {}
|
||
|
||
impl<'a, C, A> TimelineListCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oauth2::GetToken {
|
||
|
||
|
||
/// Perform the operation you have build so far.
|
||
pub fn doit(mut self) -> Result<(hyper::client::Response, TimelineListResponse)> {
|
||
use std::io::{Read, Seek};
|
||
use hyper::header::{ContentType, ContentLength, Authorization, Bearer, UserAgent, Location};
|
||
let mut dd = DefaultDelegate;
|
||
let mut dlg: &mut Delegate = match self._delegate {
|
||
Some(d) => d,
|
||
None => &mut dd
|
||
};
|
||
dlg.begin(MethodInfo { id: "mirror.timeline.list",
|
||
http_method: hyper::method::Method::Get });
|
||
let mut params: Vec<(&str, String)> = Vec::with_capacity((9 + self._additional_params.len()));
|
||
if let Some(value) = self._source_item_id {
|
||
params.push(("sourceItemId", value.to_string()));
|
||
}
|
||
if let Some(value) = self._pinned_only {
|
||
params.push(("pinnedOnly", value.to_string()));
|
||
}
|
||
if let Some(value) = self._page_token {
|
||
params.push(("pageToken", value.to_string()));
|
||
}
|
||
if let Some(value) = self._order_by {
|
||
params.push(("orderBy", value.to_string()));
|
||
}
|
||
if let Some(value) = self._max_results {
|
||
params.push(("maxResults", value.to_string()));
|
||
}
|
||
if let Some(value) = self._include_deleted {
|
||
params.push(("includeDeleted", value.to_string()));
|
||
}
|
||
if let Some(value) = self._bundle_id {
|
||
params.push(("bundleId", value.to_string()));
|
||
}
|
||
for &field in ["alt", "sourceItemId", "pinnedOnly", "pageToken", "orderBy", "maxResults", "includeDeleted", "bundleId"].iter() {
|
||
if self._additional_params.contains_key(field) {
|
||
dlg.finished(false);
|
||
return Err(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() + "timeline";
|
||
if self._scopes.len() == 0 {
|
||
self._scopes.insert(Scope::GlasLocation.as_ref().to_string(), ());
|
||
}
|
||
|
||
|
||
if params.len() > 0 {
|
||
url.push('?');
|
||
url.push_str(&url::form_urlencoded::serialize(params));
|
||
}
|
||
|
||
|
||
|
||
loop {
|
||
let token = match self.hub.auth.borrow_mut().token(self._scopes.keys()) {
|
||
Ok(token) => token,
|
||
Err(err) => {
|
||
match dlg.token(&*err) {
|
||
Some(token) => token,
|
||
None => {
|
||
dlg.finished(false);
|
||
return Err(Error::MissingToken(err))
|
||
}
|
||
}
|
||
}
|
||
};
|
||
let auth_header = Authorization(Bearer { token: token.access_token });
|
||
let mut req_result = {
|
||
let mut client = &mut *self.hub.client.borrow_mut();
|
||
let mut req = client.borrow_mut().request(hyper::method::Method::Get, &url)
|
||
.header(UserAgent(self.hub._user_agent.clone()))
|
||
.header(auth_header.clone());
|
||
|
||
dlg.pre_request();
|
||
req.send()
|
||
};
|
||
|
||
match req_result {
|
||
Err(err) => {
|
||
if let oauth2::Retry::After(d) = dlg.http_error(&err) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return Err(Error::HttpError(err))
|
||
}
|
||
Ok(mut res) => {
|
||
if !res.status.is_success() {
|
||
let mut json_err = String::new();
|
||
res.read_to_string(&mut json_err).unwrap();
|
||
if let oauth2::Retry::After(d) = dlg.http_failure(&res,
|
||
json::from_str(&json_err).ok(),
|
||
json::from_str(&json_err).ok()) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return match json::from_str::<ErrorResponse>(&json_err){
|
||
Err(_) => Err(Error::Failure(res)),
|
||
Ok(serr) => Err(Error::BadRequest(serr))
|
||
}
|
||
}
|
||
let result_value = {
|
||
let mut json_response = String::new();
|
||
res.read_to_string(&mut json_response).unwrap();
|
||
match json::from_str(&json_response) {
|
||
Ok(decoded) => (res, decoded),
|
||
Err(err) => {
|
||
dlg.response_json_decode_error(&json_response, &err);
|
||
return Err(Error::JsonDecodeError(json_response, err));
|
||
}
|
||
}
|
||
};
|
||
|
||
dlg.finished(true);
|
||
return Ok(result_value)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
/// If provided, only items with the given sourceItemId will be returned.
|
||
///
|
||
/// Sets the *source item id* query property to the given value.
|
||
pub fn source_item_id(mut self, new_value: &str) -> TimelineListCall<'a, C, A> {
|
||
self._source_item_id = Some(new_value.to_string());
|
||
self
|
||
}
|
||
/// If true, only pinned items will be returned.
|
||
///
|
||
/// Sets the *pinned only* query property to the given value.
|
||
pub fn pinned_only(mut self, new_value: bool) -> TimelineListCall<'a, C, A> {
|
||
self._pinned_only = Some(new_value);
|
||
self
|
||
}
|
||
/// Token for the page of results to return.
|
||
///
|
||
/// Sets the *page token* query property to the given value.
|
||
pub fn page_token(mut self, new_value: &str) -> TimelineListCall<'a, C, A> {
|
||
self._page_token = Some(new_value.to_string());
|
||
self
|
||
}
|
||
/// Controls the order in which timeline items are returned.
|
||
///
|
||
/// Sets the *order by* query property to the given value.
|
||
pub fn order_by(mut self, new_value: &str) -> TimelineListCall<'a, C, A> {
|
||
self._order_by = Some(new_value.to_string());
|
||
self
|
||
}
|
||
/// The maximum number of items to include in the response, used for paging.
|
||
///
|
||
/// Sets the *max results* query property to the given value.
|
||
pub fn max_results(mut self, new_value: u32) -> TimelineListCall<'a, C, A> {
|
||
self._max_results = Some(new_value);
|
||
self
|
||
}
|
||
/// If true, tombstone records for deleted items will be returned.
|
||
///
|
||
/// Sets the *include deleted* query property to the given value.
|
||
pub fn include_deleted(mut self, new_value: bool) -> TimelineListCall<'a, C, A> {
|
||
self._include_deleted = Some(new_value);
|
||
self
|
||
}
|
||
/// If provided, only items with the given bundleId will be returned.
|
||
///
|
||
/// Sets the *bundle id* query property to the given value.
|
||
pub fn bundle_id(mut self, new_value: &str) -> TimelineListCall<'a, C, A> {
|
||
self._bundle_id = 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 Delegate) -> TimelineListCall<'a, C, 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 paramters
|
||
/// which have their own setter method. If done anyway, the request will fail.
|
||
///
|
||
/// # Additional Parameters
|
||
///
|
||
/// * *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. Overrides userIp if both are provided.
|
||
/// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
|
||
/// * *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.
|
||
/// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
|
||
/// * *userIp* (query-string) - IP address of the site where the request originates. Use this if you want to enforce per-user limits.
|
||
/// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
|
||
/// * *alt* (query-string) - Data format for the response.
|
||
pub fn param<T>(mut self, name: T, value: T) -> TimelineListCall<'a, C, 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::GlasLocation`.
|
||
///
|
||
/// The `scope` will be added to a set of scopes. This is important as one can maintain access
|
||
/// tokens for more than one scope.
|
||
///
|
||
/// 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>(mut self, scope: T) -> TimelineListCall<'a, C, A>
|
||
where T: AsRef<str> {
|
||
self._scopes.insert(scope.as_ref().to_string(), ());
|
||
self
|
||
}
|
||
}
|
||
|
||
|
||
/// Adds a new attachment to a timeline item.
|
||
///
|
||
/// A builder for the *attachments.insert* method supported by a *timeline* resource.
|
||
/// It is not used directly, but through a `TimelineMethods` instance.
|
||
///
|
||
/// # Example
|
||
///
|
||
/// Instantiate a resource method builder
|
||
///
|
||
/// ```test_harness,no_run
|
||
/// # extern crate hyper;
|
||
/// # extern crate yup_oauth2 as oauth2;
|
||
/// # extern crate google_mirror1 as mirror1;
|
||
/// use std::fs;
|
||
/// # #[test] fn egal() {
|
||
/// # use std::default::Default;
|
||
/// # use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage};
|
||
/// # use mirror1::Mirror;
|
||
///
|
||
/// # let secret: ApplicationSecret = Default::default();
|
||
/// # let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate,
|
||
/// # hyper::Client::new(),
|
||
/// # <MemoryStorage as Default>::default(), None);
|
||
/// # let mut hub = Mirror::new(hyper::Client::new(), auth);
|
||
/// // You can configure optional parameters by calling the respective setters at will, and
|
||
/// // execute the final call using `upload(...)`.
|
||
/// // Values shown here are possibly random and not representative !
|
||
/// let result = hub.timeline().attachments_insert("itemId")
|
||
/// .upload(fs::File::open("file.ext").unwrap(), "application/octet-stream".parse().unwrap());
|
||
/// # }
|
||
/// ```
|
||
pub struct TimelineAttachmentInsertCall<'a, C, A>
|
||
where C: 'a, A: 'a {
|
||
|
||
hub: &'a Mirror<C, A>,
|
||
_item_id: String,
|
||
_delegate: Option<&'a mut Delegate>,
|
||
_additional_params: HashMap<String, String>,
|
||
_scopes: BTreeMap<String, ()>
|
||
}
|
||
|
||
impl<'a, C, A> CallBuilder for TimelineAttachmentInsertCall<'a, C, A> {}
|
||
|
||
impl<'a, C, A> TimelineAttachmentInsertCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oauth2::GetToken {
|
||
|
||
|
||
/// Perform the operation you have build so far.
|
||
fn doit<RS>(mut self, mut reader: RS, reader_mime_type: mime::Mime, protocol: &'static str) -> Result<(hyper::client::Response, Attachment)>
|
||
where RS: ReadSeek {
|
||
use std::io::{Read, Seek};
|
||
use hyper::header::{ContentType, ContentLength, Authorization, Bearer, UserAgent, Location};
|
||
let mut dd = DefaultDelegate;
|
||
let mut dlg: &mut Delegate = match self._delegate {
|
||
Some(d) => d,
|
||
None => &mut dd
|
||
};
|
||
dlg.begin(MethodInfo { id: "mirror.timeline.attachments.insert",
|
||
http_method: hyper::method::Method::Post });
|
||
let mut params: Vec<(&str, String)> = Vec::with_capacity((3 + self._additional_params.len()));
|
||
params.push(("itemId", self._item_id.to_string()));
|
||
for &field in ["alt", "itemId"].iter() {
|
||
if self._additional_params.contains_key(field) {
|
||
dlg.finished(false);
|
||
return Err(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, upload_type) =
|
||
if protocol == "simple" {
|
||
(self.hub._root_url.clone() + "/upload/mirror/v1/timeline/{itemId}/attachments", "multipart")
|
||
} else if protocol == "resumable" {
|
||
(self.hub._root_url.clone() + "/resumable/upload/mirror/v1/timeline/{itemId}/attachments", "resumable")
|
||
} else {
|
||
unreachable!()
|
||
};
|
||
params.push(("uploadType", upload_type.to_string()));
|
||
if self._scopes.len() == 0 {
|
||
self._scopes.insert(Scope::GlasTimeline.as_ref().to_string(), ());
|
||
}
|
||
|
||
for &(find_this, param_name) in [("{itemId}", "itemId")].iter() {
|
||
let mut replace_with: Option<&str> = None;
|
||
for &(name, ref value) in params.iter() {
|
||
if name == param_name {
|
||
replace_with = Some(value);
|
||
break;
|
||
}
|
||
}
|
||
url = url.replace(find_this, replace_with.expect("to find substitution value in params"));
|
||
}
|
||
{
|
||
let mut indices_for_removal: Vec<usize> = Vec::with_capacity(1);
|
||
for param_name in ["itemId"].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);
|
||
}
|
||
}
|
||
|
||
if params.len() > 0 {
|
||
url.push('?');
|
||
url.push_str(&url::form_urlencoded::serialize(params));
|
||
}
|
||
|
||
|
||
let mut should_ask_dlg_for_url = false;
|
||
let mut upload_url_from_server;
|
||
let mut upload_url: Option<String> = None;
|
||
|
||
loop {
|
||
let token = match self.hub.auth.borrow_mut().token(self._scopes.keys()) {
|
||
Ok(token) => token,
|
||
Err(err) => {
|
||
match dlg.token(&*err) {
|
||
Some(token) => token,
|
||
None => {
|
||
dlg.finished(false);
|
||
return Err(Error::MissingToken(err))
|
||
}
|
||
}
|
||
}
|
||
};
|
||
let auth_header = Authorization(Bearer { token: token.access_token });
|
||
let mut req_result = {
|
||
if should_ask_dlg_for_url && (upload_url = dlg.upload_url()) == () && upload_url.is_some() {
|
||
should_ask_dlg_for_url = false;
|
||
upload_url_from_server = false;
|
||
let url = upload_url.as_ref().and_then(|s| Some(hyper::Url::parse(s).unwrap())).unwrap();
|
||
hyper::client::Response::new(url, Box::new(cmn::DummyNetworkStream)).and_then(|mut res| {
|
||
res.status = hyper::status::StatusCode::Ok;
|
||
res.headers.set(Location(upload_url.as_ref().unwrap().clone()));
|
||
Ok(res)
|
||
})
|
||
} else {
|
||
let mut client = &mut *self.hub.client.borrow_mut();
|
||
let mut req = client.borrow_mut().request(hyper::method::Method::Post, &url)
|
||
.header(UserAgent(self.hub._user_agent.clone()))
|
||
.header(auth_header.clone());
|
||
if protocol == "simple" {
|
||
let size = reader.seek(io::SeekFrom::End(0)).unwrap();
|
||
reader.seek(io::SeekFrom::Start(0)).unwrap();
|
||
if size > 10485760 {
|
||
return Err(Error::UploadSizeLimitExceeded(size, 10485760))
|
||
}
|
||
req = req.header(ContentType(reader_mime_type.clone()))
|
||
.header(ContentLength(size))
|
||
.body(&mut reader);
|
||
}
|
||
upload_url_from_server = true;
|
||
if protocol == "resumable" {
|
||
req = req.header(cmn::XUploadContentType(reader_mime_type.clone()));
|
||
}
|
||
|
||
dlg.pre_request();
|
||
req.send()
|
||
}
|
||
};
|
||
|
||
match req_result {
|
||
Err(err) => {
|
||
if let oauth2::Retry::After(d) = dlg.http_error(&err) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return Err(Error::HttpError(err))
|
||
}
|
||
Ok(mut res) => {
|
||
if !res.status.is_success() {
|
||
let mut json_err = String::new();
|
||
res.read_to_string(&mut json_err).unwrap();
|
||
if let oauth2::Retry::After(d) = dlg.http_failure(&res,
|
||
json::from_str(&json_err).ok(),
|
||
json::from_str(&json_err).ok()) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return match json::from_str::<ErrorResponse>(&json_err){
|
||
Err(_) => Err(Error::Failure(res)),
|
||
Ok(serr) => Err(Error::BadRequest(serr))
|
||
}
|
||
}
|
||
if protocol == "resumable" {
|
||
let size = reader.seek(io::SeekFrom::End(0)).unwrap();
|
||
reader.seek(io::SeekFrom::Start(0)).unwrap();
|
||
if size > 10485760 {
|
||
return Err(Error::UploadSizeLimitExceeded(size, 10485760))
|
||
}
|
||
let mut client = &mut *self.hub.client.borrow_mut();
|
||
let upload_result = {
|
||
let url_str = &res.headers.get::<Location>().expect("Location header is part of protocol").0;
|
||
if upload_url_from_server {
|
||
dlg.store_upload_url(Some(url_str));
|
||
}
|
||
|
||
cmn::ResumableUploadHelper {
|
||
client: &mut client.borrow_mut(),
|
||
delegate: dlg,
|
||
start_at: if upload_url_from_server { Some(0) } else { None },
|
||
auth: &mut *self.hub.auth.borrow_mut(),
|
||
user_agent: &self.hub._user_agent,
|
||
auth_header: auth_header.clone(),
|
||
url: url_str,
|
||
reader: &mut reader,
|
||
media_type: reader_mime_type.clone(),
|
||
content_length: size
|
||
}.upload()
|
||
};
|
||
match upload_result {
|
||
None => {
|
||
dlg.finished(false);
|
||
return Err(Error::Cancelled)
|
||
}
|
||
Some(Err(err)) => {
|
||
dlg.finished(false);
|
||
return Err(Error::HttpError(err))
|
||
}
|
||
Some(Ok(upload_result)) => {
|
||
res = upload_result;
|
||
if !res.status.is_success() {
|
||
dlg.store_upload_url(None);
|
||
dlg.finished(false);
|
||
return Err(Error::Failure(res))
|
||
}
|
||
}
|
||
}
|
||
}
|
||
let result_value = {
|
||
let mut json_response = String::new();
|
||
res.read_to_string(&mut json_response).unwrap();
|
||
match json::from_str(&json_response) {
|
||
Ok(decoded) => (res, decoded),
|
||
Err(err) => {
|
||
dlg.response_json_decode_error(&json_response, &err);
|
||
return Err(Error::JsonDecodeError(json_response, err));
|
||
}
|
||
}
|
||
};
|
||
|
||
dlg.finished(true);
|
||
return Ok(result_value)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
/// Upload media all at once.
|
||
/// If the upload fails for whichever reason, all progress is lost.
|
||
///
|
||
/// * *max size*: 10MB
|
||
/// * *multipart*: yes
|
||
/// * *valid mime types*: 'audio/*', 'image/*' and 'video/*'
|
||
pub fn upload<RS>(self, stream: RS, mime_type: mime::Mime) -> Result<(hyper::client::Response, Attachment)>
|
||
where RS: ReadSeek {
|
||
self.doit(stream, mime_type, "simple")
|
||
}
|
||
/// Upload media in a resumable fashion.
|
||
/// Even if the upload fails or is interrupted, it can be resumed for a
|
||
/// certain amount of time as the server maintains state temporarily.
|
||
///
|
||
/// The delegate will be asked for an `upload_url()`, and if not provided, will be asked to store an upload URL
|
||
/// that was provided by the server, using `store_upload_url(...)`. The upload will be done in chunks, the delegate
|
||
/// may specify the `chunk_size()` and may cancel the operation before each chunk is uploaded, using
|
||
/// `cancel_chunk_upload(...)`.
|
||
///
|
||
/// * *max size*: 10MB
|
||
/// * *multipart*: yes
|
||
/// * *valid mime types*: 'audio/*', 'image/*' and 'video/*'
|
||
pub fn upload_resumable<RS>(self, resumeable_stream: RS, mime_type: mime::Mime) -> Result<(hyper::client::Response, Attachment)>
|
||
where RS: ReadSeek {
|
||
self.doit(resumeable_stream, mime_type, "resumable")
|
||
}
|
||
|
||
/// The ID of the timeline item the attachment belongs to.
|
||
///
|
||
/// Sets the *item id* 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 item_id(mut self, new_value: &str) -> TimelineAttachmentInsertCall<'a, C, A> {
|
||
self._item_id = 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 Delegate) -> TimelineAttachmentInsertCall<'a, C, 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 paramters
|
||
/// which have their own setter method. If done anyway, the request will fail.
|
||
///
|
||
/// # Additional Parameters
|
||
///
|
||
/// * *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. Overrides userIp if both are provided.
|
||
/// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
|
||
/// * *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.
|
||
/// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
|
||
/// * *userIp* (query-string) - IP address of the site where the request originates. Use this if you want to enforce per-user limits.
|
||
/// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
|
||
/// * *alt* (query-string) - Data format for the response.
|
||
pub fn param<T>(mut self, name: T, value: T) -> TimelineAttachmentInsertCall<'a, C, 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::GlasTimeline`.
|
||
///
|
||
/// The `scope` will be added to a set of scopes. This is important as one can maintain access
|
||
/// tokens for more than one scope.
|
||
///
|
||
/// 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>(mut self, scope: T) -> TimelineAttachmentInsertCall<'a, C, A>
|
||
where T: AsRef<str> {
|
||
self._scopes.insert(scope.as_ref().to_string(), ());
|
||
self
|
||
}
|
||
}
|
||
|
||
|
||
/// Deletes an attachment from a timeline item.
|
||
///
|
||
/// A builder for the *attachments.delete* method supported by a *timeline* resource.
|
||
/// It is not used directly, but through a `TimelineMethods` instance.
|
||
///
|
||
/// # Example
|
||
///
|
||
/// Instantiate a resource method builder
|
||
///
|
||
/// ```test_harness,no_run
|
||
/// # extern crate hyper;
|
||
/// # extern crate yup_oauth2 as oauth2;
|
||
/// # extern crate google_mirror1 as mirror1;
|
||
/// # #[test] fn egal() {
|
||
/// # use std::default::Default;
|
||
/// # use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage};
|
||
/// # use mirror1::Mirror;
|
||
///
|
||
/// # let secret: ApplicationSecret = Default::default();
|
||
/// # let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate,
|
||
/// # hyper::Client::new(),
|
||
/// # <MemoryStorage as Default>::default(), None);
|
||
/// # let mut hub = Mirror::new(hyper::Client::new(), 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.timeline().attachments_delete("itemId", "attachmentId")
|
||
/// .doit();
|
||
/// # }
|
||
/// ```
|
||
pub struct TimelineAttachmentDeleteCall<'a, C, A>
|
||
where C: 'a, A: 'a {
|
||
|
||
hub: &'a Mirror<C, A>,
|
||
_item_id: String,
|
||
_attachment_id: String,
|
||
_delegate: Option<&'a mut Delegate>,
|
||
_additional_params: HashMap<String, String>,
|
||
_scopes: BTreeMap<String, ()>
|
||
}
|
||
|
||
impl<'a, C, A> CallBuilder for TimelineAttachmentDeleteCall<'a, C, A> {}
|
||
|
||
impl<'a, C, A> TimelineAttachmentDeleteCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oauth2::GetToken {
|
||
|
||
|
||
/// Perform the operation you have build so far.
|
||
pub fn doit(mut self) -> Result<hyper::client::Response> {
|
||
use std::io::{Read, Seek};
|
||
use hyper::header::{ContentType, ContentLength, Authorization, Bearer, UserAgent, Location};
|
||
let mut dd = DefaultDelegate;
|
||
let mut dlg: &mut Delegate = match self._delegate {
|
||
Some(d) => d,
|
||
None => &mut dd
|
||
};
|
||
dlg.begin(MethodInfo { id: "mirror.timeline.attachments.delete",
|
||
http_method: hyper::method::Method::Delete });
|
||
let mut params: Vec<(&str, String)> = Vec::with_capacity((3 + self._additional_params.len()));
|
||
params.push(("itemId", self._item_id.to_string()));
|
||
params.push(("attachmentId", self._attachment_id.to_string()));
|
||
for &field in ["itemId", "attachmentId"].iter() {
|
||
if self._additional_params.contains_key(field) {
|
||
dlg.finished(false);
|
||
return Err(Error::FieldClash(field));
|
||
}
|
||
}
|
||
for (name, value) in self._additional_params.iter() {
|
||
params.push((&name, value.clone()));
|
||
}
|
||
|
||
|
||
let mut url = self.hub._base_url.clone() + "timeline/{itemId}/attachments/{attachmentId}";
|
||
if self._scopes.len() == 0 {
|
||
self._scopes.insert(Scope::GlasTimeline.as_ref().to_string(), ());
|
||
}
|
||
|
||
for &(find_this, param_name) in [("{itemId}", "itemId"), ("{attachmentId}", "attachmentId")].iter() {
|
||
let mut replace_with: Option<&str> = None;
|
||
for &(name, ref value) in params.iter() {
|
||
if name == param_name {
|
||
replace_with = Some(value);
|
||
break;
|
||
}
|
||
}
|
||
url = url.replace(find_this, replace_with.expect("to find substitution value in params"));
|
||
}
|
||
{
|
||
let mut indices_for_removal: Vec<usize> = Vec::with_capacity(2);
|
||
for param_name in ["attachmentId", "itemId"].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);
|
||
}
|
||
}
|
||
|
||
if params.len() > 0 {
|
||
url.push('?');
|
||
url.push_str(&url::form_urlencoded::serialize(params));
|
||
}
|
||
|
||
|
||
|
||
loop {
|
||
let token = match self.hub.auth.borrow_mut().token(self._scopes.keys()) {
|
||
Ok(token) => token,
|
||
Err(err) => {
|
||
match dlg.token(&*err) {
|
||
Some(token) => token,
|
||
None => {
|
||
dlg.finished(false);
|
||
return Err(Error::MissingToken(err))
|
||
}
|
||
}
|
||
}
|
||
};
|
||
let auth_header = Authorization(Bearer { token: token.access_token });
|
||
let mut req_result = {
|
||
let mut client = &mut *self.hub.client.borrow_mut();
|
||
let mut req = client.borrow_mut().request(hyper::method::Method::Delete, &url)
|
||
.header(UserAgent(self.hub._user_agent.clone()))
|
||
.header(auth_header.clone());
|
||
|
||
dlg.pre_request();
|
||
req.send()
|
||
};
|
||
|
||
match req_result {
|
||
Err(err) => {
|
||
if let oauth2::Retry::After(d) = dlg.http_error(&err) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return Err(Error::HttpError(err))
|
||
}
|
||
Ok(mut res) => {
|
||
if !res.status.is_success() {
|
||
let mut json_err = String::new();
|
||
res.read_to_string(&mut json_err).unwrap();
|
||
if let oauth2::Retry::After(d) = dlg.http_failure(&res,
|
||
json::from_str(&json_err).ok(),
|
||
json::from_str(&json_err).ok()) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return match json::from_str::<ErrorResponse>(&json_err){
|
||
Err(_) => Err(Error::Failure(res)),
|
||
Ok(serr) => Err(Error::BadRequest(serr))
|
||
}
|
||
}
|
||
let result_value = res;
|
||
|
||
dlg.finished(true);
|
||
return Ok(result_value)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
/// The ID of the timeline item the attachment belongs to.
|
||
///
|
||
/// Sets the *item id* 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 item_id(mut self, new_value: &str) -> TimelineAttachmentDeleteCall<'a, C, A> {
|
||
self._item_id = new_value.to_string();
|
||
self
|
||
}
|
||
/// The ID of the attachment.
|
||
///
|
||
/// Sets the *attachment id* 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 attachment_id(mut self, new_value: &str) -> TimelineAttachmentDeleteCall<'a, C, A> {
|
||
self._attachment_id = 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 Delegate) -> TimelineAttachmentDeleteCall<'a, C, 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 paramters
|
||
/// which have their own setter method. If done anyway, the request will fail.
|
||
///
|
||
/// # Additional Parameters
|
||
///
|
||
/// * *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. Overrides userIp if both are provided.
|
||
/// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
|
||
/// * *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.
|
||
/// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
|
||
/// * *userIp* (query-string) - IP address of the site where the request originates. Use this if you want to enforce per-user limits.
|
||
/// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
|
||
/// * *alt* (query-string) - Data format for the response.
|
||
pub fn param<T>(mut self, name: T, value: T) -> TimelineAttachmentDeleteCall<'a, C, 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::GlasTimeline`.
|
||
///
|
||
/// The `scope` will be added to a set of scopes. This is important as one can maintain access
|
||
/// tokens for more than one scope.
|
||
///
|
||
/// 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>(mut self, scope: T) -> TimelineAttachmentDeleteCall<'a, C, A>
|
||
where T: AsRef<str> {
|
||
self._scopes.insert(scope.as_ref().to_string(), ());
|
||
self
|
||
}
|
||
}
|
||
|
||
|
||
/// Deletes a timeline item.
|
||
///
|
||
/// A builder for the *delete* method supported by a *timeline* resource.
|
||
/// It is not used directly, but through a `TimelineMethods` instance.
|
||
///
|
||
/// # Example
|
||
///
|
||
/// Instantiate a resource method builder
|
||
///
|
||
/// ```test_harness,no_run
|
||
/// # extern crate hyper;
|
||
/// # extern crate yup_oauth2 as oauth2;
|
||
/// # extern crate google_mirror1 as mirror1;
|
||
/// # #[test] fn egal() {
|
||
/// # use std::default::Default;
|
||
/// # use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage};
|
||
/// # use mirror1::Mirror;
|
||
///
|
||
/// # let secret: ApplicationSecret = Default::default();
|
||
/// # let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate,
|
||
/// # hyper::Client::new(),
|
||
/// # <MemoryStorage as Default>::default(), None);
|
||
/// # let mut hub = Mirror::new(hyper::Client::new(), 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.timeline().delete("id")
|
||
/// .doit();
|
||
/// # }
|
||
/// ```
|
||
pub struct TimelineDeleteCall<'a, C, A>
|
||
where C: 'a, A: 'a {
|
||
|
||
hub: &'a Mirror<C, A>,
|
||
_id: String,
|
||
_delegate: Option<&'a mut Delegate>,
|
||
_additional_params: HashMap<String, String>,
|
||
_scopes: BTreeMap<String, ()>
|
||
}
|
||
|
||
impl<'a, C, A> CallBuilder for TimelineDeleteCall<'a, C, A> {}
|
||
|
||
impl<'a, C, A> TimelineDeleteCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oauth2::GetToken {
|
||
|
||
|
||
/// Perform the operation you have build so far.
|
||
pub fn doit(mut self) -> Result<hyper::client::Response> {
|
||
use std::io::{Read, Seek};
|
||
use hyper::header::{ContentType, ContentLength, Authorization, Bearer, UserAgent, Location};
|
||
let mut dd = DefaultDelegate;
|
||
let mut dlg: &mut Delegate = match self._delegate {
|
||
Some(d) => d,
|
||
None => &mut dd
|
||
};
|
||
dlg.begin(MethodInfo { id: "mirror.timeline.delete",
|
||
http_method: hyper::method::Method::Delete });
|
||
let mut params: Vec<(&str, String)> = Vec::with_capacity((2 + self._additional_params.len()));
|
||
params.push(("id", self._id.to_string()));
|
||
for &field in ["id"].iter() {
|
||
if self._additional_params.contains_key(field) {
|
||
dlg.finished(false);
|
||
return Err(Error::FieldClash(field));
|
||
}
|
||
}
|
||
for (name, value) in self._additional_params.iter() {
|
||
params.push((&name, value.clone()));
|
||
}
|
||
|
||
|
||
let mut url = self.hub._base_url.clone() + "timeline/{id}";
|
||
if self._scopes.len() == 0 {
|
||
self._scopes.insert(Scope::GlasLocation.as_ref().to_string(), ());
|
||
}
|
||
|
||
for &(find_this, param_name) in [("{id}", "id")].iter() {
|
||
let mut replace_with: Option<&str> = None;
|
||
for &(name, ref value) in params.iter() {
|
||
if name == param_name {
|
||
replace_with = Some(value);
|
||
break;
|
||
}
|
||
}
|
||
url = url.replace(find_this, replace_with.expect("to find substitution value in params"));
|
||
}
|
||
{
|
||
let mut indices_for_removal: Vec<usize> = Vec::with_capacity(1);
|
||
for param_name in ["id"].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);
|
||
}
|
||
}
|
||
|
||
if params.len() > 0 {
|
||
url.push('?');
|
||
url.push_str(&url::form_urlencoded::serialize(params));
|
||
}
|
||
|
||
|
||
|
||
loop {
|
||
let token = match self.hub.auth.borrow_mut().token(self._scopes.keys()) {
|
||
Ok(token) => token,
|
||
Err(err) => {
|
||
match dlg.token(&*err) {
|
||
Some(token) => token,
|
||
None => {
|
||
dlg.finished(false);
|
||
return Err(Error::MissingToken(err))
|
||
}
|
||
}
|
||
}
|
||
};
|
||
let auth_header = Authorization(Bearer { token: token.access_token });
|
||
let mut req_result = {
|
||
let mut client = &mut *self.hub.client.borrow_mut();
|
||
let mut req = client.borrow_mut().request(hyper::method::Method::Delete, &url)
|
||
.header(UserAgent(self.hub._user_agent.clone()))
|
||
.header(auth_header.clone());
|
||
|
||
dlg.pre_request();
|
||
req.send()
|
||
};
|
||
|
||
match req_result {
|
||
Err(err) => {
|
||
if let oauth2::Retry::After(d) = dlg.http_error(&err) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return Err(Error::HttpError(err))
|
||
}
|
||
Ok(mut res) => {
|
||
if !res.status.is_success() {
|
||
let mut json_err = String::new();
|
||
res.read_to_string(&mut json_err).unwrap();
|
||
if let oauth2::Retry::After(d) = dlg.http_failure(&res,
|
||
json::from_str(&json_err).ok(),
|
||
json::from_str(&json_err).ok()) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return match json::from_str::<ErrorResponse>(&json_err){
|
||
Err(_) => Err(Error::Failure(res)),
|
||
Ok(serr) => Err(Error::BadRequest(serr))
|
||
}
|
||
}
|
||
let result_value = res;
|
||
|
||
dlg.finished(true);
|
||
return Ok(result_value)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
/// The ID of the timeline item.
|
||
///
|
||
/// Sets the *id* 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 id(mut self, new_value: &str) -> TimelineDeleteCall<'a, C, A> {
|
||
self._id = 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 Delegate) -> TimelineDeleteCall<'a, C, 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 paramters
|
||
/// which have their own setter method. If done anyway, the request will fail.
|
||
///
|
||
/// # Additional Parameters
|
||
///
|
||
/// * *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. Overrides userIp if both are provided.
|
||
/// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
|
||
/// * *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.
|
||
/// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
|
||
/// * *userIp* (query-string) - IP address of the site where the request originates. Use this if you want to enforce per-user limits.
|
||
/// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
|
||
/// * *alt* (query-string) - Data format for the response.
|
||
pub fn param<T>(mut self, name: T, value: T) -> TimelineDeleteCall<'a, C, 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::GlasLocation`.
|
||
///
|
||
/// The `scope` will be added to a set of scopes. This is important as one can maintain access
|
||
/// tokens for more than one scope.
|
||
///
|
||
/// 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>(mut self, scope: T) -> TimelineDeleteCall<'a, C, A>
|
||
where T: AsRef<str> {
|
||
self._scopes.insert(scope.as_ref().to_string(), ());
|
||
self
|
||
}
|
||
}
|
||
|
||
|
||
/// Updates a timeline item in place.
|
||
///
|
||
/// A builder for the *update* method supported by a *timeline* resource.
|
||
/// It is not used directly, but through a `TimelineMethods` instance.
|
||
///
|
||
/// # Example
|
||
///
|
||
/// Instantiate a resource method builder
|
||
///
|
||
/// ```test_harness,no_run
|
||
/// # extern crate hyper;
|
||
/// # extern crate yup_oauth2 as oauth2;
|
||
/// # extern crate google_mirror1 as mirror1;
|
||
/// use mirror1::TimelineItem;
|
||
/// use std::fs;
|
||
/// # #[test] fn egal() {
|
||
/// # use std::default::Default;
|
||
/// # use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage};
|
||
/// # use mirror1::Mirror;
|
||
///
|
||
/// # let secret: ApplicationSecret = Default::default();
|
||
/// # let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate,
|
||
/// # hyper::Client::new(),
|
||
/// # <MemoryStorage as Default>::default(), None);
|
||
/// # let mut hub = Mirror::new(hyper::Client::new(), 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 = TimelineItem::default();
|
||
///
|
||
/// // You can configure optional parameters by calling the respective setters at will, and
|
||
/// // execute the final call using `upload(...)`.
|
||
/// // Values shown here are possibly random and not representative !
|
||
/// let result = hub.timeline().update(req, "id")
|
||
/// .upload(fs::File::open("file.ext").unwrap(), "application/octet-stream".parse().unwrap());
|
||
/// # }
|
||
/// ```
|
||
pub struct TimelineUpdateCall<'a, C, A>
|
||
where C: 'a, A: 'a {
|
||
|
||
hub: &'a Mirror<C, A>,
|
||
_request: TimelineItem,
|
||
_id: String,
|
||
_delegate: Option<&'a mut Delegate>,
|
||
_additional_params: HashMap<String, String>,
|
||
_scopes: BTreeMap<String, ()>
|
||
}
|
||
|
||
impl<'a, C, A> CallBuilder for TimelineUpdateCall<'a, C, A> {}
|
||
|
||
impl<'a, C, A> TimelineUpdateCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oauth2::GetToken {
|
||
|
||
|
||
/// Perform the operation you have build so far.
|
||
fn doit<RS>(mut self, mut reader: RS, reader_mime_type: mime::Mime, protocol: &'static str) -> Result<(hyper::client::Response, TimelineItem)>
|
||
where RS: ReadSeek {
|
||
use std::io::{Read, Seek};
|
||
use hyper::header::{ContentType, ContentLength, Authorization, Bearer, UserAgent, Location};
|
||
let mut dd = DefaultDelegate;
|
||
let mut dlg: &mut Delegate = match self._delegate {
|
||
Some(d) => d,
|
||
None => &mut dd
|
||
};
|
||
dlg.begin(MethodInfo { id: "mirror.timeline.update",
|
||
http_method: hyper::method::Method::Put });
|
||
let mut params: Vec<(&str, String)> = Vec::with_capacity((4 + self._additional_params.len()));
|
||
params.push(("id", self._id.to_string()));
|
||
for &field in ["alt", "id"].iter() {
|
||
if self._additional_params.contains_key(field) {
|
||
dlg.finished(false);
|
||
return Err(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, upload_type) =
|
||
if protocol == "simple" {
|
||
(self.hub._root_url.clone() + "/upload/mirror/v1/timeline/{id}", "multipart")
|
||
} else if protocol == "resumable" {
|
||
(self.hub._root_url.clone() + "/resumable/upload/mirror/v1/timeline/{id}", "resumable")
|
||
} else {
|
||
unreachable!()
|
||
};
|
||
params.push(("uploadType", upload_type.to_string()));
|
||
if self._scopes.len() == 0 {
|
||
self._scopes.insert(Scope::GlasLocation.as_ref().to_string(), ());
|
||
}
|
||
|
||
for &(find_this, param_name) in [("{id}", "id")].iter() {
|
||
let mut replace_with: Option<&str> = None;
|
||
for &(name, ref value) in params.iter() {
|
||
if name == param_name {
|
||
replace_with = Some(value);
|
||
break;
|
||
}
|
||
}
|
||
url = url.replace(find_this, replace_with.expect("to find substitution value in params"));
|
||
}
|
||
{
|
||
let mut indices_for_removal: Vec<usize> = Vec::with_capacity(1);
|
||
for param_name in ["id"].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);
|
||
}
|
||
}
|
||
|
||
if params.len() > 0 {
|
||
url.push('?');
|
||
url.push_str(&url::form_urlencoded::serialize(params));
|
||
}
|
||
|
||
let mut json_mime_type = mime::Mime(mime::TopLevel::Application, mime::SubLevel::Json, Default::default());
|
||
let mut request_value_reader =
|
||
{
|
||
let mut value = json::value::to_value(&self._request).expect("serde to work");
|
||
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();
|
||
|
||
let mut should_ask_dlg_for_url = false;
|
||
let mut upload_url_from_server;
|
||
let mut upload_url: Option<String> = None;
|
||
|
||
loop {
|
||
let token = match self.hub.auth.borrow_mut().token(self._scopes.keys()) {
|
||
Ok(token) => token,
|
||
Err(err) => {
|
||
match dlg.token(&*err) {
|
||
Some(token) => token,
|
||
None => {
|
||
dlg.finished(false);
|
||
return Err(Error::MissingToken(err))
|
||
}
|
||
}
|
||
}
|
||
};
|
||
let auth_header = Authorization(Bearer { token: token.access_token });
|
||
request_value_reader.seek(io::SeekFrom::Start(0)).unwrap();
|
||
let mut req_result = {
|
||
if should_ask_dlg_for_url && (upload_url = dlg.upload_url()) == () && upload_url.is_some() {
|
||
should_ask_dlg_for_url = false;
|
||
upload_url_from_server = false;
|
||
let url = upload_url.as_ref().and_then(|s| Some(hyper::Url::parse(s).unwrap())).unwrap();
|
||
hyper::client::Response::new(url, Box::new(cmn::DummyNetworkStream)).and_then(|mut res| {
|
||
res.status = hyper::status::StatusCode::Ok;
|
||
res.headers.set(Location(upload_url.as_ref().unwrap().clone()));
|
||
Ok(res)
|
||
})
|
||
} else {
|
||
let mut mp_reader: MultiPartReader = Default::default();
|
||
let (mut body_reader, content_type) = match protocol {
|
||
"simple" => {
|
||
mp_reader.reserve_exact(2);
|
||
let size = reader.seek(io::SeekFrom::End(0)).unwrap();
|
||
reader.seek(io::SeekFrom::Start(0)).unwrap();
|
||
if size > 10485760 {
|
||
return Err(Error::UploadSizeLimitExceeded(size, 10485760))
|
||
}
|
||
mp_reader.add_part(&mut request_value_reader, request_size, json_mime_type.clone())
|
||
.add_part(&mut reader, size, reader_mime_type.clone());
|
||
let mime_type = mp_reader.mime_type();
|
||
(&mut mp_reader as &mut io::Read, ContentType(mime_type))
|
||
},
|
||
_ => (&mut request_value_reader as &mut io::Read, ContentType(json_mime_type.clone())),
|
||
};
|
||
let mut client = &mut *self.hub.client.borrow_mut();
|
||
let mut req = client.borrow_mut().request(hyper::method::Method::Put, &url)
|
||
.header(UserAgent(self.hub._user_agent.clone()))
|
||
.header(auth_header.clone())
|
||
.header(content_type)
|
||
.body(&mut body_reader);
|
||
upload_url_from_server = true;
|
||
if protocol == "resumable" {
|
||
req = req.header(cmn::XUploadContentType(reader_mime_type.clone()));
|
||
}
|
||
|
||
dlg.pre_request();
|
||
req.send()
|
||
}
|
||
};
|
||
|
||
match req_result {
|
||
Err(err) => {
|
||
if let oauth2::Retry::After(d) = dlg.http_error(&err) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return Err(Error::HttpError(err))
|
||
}
|
||
Ok(mut res) => {
|
||
if !res.status.is_success() {
|
||
let mut json_err = String::new();
|
||
res.read_to_string(&mut json_err).unwrap();
|
||
if let oauth2::Retry::After(d) = dlg.http_failure(&res,
|
||
json::from_str(&json_err).ok(),
|
||
json::from_str(&json_err).ok()) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return match json::from_str::<ErrorResponse>(&json_err){
|
||
Err(_) => Err(Error::Failure(res)),
|
||
Ok(serr) => Err(Error::BadRequest(serr))
|
||
}
|
||
}
|
||
if protocol == "resumable" {
|
||
let size = reader.seek(io::SeekFrom::End(0)).unwrap();
|
||
reader.seek(io::SeekFrom::Start(0)).unwrap();
|
||
if size > 10485760 {
|
||
return Err(Error::UploadSizeLimitExceeded(size, 10485760))
|
||
}
|
||
let mut client = &mut *self.hub.client.borrow_mut();
|
||
let upload_result = {
|
||
let url_str = &res.headers.get::<Location>().expect("Location header is part of protocol").0;
|
||
if upload_url_from_server {
|
||
dlg.store_upload_url(Some(url_str));
|
||
}
|
||
|
||
cmn::ResumableUploadHelper {
|
||
client: &mut client.borrow_mut(),
|
||
delegate: dlg,
|
||
start_at: if upload_url_from_server { Some(0) } else { None },
|
||
auth: &mut *self.hub.auth.borrow_mut(),
|
||
user_agent: &self.hub._user_agent,
|
||
auth_header: auth_header.clone(),
|
||
url: url_str,
|
||
reader: &mut reader,
|
||
media_type: reader_mime_type.clone(),
|
||
content_length: size
|
||
}.upload()
|
||
};
|
||
match upload_result {
|
||
None => {
|
||
dlg.finished(false);
|
||
return Err(Error::Cancelled)
|
||
}
|
||
Some(Err(err)) => {
|
||
dlg.finished(false);
|
||
return Err(Error::HttpError(err))
|
||
}
|
||
Some(Ok(upload_result)) => {
|
||
res = upload_result;
|
||
if !res.status.is_success() {
|
||
dlg.store_upload_url(None);
|
||
dlg.finished(false);
|
||
return Err(Error::Failure(res))
|
||
}
|
||
}
|
||
}
|
||
}
|
||
let result_value = {
|
||
let mut json_response = String::new();
|
||
res.read_to_string(&mut json_response).unwrap();
|
||
match json::from_str(&json_response) {
|
||
Ok(decoded) => (res, decoded),
|
||
Err(err) => {
|
||
dlg.response_json_decode_error(&json_response, &err);
|
||
return Err(Error::JsonDecodeError(json_response, err));
|
||
}
|
||
}
|
||
};
|
||
|
||
dlg.finished(true);
|
||
return Ok(result_value)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
/// Upload media all at once.
|
||
/// If the upload fails for whichever reason, all progress is lost.
|
||
///
|
||
/// * *max size*: 10MB
|
||
/// * *multipart*: yes
|
||
/// * *valid mime types*: 'audio/*', 'image/*' and 'video/*'
|
||
pub fn upload<RS>(self, stream: RS, mime_type: mime::Mime) -> Result<(hyper::client::Response, TimelineItem)>
|
||
where RS: ReadSeek {
|
||
self.doit(stream, mime_type, "simple")
|
||
}
|
||
/// Upload media in a resumable fashion.
|
||
/// Even if the upload fails or is interrupted, it can be resumed for a
|
||
/// certain amount of time as the server maintains state temporarily.
|
||
///
|
||
/// The delegate will be asked for an `upload_url()`, and if not provided, will be asked to store an upload URL
|
||
/// that was provided by the server, using `store_upload_url(...)`. The upload will be done in chunks, the delegate
|
||
/// may specify the `chunk_size()` and may cancel the operation before each chunk is uploaded, using
|
||
/// `cancel_chunk_upload(...)`.
|
||
///
|
||
/// * *max size*: 10MB
|
||
/// * *multipart*: yes
|
||
/// * *valid mime types*: 'audio/*', 'image/*' and 'video/*'
|
||
pub fn upload_resumable<RS>(self, resumeable_stream: RS, mime_type: mime::Mime) -> Result<(hyper::client::Response, TimelineItem)>
|
||
where RS: ReadSeek {
|
||
self.doit(resumeable_stream, mime_type, "resumable")
|
||
}
|
||
|
||
///
|
||
/// 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: TimelineItem) -> TimelineUpdateCall<'a, C, A> {
|
||
self._request = new_value;
|
||
self
|
||
}
|
||
/// The ID of the timeline item.
|
||
///
|
||
/// Sets the *id* 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 id(mut self, new_value: &str) -> TimelineUpdateCall<'a, C, A> {
|
||
self._id = 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 Delegate) -> TimelineUpdateCall<'a, C, 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 paramters
|
||
/// which have their own setter method. If done anyway, the request will fail.
|
||
///
|
||
/// # Additional Parameters
|
||
///
|
||
/// * *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. Overrides userIp if both are provided.
|
||
/// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
|
||
/// * *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.
|
||
/// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
|
||
/// * *userIp* (query-string) - IP address of the site where the request originates. Use this if you want to enforce per-user limits.
|
||
/// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
|
||
/// * *alt* (query-string) - Data format for the response.
|
||
pub fn param<T>(mut self, name: T, value: T) -> TimelineUpdateCall<'a, C, 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::GlasLocation`.
|
||
///
|
||
/// The `scope` will be added to a set of scopes. This is important as one can maintain access
|
||
/// tokens for more than one scope.
|
||
///
|
||
/// 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>(mut self, scope: T) -> TimelineUpdateCall<'a, C, A>
|
||
where T: AsRef<str> {
|
||
self._scopes.insert(scope.as_ref().to_string(), ());
|
||
self
|
||
}
|
||
}
|
||
|
||
|
||
/// Retrieves an attachment on a timeline item by item ID and attachment ID.
|
||
///
|
||
/// 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 *attachments.get* method supported by a *timeline* resource.
|
||
/// It is not used directly, but through a `TimelineMethods` instance.
|
||
///
|
||
/// # Example
|
||
///
|
||
/// Instantiate a resource method builder
|
||
///
|
||
/// ```test_harness,no_run
|
||
/// # extern crate hyper;
|
||
/// # extern crate yup_oauth2 as oauth2;
|
||
/// # extern crate google_mirror1 as mirror1;
|
||
/// # #[test] fn egal() {
|
||
/// # use std::default::Default;
|
||
/// # use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage};
|
||
/// # use mirror1::Mirror;
|
||
///
|
||
/// # let secret: ApplicationSecret = Default::default();
|
||
/// # let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate,
|
||
/// # hyper::Client::new(),
|
||
/// # <MemoryStorage as Default>::default(), None);
|
||
/// # let mut hub = Mirror::new(hyper::Client::new(), 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.timeline().attachments_get("itemId", "attachmentId")
|
||
/// .doit();
|
||
/// # }
|
||
/// ```
|
||
pub struct TimelineAttachmentGetCall<'a, C, A>
|
||
where C: 'a, A: 'a {
|
||
|
||
hub: &'a Mirror<C, A>,
|
||
_item_id: String,
|
||
_attachment_id: String,
|
||
_delegate: Option<&'a mut Delegate>,
|
||
_additional_params: HashMap<String, String>,
|
||
_scopes: BTreeMap<String, ()>
|
||
}
|
||
|
||
impl<'a, C, A> CallBuilder for TimelineAttachmentGetCall<'a, C, A> {}
|
||
|
||
impl<'a, C, A> TimelineAttachmentGetCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oauth2::GetToken {
|
||
|
||
|
||
/// Perform the operation you have build so far.
|
||
pub fn doit(mut self) -> Result<(hyper::client::Response, Attachment)> {
|
||
use std::io::{Read, Seek};
|
||
use hyper::header::{ContentType, ContentLength, Authorization, Bearer, UserAgent, Location};
|
||
let mut dd = DefaultDelegate;
|
||
let mut dlg: &mut Delegate = match self._delegate {
|
||
Some(d) => d,
|
||
None => &mut dd
|
||
};
|
||
dlg.begin(MethodInfo { id: "mirror.timeline.attachments.get",
|
||
http_method: hyper::method::Method::Get });
|
||
let mut params: Vec<(&str, String)> = Vec::with_capacity((3 + self._additional_params.len()));
|
||
params.push(("itemId", self._item_id.to_string()));
|
||
params.push(("attachmentId", self._attachment_id.to_string()));
|
||
for &field in ["itemId", "attachmentId"].iter() {
|
||
if self._additional_params.contains_key(field) {
|
||
dlg.finished(false);
|
||
return Err(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() + "timeline/{itemId}/attachments/{attachmentId}";
|
||
if self._scopes.len() == 0 {
|
||
self._scopes.insert(Scope::GlasTimeline.as_ref().to_string(), ());
|
||
}
|
||
|
||
for &(find_this, param_name) in [("{itemId}", "itemId"), ("{attachmentId}", "attachmentId")].iter() {
|
||
let mut replace_with: Option<&str> = None;
|
||
for &(name, ref value) in params.iter() {
|
||
if name == param_name {
|
||
replace_with = Some(value);
|
||
break;
|
||
}
|
||
}
|
||
url = url.replace(find_this, replace_with.expect("to find substitution value in params"));
|
||
}
|
||
{
|
||
let mut indices_for_removal: Vec<usize> = Vec::with_capacity(2);
|
||
for param_name in ["attachmentId", "itemId"].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);
|
||
}
|
||
}
|
||
|
||
if params.len() > 0 {
|
||
url.push('?');
|
||
url.push_str(&url::form_urlencoded::serialize(params));
|
||
}
|
||
|
||
|
||
|
||
loop {
|
||
let token = match self.hub.auth.borrow_mut().token(self._scopes.keys()) {
|
||
Ok(token) => token,
|
||
Err(err) => {
|
||
match dlg.token(&*err) {
|
||
Some(token) => token,
|
||
None => {
|
||
dlg.finished(false);
|
||
return Err(Error::MissingToken(err))
|
||
}
|
||
}
|
||
}
|
||
};
|
||
let auth_header = Authorization(Bearer { token: token.access_token });
|
||
let mut req_result = {
|
||
let mut client = &mut *self.hub.client.borrow_mut();
|
||
let mut req = client.borrow_mut().request(hyper::method::Method::Get, &url)
|
||
.header(UserAgent(self.hub._user_agent.clone()))
|
||
.header(auth_header.clone());
|
||
|
||
dlg.pre_request();
|
||
req.send()
|
||
};
|
||
|
||
match req_result {
|
||
Err(err) => {
|
||
if let oauth2::Retry::After(d) = dlg.http_error(&err) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return Err(Error::HttpError(err))
|
||
}
|
||
Ok(mut res) => {
|
||
if !res.status.is_success() {
|
||
let mut json_err = String::new();
|
||
res.read_to_string(&mut json_err).unwrap();
|
||
if let oauth2::Retry::After(d) = dlg.http_failure(&res,
|
||
json::from_str(&json_err).ok(),
|
||
json::from_str(&json_err).ok()) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return match json::from_str::<ErrorResponse>(&json_err){
|
||
Err(_) => Err(Error::Failure(res)),
|
||
Ok(serr) => Err(Error::BadRequest(serr))
|
||
}
|
||
}
|
||
let result_value = if enable_resource_parsing {
|
||
let mut json_response = String::new();
|
||
res.read_to_string(&mut json_response).unwrap();
|
||
match json::from_str(&json_response) {
|
||
Ok(decoded) => (res, decoded),
|
||
Err(err) => {
|
||
dlg.response_json_decode_error(&json_response, &err);
|
||
return Err(Error::JsonDecodeError(json_response, err));
|
||
}
|
||
}
|
||
} else { (res, Default::default()) };
|
||
|
||
dlg.finished(true);
|
||
return Ok(result_value)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
/// The ID of the timeline item the attachment belongs to.
|
||
///
|
||
/// Sets the *item id* 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 item_id(mut self, new_value: &str) -> TimelineAttachmentGetCall<'a, C, A> {
|
||
self._item_id = new_value.to_string();
|
||
self
|
||
}
|
||
/// The ID of the attachment.
|
||
///
|
||
/// Sets the *attachment id* 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 attachment_id(mut self, new_value: &str) -> TimelineAttachmentGetCall<'a, C, A> {
|
||
self._attachment_id = 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 Delegate) -> TimelineAttachmentGetCall<'a, C, 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 paramters
|
||
/// which have their own setter method. If done anyway, the request will fail.
|
||
///
|
||
/// # Additional Parameters
|
||
///
|
||
/// * *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. Overrides userIp if both are provided.
|
||
/// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
|
||
/// * *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.
|
||
/// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
|
||
/// * *userIp* (query-string) - IP address of the site where the request originates. Use this if you want to enforce per-user limits.
|
||
/// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
|
||
/// * *alt* (query-string) - Data format for the response.
|
||
pub fn param<T>(mut self, name: T, value: T) -> TimelineAttachmentGetCall<'a, C, 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::GlasTimeline`.
|
||
///
|
||
/// The `scope` will be added to a set of scopes. This is important as one can maintain access
|
||
/// tokens for more than one scope.
|
||
///
|
||
/// 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>(mut self, scope: T) -> TimelineAttachmentGetCall<'a, C, A>
|
||
where T: AsRef<str> {
|
||
self._scopes.insert(scope.as_ref().to_string(), ());
|
||
self
|
||
}
|
||
}
|
||
|
||
|
||
/// Gets a single timeline item by ID.
|
||
///
|
||
/// A builder for the *get* method supported by a *timeline* resource.
|
||
/// It is not used directly, but through a `TimelineMethods` instance.
|
||
///
|
||
/// # Example
|
||
///
|
||
/// Instantiate a resource method builder
|
||
///
|
||
/// ```test_harness,no_run
|
||
/// # extern crate hyper;
|
||
/// # extern crate yup_oauth2 as oauth2;
|
||
/// # extern crate google_mirror1 as mirror1;
|
||
/// # #[test] fn egal() {
|
||
/// # use std::default::Default;
|
||
/// # use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage};
|
||
/// # use mirror1::Mirror;
|
||
///
|
||
/// # let secret: ApplicationSecret = Default::default();
|
||
/// # let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate,
|
||
/// # hyper::Client::new(),
|
||
/// # <MemoryStorage as Default>::default(), None);
|
||
/// # let mut hub = Mirror::new(hyper::Client::new(), 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.timeline().get("id")
|
||
/// .doit();
|
||
/// # }
|
||
/// ```
|
||
pub struct TimelineGetCall<'a, C, A>
|
||
where C: 'a, A: 'a {
|
||
|
||
hub: &'a Mirror<C, A>,
|
||
_id: String,
|
||
_delegate: Option<&'a mut Delegate>,
|
||
_additional_params: HashMap<String, String>,
|
||
_scopes: BTreeMap<String, ()>
|
||
}
|
||
|
||
impl<'a, C, A> CallBuilder for TimelineGetCall<'a, C, A> {}
|
||
|
||
impl<'a, C, A> TimelineGetCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oauth2::GetToken {
|
||
|
||
|
||
/// Perform the operation you have build so far.
|
||
pub fn doit(mut self) -> Result<(hyper::client::Response, TimelineItem)> {
|
||
use std::io::{Read, Seek};
|
||
use hyper::header::{ContentType, ContentLength, Authorization, Bearer, UserAgent, Location};
|
||
let mut dd = DefaultDelegate;
|
||
let mut dlg: &mut Delegate = match self._delegate {
|
||
Some(d) => d,
|
||
None => &mut dd
|
||
};
|
||
dlg.begin(MethodInfo { id: "mirror.timeline.get",
|
||
http_method: hyper::method::Method::Get });
|
||
let mut params: Vec<(&str, String)> = Vec::with_capacity((3 + self._additional_params.len()));
|
||
params.push(("id", self._id.to_string()));
|
||
for &field in ["alt", "id"].iter() {
|
||
if self._additional_params.contains_key(field) {
|
||
dlg.finished(false);
|
||
return Err(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() + "timeline/{id}";
|
||
if self._scopes.len() == 0 {
|
||
self._scopes.insert(Scope::GlasLocation.as_ref().to_string(), ());
|
||
}
|
||
|
||
for &(find_this, param_name) in [("{id}", "id")].iter() {
|
||
let mut replace_with: Option<&str> = None;
|
||
for &(name, ref value) in params.iter() {
|
||
if name == param_name {
|
||
replace_with = Some(value);
|
||
break;
|
||
}
|
||
}
|
||
url = url.replace(find_this, replace_with.expect("to find substitution value in params"));
|
||
}
|
||
{
|
||
let mut indices_for_removal: Vec<usize> = Vec::with_capacity(1);
|
||
for param_name in ["id"].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);
|
||
}
|
||
}
|
||
|
||
if params.len() > 0 {
|
||
url.push('?');
|
||
url.push_str(&url::form_urlencoded::serialize(params));
|
||
}
|
||
|
||
|
||
|
||
loop {
|
||
let token = match self.hub.auth.borrow_mut().token(self._scopes.keys()) {
|
||
Ok(token) => token,
|
||
Err(err) => {
|
||
match dlg.token(&*err) {
|
||
Some(token) => token,
|
||
None => {
|
||
dlg.finished(false);
|
||
return Err(Error::MissingToken(err))
|
||
}
|
||
}
|
||
}
|
||
};
|
||
let auth_header = Authorization(Bearer { token: token.access_token });
|
||
let mut req_result = {
|
||
let mut client = &mut *self.hub.client.borrow_mut();
|
||
let mut req = client.borrow_mut().request(hyper::method::Method::Get, &url)
|
||
.header(UserAgent(self.hub._user_agent.clone()))
|
||
.header(auth_header.clone());
|
||
|
||
dlg.pre_request();
|
||
req.send()
|
||
};
|
||
|
||
match req_result {
|
||
Err(err) => {
|
||
if let oauth2::Retry::After(d) = dlg.http_error(&err) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return Err(Error::HttpError(err))
|
||
}
|
||
Ok(mut res) => {
|
||
if !res.status.is_success() {
|
||
let mut json_err = String::new();
|
||
res.read_to_string(&mut json_err).unwrap();
|
||
if let oauth2::Retry::After(d) = dlg.http_failure(&res,
|
||
json::from_str(&json_err).ok(),
|
||
json::from_str(&json_err).ok()) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return match json::from_str::<ErrorResponse>(&json_err){
|
||
Err(_) => Err(Error::Failure(res)),
|
||
Ok(serr) => Err(Error::BadRequest(serr))
|
||
}
|
||
}
|
||
let result_value = {
|
||
let mut json_response = String::new();
|
||
res.read_to_string(&mut json_response).unwrap();
|
||
match json::from_str(&json_response) {
|
||
Ok(decoded) => (res, decoded),
|
||
Err(err) => {
|
||
dlg.response_json_decode_error(&json_response, &err);
|
||
return Err(Error::JsonDecodeError(json_response, err));
|
||
}
|
||
}
|
||
};
|
||
|
||
dlg.finished(true);
|
||
return Ok(result_value)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
/// The ID of the timeline item.
|
||
///
|
||
/// Sets the *id* 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 id(mut self, new_value: &str) -> TimelineGetCall<'a, C, A> {
|
||
self._id = 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 Delegate) -> TimelineGetCall<'a, C, 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 paramters
|
||
/// which have their own setter method. If done anyway, the request will fail.
|
||
///
|
||
/// # Additional Parameters
|
||
///
|
||
/// * *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. Overrides userIp if both are provided.
|
||
/// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
|
||
/// * *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.
|
||
/// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
|
||
/// * *userIp* (query-string) - IP address of the site where the request originates. Use this if you want to enforce per-user limits.
|
||
/// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
|
||
/// * *alt* (query-string) - Data format for the response.
|
||
pub fn param<T>(mut self, name: T, value: T) -> TimelineGetCall<'a, C, 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::GlasLocation`.
|
||
///
|
||
/// The `scope` will be added to a set of scopes. This is important as one can maintain access
|
||
/// tokens for more than one scope.
|
||
///
|
||
/// 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>(mut self, scope: T) -> TimelineGetCall<'a, C, A>
|
||
where T: AsRef<str> {
|
||
self._scopes.insert(scope.as_ref().to_string(), ());
|
||
self
|
||
}
|
||
}
|
||
|
||
|
||
/// Gets a single setting by ID.
|
||
///
|
||
/// A builder for the *get* method supported by a *setting* resource.
|
||
/// It is not used directly, but through a `SettingMethods` instance.
|
||
///
|
||
/// # Example
|
||
///
|
||
/// Instantiate a resource method builder
|
||
///
|
||
/// ```test_harness,no_run
|
||
/// # extern crate hyper;
|
||
/// # extern crate yup_oauth2 as oauth2;
|
||
/// # extern crate google_mirror1 as mirror1;
|
||
/// # #[test] fn egal() {
|
||
/// # use std::default::Default;
|
||
/// # use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage};
|
||
/// # use mirror1::Mirror;
|
||
///
|
||
/// # let secret: ApplicationSecret = Default::default();
|
||
/// # let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate,
|
||
/// # hyper::Client::new(),
|
||
/// # <MemoryStorage as Default>::default(), None);
|
||
/// # let mut hub = Mirror::new(hyper::Client::new(), 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.settings().get("id")
|
||
/// .doit();
|
||
/// # }
|
||
/// ```
|
||
pub struct SettingGetCall<'a, C, A>
|
||
where C: 'a, A: 'a {
|
||
|
||
hub: &'a Mirror<C, A>,
|
||
_id: String,
|
||
_delegate: Option<&'a mut Delegate>,
|
||
_additional_params: HashMap<String, String>,
|
||
_scopes: BTreeMap<String, ()>
|
||
}
|
||
|
||
impl<'a, C, A> CallBuilder for SettingGetCall<'a, C, A> {}
|
||
|
||
impl<'a, C, A> SettingGetCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oauth2::GetToken {
|
||
|
||
|
||
/// Perform the operation you have build so far.
|
||
pub fn doit(mut self) -> Result<(hyper::client::Response, Setting)> {
|
||
use std::io::{Read, Seek};
|
||
use hyper::header::{ContentType, ContentLength, Authorization, Bearer, UserAgent, Location};
|
||
let mut dd = DefaultDelegate;
|
||
let mut dlg: &mut Delegate = match self._delegate {
|
||
Some(d) => d,
|
||
None => &mut dd
|
||
};
|
||
dlg.begin(MethodInfo { id: "mirror.settings.get",
|
||
http_method: hyper::method::Method::Get });
|
||
let mut params: Vec<(&str, String)> = Vec::with_capacity((3 + self._additional_params.len()));
|
||
params.push(("id", self._id.to_string()));
|
||
for &field in ["alt", "id"].iter() {
|
||
if self._additional_params.contains_key(field) {
|
||
dlg.finished(false);
|
||
return Err(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() + "settings/{id}";
|
||
if self._scopes.len() == 0 {
|
||
self._scopes.insert(Scope::GlasTimeline.as_ref().to_string(), ());
|
||
}
|
||
|
||
for &(find_this, param_name) in [("{id}", "id")].iter() {
|
||
let mut replace_with: Option<&str> = None;
|
||
for &(name, ref value) in params.iter() {
|
||
if name == param_name {
|
||
replace_with = Some(value);
|
||
break;
|
||
}
|
||
}
|
||
url = url.replace(find_this, replace_with.expect("to find substitution value in params"));
|
||
}
|
||
{
|
||
let mut indices_for_removal: Vec<usize> = Vec::with_capacity(1);
|
||
for param_name in ["id"].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);
|
||
}
|
||
}
|
||
|
||
if params.len() > 0 {
|
||
url.push('?');
|
||
url.push_str(&url::form_urlencoded::serialize(params));
|
||
}
|
||
|
||
|
||
|
||
loop {
|
||
let token = match self.hub.auth.borrow_mut().token(self._scopes.keys()) {
|
||
Ok(token) => token,
|
||
Err(err) => {
|
||
match dlg.token(&*err) {
|
||
Some(token) => token,
|
||
None => {
|
||
dlg.finished(false);
|
||
return Err(Error::MissingToken(err))
|
||
}
|
||
}
|
||
}
|
||
};
|
||
let auth_header = Authorization(Bearer { token: token.access_token });
|
||
let mut req_result = {
|
||
let mut client = &mut *self.hub.client.borrow_mut();
|
||
let mut req = client.borrow_mut().request(hyper::method::Method::Get, &url)
|
||
.header(UserAgent(self.hub._user_agent.clone()))
|
||
.header(auth_header.clone());
|
||
|
||
dlg.pre_request();
|
||
req.send()
|
||
};
|
||
|
||
match req_result {
|
||
Err(err) => {
|
||
if let oauth2::Retry::After(d) = dlg.http_error(&err) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return Err(Error::HttpError(err))
|
||
}
|
||
Ok(mut res) => {
|
||
if !res.status.is_success() {
|
||
let mut json_err = String::new();
|
||
res.read_to_string(&mut json_err).unwrap();
|
||
if let oauth2::Retry::After(d) = dlg.http_failure(&res,
|
||
json::from_str(&json_err).ok(),
|
||
json::from_str(&json_err).ok()) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return match json::from_str::<ErrorResponse>(&json_err){
|
||
Err(_) => Err(Error::Failure(res)),
|
||
Ok(serr) => Err(Error::BadRequest(serr))
|
||
}
|
||
}
|
||
let result_value = {
|
||
let mut json_response = String::new();
|
||
res.read_to_string(&mut json_response).unwrap();
|
||
match json::from_str(&json_response) {
|
||
Ok(decoded) => (res, decoded),
|
||
Err(err) => {
|
||
dlg.response_json_decode_error(&json_response, &err);
|
||
return Err(Error::JsonDecodeError(json_response, err));
|
||
}
|
||
}
|
||
};
|
||
|
||
dlg.finished(true);
|
||
return Ok(result_value)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
/// The ID of the setting. The following IDs are valid:
|
||
/// - locale - The key to the user’s language/locale (BCP 47 identifier) that Glassware should use to render localized content.
|
||
/// - timezone - The key to the user’s current time zone region as defined in the tz database. Example: America/Los_Angeles.
|
||
///
|
||
/// Sets the *id* 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 id(mut self, new_value: &str) -> SettingGetCall<'a, C, A> {
|
||
self._id = 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 Delegate) -> SettingGetCall<'a, C, 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 paramters
|
||
/// which have their own setter method. If done anyway, the request will fail.
|
||
///
|
||
/// # Additional Parameters
|
||
///
|
||
/// * *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. Overrides userIp if both are provided.
|
||
/// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
|
||
/// * *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.
|
||
/// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
|
||
/// * *userIp* (query-string) - IP address of the site where the request originates. Use this if you want to enforce per-user limits.
|
||
/// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
|
||
/// * *alt* (query-string) - Data format for the response.
|
||
pub fn param<T>(mut self, name: T, value: T) -> SettingGetCall<'a, C, 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::GlasTimeline`.
|
||
///
|
||
/// The `scope` will be added to a set of scopes. This is important as one can maintain access
|
||
/// tokens for more than one scope.
|
||
///
|
||
/// 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>(mut self, scope: T) -> SettingGetCall<'a, C, A>
|
||
where T: AsRef<str> {
|
||
self._scopes.insert(scope.as_ref().to_string(), ());
|
||
self
|
||
}
|
||
}
|
||
|
||
|
||
/// Gets a single location by ID.
|
||
///
|
||
/// A builder for the *get* method supported by a *location* resource.
|
||
/// It is not used directly, but through a `LocationMethods` instance.
|
||
///
|
||
/// # Example
|
||
///
|
||
/// Instantiate a resource method builder
|
||
///
|
||
/// ```test_harness,no_run
|
||
/// # extern crate hyper;
|
||
/// # extern crate yup_oauth2 as oauth2;
|
||
/// # extern crate google_mirror1 as mirror1;
|
||
/// # #[test] fn egal() {
|
||
/// # use std::default::Default;
|
||
/// # use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage};
|
||
/// # use mirror1::Mirror;
|
||
///
|
||
/// # let secret: ApplicationSecret = Default::default();
|
||
/// # let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate,
|
||
/// # hyper::Client::new(),
|
||
/// # <MemoryStorage as Default>::default(), None);
|
||
/// # let mut hub = Mirror::new(hyper::Client::new(), 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.locations().get("id")
|
||
/// .doit();
|
||
/// # }
|
||
/// ```
|
||
pub struct LocationGetCall<'a, C, A>
|
||
where C: 'a, A: 'a {
|
||
|
||
hub: &'a Mirror<C, A>,
|
||
_id: String,
|
||
_delegate: Option<&'a mut Delegate>,
|
||
_additional_params: HashMap<String, String>,
|
||
_scopes: BTreeMap<String, ()>
|
||
}
|
||
|
||
impl<'a, C, A> CallBuilder for LocationGetCall<'a, C, A> {}
|
||
|
||
impl<'a, C, A> LocationGetCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oauth2::GetToken {
|
||
|
||
|
||
/// Perform the operation you have build so far.
|
||
pub fn doit(mut self) -> Result<(hyper::client::Response, Location)> {
|
||
use std::io::{Read, Seek};
|
||
use hyper::header::{ContentType, ContentLength, Authorization, Bearer, UserAgent, Location};
|
||
let mut dd = DefaultDelegate;
|
||
let mut dlg: &mut Delegate = match self._delegate {
|
||
Some(d) => d,
|
||
None => &mut dd
|
||
};
|
||
dlg.begin(MethodInfo { id: "mirror.locations.get",
|
||
http_method: hyper::method::Method::Get });
|
||
let mut params: Vec<(&str, String)> = Vec::with_capacity((3 + self._additional_params.len()));
|
||
params.push(("id", self._id.to_string()));
|
||
for &field in ["alt", "id"].iter() {
|
||
if self._additional_params.contains_key(field) {
|
||
dlg.finished(false);
|
||
return Err(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() + "locations/{id}";
|
||
if self._scopes.len() == 0 {
|
||
self._scopes.insert(Scope::GlasLocation.as_ref().to_string(), ());
|
||
}
|
||
|
||
for &(find_this, param_name) in [("{id}", "id")].iter() {
|
||
let mut replace_with: Option<&str> = None;
|
||
for &(name, ref value) in params.iter() {
|
||
if name == param_name {
|
||
replace_with = Some(value);
|
||
break;
|
||
}
|
||
}
|
||
url = url.replace(find_this, replace_with.expect("to find substitution value in params"));
|
||
}
|
||
{
|
||
let mut indices_for_removal: Vec<usize> = Vec::with_capacity(1);
|
||
for param_name in ["id"].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);
|
||
}
|
||
}
|
||
|
||
if params.len() > 0 {
|
||
url.push('?');
|
||
url.push_str(&url::form_urlencoded::serialize(params));
|
||
}
|
||
|
||
|
||
|
||
loop {
|
||
let token = match self.hub.auth.borrow_mut().token(self._scopes.keys()) {
|
||
Ok(token) => token,
|
||
Err(err) => {
|
||
match dlg.token(&*err) {
|
||
Some(token) => token,
|
||
None => {
|
||
dlg.finished(false);
|
||
return Err(Error::MissingToken(err))
|
||
}
|
||
}
|
||
}
|
||
};
|
||
let auth_header = Authorization(Bearer { token: token.access_token });
|
||
let mut req_result = {
|
||
let mut client = &mut *self.hub.client.borrow_mut();
|
||
let mut req = client.borrow_mut().request(hyper::method::Method::Get, &url)
|
||
.header(UserAgent(self.hub._user_agent.clone()))
|
||
.header(auth_header.clone());
|
||
|
||
dlg.pre_request();
|
||
req.send()
|
||
};
|
||
|
||
match req_result {
|
||
Err(err) => {
|
||
if let oauth2::Retry::After(d) = dlg.http_error(&err) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return Err(Error::HttpError(err))
|
||
}
|
||
Ok(mut res) => {
|
||
if !res.status.is_success() {
|
||
let mut json_err = String::new();
|
||
res.read_to_string(&mut json_err).unwrap();
|
||
if let oauth2::Retry::After(d) = dlg.http_failure(&res,
|
||
json::from_str(&json_err).ok(),
|
||
json::from_str(&json_err).ok()) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return match json::from_str::<ErrorResponse>(&json_err){
|
||
Err(_) => Err(Error::Failure(res)),
|
||
Ok(serr) => Err(Error::BadRequest(serr))
|
||
}
|
||
}
|
||
let result_value = {
|
||
let mut json_response = String::new();
|
||
res.read_to_string(&mut json_response).unwrap();
|
||
match json::from_str(&json_response) {
|
||
Ok(decoded) => (res, decoded),
|
||
Err(err) => {
|
||
dlg.response_json_decode_error(&json_response, &err);
|
||
return Err(Error::JsonDecodeError(json_response, err));
|
||
}
|
||
}
|
||
};
|
||
|
||
dlg.finished(true);
|
||
return Ok(result_value)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
/// The ID of the location or latest for the last known location.
|
||
///
|
||
/// Sets the *id* 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 id(mut self, new_value: &str) -> LocationGetCall<'a, C, A> {
|
||
self._id = 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 Delegate) -> LocationGetCall<'a, C, 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 paramters
|
||
/// which have their own setter method. If done anyway, the request will fail.
|
||
///
|
||
/// # Additional Parameters
|
||
///
|
||
/// * *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. Overrides userIp if both are provided.
|
||
/// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
|
||
/// * *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.
|
||
/// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
|
||
/// * *userIp* (query-string) - IP address of the site where the request originates. Use this if you want to enforce per-user limits.
|
||
/// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
|
||
/// * *alt* (query-string) - Data format for the response.
|
||
pub fn param<T>(mut self, name: T, value: T) -> LocationGetCall<'a, C, 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::GlasLocation`.
|
||
///
|
||
/// The `scope` will be added to a set of scopes. This is important as one can maintain access
|
||
/// tokens for more than one scope.
|
||
///
|
||
/// 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>(mut self, scope: T) -> LocationGetCall<'a, C, A>
|
||
where T: AsRef<str> {
|
||
self._scopes.insert(scope.as_ref().to_string(), ());
|
||
self
|
||
}
|
||
}
|
||
|
||
|
||
/// Retrieves a list of locations for the user.
|
||
///
|
||
/// A builder for the *list* method supported by a *location* resource.
|
||
/// It is not used directly, but through a `LocationMethods` instance.
|
||
///
|
||
/// # Example
|
||
///
|
||
/// Instantiate a resource method builder
|
||
///
|
||
/// ```test_harness,no_run
|
||
/// # extern crate hyper;
|
||
/// # extern crate yup_oauth2 as oauth2;
|
||
/// # extern crate google_mirror1 as mirror1;
|
||
/// # #[test] fn egal() {
|
||
/// # use std::default::Default;
|
||
/// # use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage};
|
||
/// # use mirror1::Mirror;
|
||
///
|
||
/// # let secret: ApplicationSecret = Default::default();
|
||
/// # let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate,
|
||
/// # hyper::Client::new(),
|
||
/// # <MemoryStorage as Default>::default(), None);
|
||
/// # let mut hub = Mirror::new(hyper::Client::new(), 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.locations().list()
|
||
/// .doit();
|
||
/// # }
|
||
/// ```
|
||
pub struct LocationListCall<'a, C, A>
|
||
where C: 'a, A: 'a {
|
||
|
||
hub: &'a Mirror<C, A>,
|
||
_delegate: Option<&'a mut Delegate>,
|
||
_additional_params: HashMap<String, String>,
|
||
_scopes: BTreeMap<String, ()>
|
||
}
|
||
|
||
impl<'a, C, A> CallBuilder for LocationListCall<'a, C, A> {}
|
||
|
||
impl<'a, C, A> LocationListCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oauth2::GetToken {
|
||
|
||
|
||
/// Perform the operation you have build so far.
|
||
pub fn doit(mut self) -> Result<(hyper::client::Response, LocationsListResponse)> {
|
||
use std::io::{Read, Seek};
|
||
use hyper::header::{ContentType, ContentLength, Authorization, Bearer, UserAgent, Location};
|
||
let mut dd = DefaultDelegate;
|
||
let mut dlg: &mut Delegate = match self._delegate {
|
||
Some(d) => d,
|
||
None => &mut dd
|
||
};
|
||
dlg.begin(MethodInfo { id: "mirror.locations.list",
|
||
http_method: hyper::method::Method::Get });
|
||
let mut params: Vec<(&str, String)> = Vec::with_capacity((2 + self._additional_params.len()));
|
||
for &field in ["alt"].iter() {
|
||
if self._additional_params.contains_key(field) {
|
||
dlg.finished(false);
|
||
return Err(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() + "locations";
|
||
if self._scopes.len() == 0 {
|
||
self._scopes.insert(Scope::GlasLocation.as_ref().to_string(), ());
|
||
}
|
||
|
||
|
||
if params.len() > 0 {
|
||
url.push('?');
|
||
url.push_str(&url::form_urlencoded::serialize(params));
|
||
}
|
||
|
||
|
||
|
||
loop {
|
||
let token = match self.hub.auth.borrow_mut().token(self._scopes.keys()) {
|
||
Ok(token) => token,
|
||
Err(err) => {
|
||
match dlg.token(&*err) {
|
||
Some(token) => token,
|
||
None => {
|
||
dlg.finished(false);
|
||
return Err(Error::MissingToken(err))
|
||
}
|
||
}
|
||
}
|
||
};
|
||
let auth_header = Authorization(Bearer { token: token.access_token });
|
||
let mut req_result = {
|
||
let mut client = &mut *self.hub.client.borrow_mut();
|
||
let mut req = client.borrow_mut().request(hyper::method::Method::Get, &url)
|
||
.header(UserAgent(self.hub._user_agent.clone()))
|
||
.header(auth_header.clone());
|
||
|
||
dlg.pre_request();
|
||
req.send()
|
||
};
|
||
|
||
match req_result {
|
||
Err(err) => {
|
||
if let oauth2::Retry::After(d) = dlg.http_error(&err) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return Err(Error::HttpError(err))
|
||
}
|
||
Ok(mut res) => {
|
||
if !res.status.is_success() {
|
||
let mut json_err = String::new();
|
||
res.read_to_string(&mut json_err).unwrap();
|
||
if let oauth2::Retry::After(d) = dlg.http_failure(&res,
|
||
json::from_str(&json_err).ok(),
|
||
json::from_str(&json_err).ok()) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return match json::from_str::<ErrorResponse>(&json_err){
|
||
Err(_) => Err(Error::Failure(res)),
|
||
Ok(serr) => Err(Error::BadRequest(serr))
|
||
}
|
||
}
|
||
let result_value = {
|
||
let mut json_response = String::new();
|
||
res.read_to_string(&mut json_response).unwrap();
|
||
match json::from_str(&json_response) {
|
||
Ok(decoded) => (res, decoded),
|
||
Err(err) => {
|
||
dlg.response_json_decode_error(&json_response, &err);
|
||
return Err(Error::JsonDecodeError(json_response, err));
|
||
}
|
||
}
|
||
};
|
||
|
||
dlg.finished(true);
|
||
return Ok(result_value)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
/// 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 Delegate) -> LocationListCall<'a, C, 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 paramters
|
||
/// which have their own setter method. If done anyway, the request will fail.
|
||
///
|
||
/// # Additional Parameters
|
||
///
|
||
/// * *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. Overrides userIp if both are provided.
|
||
/// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
|
||
/// * *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.
|
||
/// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
|
||
/// * *userIp* (query-string) - IP address of the site where the request originates. Use this if you want to enforce per-user limits.
|
||
/// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
|
||
/// * *alt* (query-string) - Data format for the response.
|
||
pub fn param<T>(mut self, name: T, value: T) -> LocationListCall<'a, C, 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::GlasLocation`.
|
||
///
|
||
/// The `scope` will be added to a set of scopes. This is important as one can maintain access
|
||
/// tokens for more than one scope.
|
||
///
|
||
/// 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>(mut self, scope: T) -> LocationListCall<'a, C, A>
|
||
where T: AsRef<str> {
|
||
self._scopes.insert(scope.as_ref().to_string(), ());
|
||
self
|
||
}
|
||
}
|
||
|
||
|
||
/// Inserts a new account for a user
|
||
///
|
||
/// A builder for the *insert* method supported by a *account* resource.
|
||
/// It is not used directly, but through a `AccountMethods` instance.
|
||
///
|
||
/// # Example
|
||
///
|
||
/// Instantiate a resource method builder
|
||
///
|
||
/// ```test_harness,no_run
|
||
/// # extern crate hyper;
|
||
/// # extern crate yup_oauth2 as oauth2;
|
||
/// # extern crate google_mirror1 as mirror1;
|
||
/// use mirror1::Account;
|
||
/// # #[test] fn egal() {
|
||
/// # use std::default::Default;
|
||
/// # use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage};
|
||
/// # use mirror1::Mirror;
|
||
///
|
||
/// # let secret: ApplicationSecret = Default::default();
|
||
/// # let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate,
|
||
/// # hyper::Client::new(),
|
||
/// # <MemoryStorage as Default>::default(), None);
|
||
/// # let mut hub = Mirror::new(hyper::Client::new(), 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 = Account::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.accounts().insert(req, "userToken", "accountType", "accountName")
|
||
/// .doit();
|
||
/// # }
|
||
/// ```
|
||
pub struct AccountInsertCall<'a, C, A>
|
||
where C: 'a, A: 'a {
|
||
|
||
hub: &'a Mirror<C, A>,
|
||
_request: Account,
|
||
_user_token: String,
|
||
_account_type: String,
|
||
_account_name: String,
|
||
_delegate: Option<&'a mut Delegate>,
|
||
_additional_params: HashMap<String, String>,
|
||
}
|
||
|
||
impl<'a, C, A> CallBuilder for AccountInsertCall<'a, C, A> {}
|
||
|
||
impl<'a, C, A> AccountInsertCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oauth2::GetToken {
|
||
|
||
|
||
/// Perform the operation you have build so far.
|
||
pub fn doit(mut self) -> Result<(hyper::client::Response, Account)> {
|
||
use std::io::{Read, Seek};
|
||
use hyper::header::{ContentType, ContentLength, Authorization, Bearer, UserAgent, Location};
|
||
let mut dd = DefaultDelegate;
|
||
let mut dlg: &mut Delegate = match self._delegate {
|
||
Some(d) => d,
|
||
None => &mut dd
|
||
};
|
||
dlg.begin(MethodInfo { id: "mirror.accounts.insert",
|
||
http_method: hyper::method::Method::Post });
|
||
let mut params: Vec<(&str, String)> = Vec::with_capacity((6 + self._additional_params.len()));
|
||
params.push(("userToken", self._user_token.to_string()));
|
||
params.push(("accountType", self._account_type.to_string()));
|
||
params.push(("accountName", self._account_name.to_string()));
|
||
for &field in ["alt", "userToken", "accountType", "accountName"].iter() {
|
||
if self._additional_params.contains_key(field) {
|
||
dlg.finished(false);
|
||
return Err(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() + "accounts/{userToken}/{accountType}/{accountName}";
|
||
|
||
let mut key = self.hub.auth.borrow_mut().api_key();
|
||
if key.is_none() {
|
||
key = dlg.api_key();
|
||
}
|
||
match key {
|
||
Some(value) => params.push(("key", value)),
|
||
None => {
|
||
dlg.finished(false);
|
||
return Err(Error::MissingAPIKey)
|
||
}
|
||
}
|
||
|
||
for &(find_this, param_name) in [("{userToken}", "userToken"), ("{accountType}", "accountType"), ("{accountName}", "accountName")].iter() {
|
||
let mut replace_with: Option<&str> = None;
|
||
for &(name, ref value) in params.iter() {
|
||
if name == param_name {
|
||
replace_with = Some(value);
|
||
break;
|
||
}
|
||
}
|
||
url = url.replace(find_this, replace_with.expect("to find substitution value in params"));
|
||
}
|
||
{
|
||
let mut indices_for_removal: Vec<usize> = Vec::with_capacity(3);
|
||
for param_name in ["accountName", "accountType", "userToken"].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);
|
||
}
|
||
}
|
||
|
||
if params.len() > 0 {
|
||
url.push('?');
|
||
url.push_str(&url::form_urlencoded::serialize(params));
|
||
}
|
||
|
||
let mut json_mime_type = mime::Mime(mime::TopLevel::Application, mime::SubLevel::Json, Default::default());
|
||
let mut request_value_reader =
|
||
{
|
||
let mut value = json::value::to_value(&self._request).expect("serde to work");
|
||
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 {
|
||
request_value_reader.seek(io::SeekFrom::Start(0)).unwrap();
|
||
let mut req_result = {
|
||
let mut client = &mut *self.hub.client.borrow_mut();
|
||
let mut req = client.borrow_mut().request(hyper::method::Method::Post, &url)
|
||
.header(UserAgent(self.hub._user_agent.clone()))
|
||
.header(ContentType(json_mime_type.clone()))
|
||
.header(ContentLength(request_size as u64))
|
||
.body(&mut request_value_reader);
|
||
|
||
dlg.pre_request();
|
||
req.send()
|
||
};
|
||
|
||
match req_result {
|
||
Err(err) => {
|
||
if let oauth2::Retry::After(d) = dlg.http_error(&err) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return Err(Error::HttpError(err))
|
||
}
|
||
Ok(mut res) => {
|
||
if !res.status.is_success() {
|
||
let mut json_err = String::new();
|
||
res.read_to_string(&mut json_err).unwrap();
|
||
if let oauth2::Retry::After(d) = dlg.http_failure(&res,
|
||
json::from_str(&json_err).ok(),
|
||
json::from_str(&json_err).ok()) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return match json::from_str::<ErrorResponse>(&json_err){
|
||
Err(_) => Err(Error::Failure(res)),
|
||
Ok(serr) => Err(Error::BadRequest(serr))
|
||
}
|
||
}
|
||
let result_value = {
|
||
let mut json_response = String::new();
|
||
res.read_to_string(&mut json_response).unwrap();
|
||
match json::from_str(&json_response) {
|
||
Ok(decoded) => (res, decoded),
|
||
Err(err) => {
|
||
dlg.response_json_decode_error(&json_response, &err);
|
||
return Err(Error::JsonDecodeError(json_response, 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: Account) -> AccountInsertCall<'a, C, A> {
|
||
self._request = new_value;
|
||
self
|
||
}
|
||
/// The ID for the user.
|
||
///
|
||
/// Sets the *user token* 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 user_token(mut self, new_value: &str) -> AccountInsertCall<'a, C, A> {
|
||
self._user_token = new_value.to_string();
|
||
self
|
||
}
|
||
/// Account type to be passed to Android Account Manager.
|
||
///
|
||
/// Sets the *account type* 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 account_type(mut self, new_value: &str) -> AccountInsertCall<'a, C, A> {
|
||
self._account_type = new_value.to_string();
|
||
self
|
||
}
|
||
/// The name of the account to be passed to the Android Account Manager.
|
||
///
|
||
/// Sets the *account 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 account_name(mut self, new_value: &str) -> AccountInsertCall<'a, C, A> {
|
||
self._account_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 Delegate) -> AccountInsertCall<'a, C, 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 paramters
|
||
/// which have their own setter method. If done anyway, the request will fail.
|
||
///
|
||
/// # Additional Parameters
|
||
///
|
||
/// * *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. Overrides userIp if both are provided.
|
||
/// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
|
||
/// * *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.
|
||
/// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
|
||
/// * *userIp* (query-string) - IP address of the site where the request originates. Use this if you want to enforce per-user limits.
|
||
/// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
|
||
/// * *alt* (query-string) - Data format for the response.
|
||
pub fn param<T>(mut self, name: T, value: T) -> AccountInsertCall<'a, C, A>
|
||
where T: AsRef<str> {
|
||
self._additional_params.insert(name.as_ref().to_string(), value.as_ref().to_string());
|
||
self
|
||
}
|
||
|
||
}
|
||
|
||
|
||
/// Gets a single contact by ID.
|
||
///
|
||
/// A builder for the *get* method supported by a *contact* resource.
|
||
/// It is not used directly, but through a `ContactMethods` instance.
|
||
///
|
||
/// # Example
|
||
///
|
||
/// Instantiate a resource method builder
|
||
///
|
||
/// ```test_harness,no_run
|
||
/// # extern crate hyper;
|
||
/// # extern crate yup_oauth2 as oauth2;
|
||
/// # extern crate google_mirror1 as mirror1;
|
||
/// # #[test] fn egal() {
|
||
/// # use std::default::Default;
|
||
/// # use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage};
|
||
/// # use mirror1::Mirror;
|
||
///
|
||
/// # let secret: ApplicationSecret = Default::default();
|
||
/// # let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate,
|
||
/// # hyper::Client::new(),
|
||
/// # <MemoryStorage as Default>::default(), None);
|
||
/// # let mut hub = Mirror::new(hyper::Client::new(), 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.contacts().get("id")
|
||
/// .doit();
|
||
/// # }
|
||
/// ```
|
||
pub struct ContactGetCall<'a, C, A>
|
||
where C: 'a, A: 'a {
|
||
|
||
hub: &'a Mirror<C, A>,
|
||
_id: String,
|
||
_delegate: Option<&'a mut Delegate>,
|
||
_additional_params: HashMap<String, String>,
|
||
_scopes: BTreeMap<String, ()>
|
||
}
|
||
|
||
impl<'a, C, A> CallBuilder for ContactGetCall<'a, C, A> {}
|
||
|
||
impl<'a, C, A> ContactGetCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oauth2::GetToken {
|
||
|
||
|
||
/// Perform the operation you have build so far.
|
||
pub fn doit(mut self) -> Result<(hyper::client::Response, Contact)> {
|
||
use std::io::{Read, Seek};
|
||
use hyper::header::{ContentType, ContentLength, Authorization, Bearer, UserAgent, Location};
|
||
let mut dd = DefaultDelegate;
|
||
let mut dlg: &mut Delegate = match self._delegate {
|
||
Some(d) => d,
|
||
None => &mut dd
|
||
};
|
||
dlg.begin(MethodInfo { id: "mirror.contacts.get",
|
||
http_method: hyper::method::Method::Get });
|
||
let mut params: Vec<(&str, String)> = Vec::with_capacity((3 + self._additional_params.len()));
|
||
params.push(("id", self._id.to_string()));
|
||
for &field in ["alt", "id"].iter() {
|
||
if self._additional_params.contains_key(field) {
|
||
dlg.finished(false);
|
||
return Err(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() + "contacts/{id}";
|
||
if self._scopes.len() == 0 {
|
||
self._scopes.insert(Scope::GlasTimeline.as_ref().to_string(), ());
|
||
}
|
||
|
||
for &(find_this, param_name) in [("{id}", "id")].iter() {
|
||
let mut replace_with: Option<&str> = None;
|
||
for &(name, ref value) in params.iter() {
|
||
if name == param_name {
|
||
replace_with = Some(value);
|
||
break;
|
||
}
|
||
}
|
||
url = url.replace(find_this, replace_with.expect("to find substitution value in params"));
|
||
}
|
||
{
|
||
let mut indices_for_removal: Vec<usize> = Vec::with_capacity(1);
|
||
for param_name in ["id"].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);
|
||
}
|
||
}
|
||
|
||
if params.len() > 0 {
|
||
url.push('?');
|
||
url.push_str(&url::form_urlencoded::serialize(params));
|
||
}
|
||
|
||
|
||
|
||
loop {
|
||
let token = match self.hub.auth.borrow_mut().token(self._scopes.keys()) {
|
||
Ok(token) => token,
|
||
Err(err) => {
|
||
match dlg.token(&*err) {
|
||
Some(token) => token,
|
||
None => {
|
||
dlg.finished(false);
|
||
return Err(Error::MissingToken(err))
|
||
}
|
||
}
|
||
}
|
||
};
|
||
let auth_header = Authorization(Bearer { token: token.access_token });
|
||
let mut req_result = {
|
||
let mut client = &mut *self.hub.client.borrow_mut();
|
||
let mut req = client.borrow_mut().request(hyper::method::Method::Get, &url)
|
||
.header(UserAgent(self.hub._user_agent.clone()))
|
||
.header(auth_header.clone());
|
||
|
||
dlg.pre_request();
|
||
req.send()
|
||
};
|
||
|
||
match req_result {
|
||
Err(err) => {
|
||
if let oauth2::Retry::After(d) = dlg.http_error(&err) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return Err(Error::HttpError(err))
|
||
}
|
||
Ok(mut res) => {
|
||
if !res.status.is_success() {
|
||
let mut json_err = String::new();
|
||
res.read_to_string(&mut json_err).unwrap();
|
||
if let oauth2::Retry::After(d) = dlg.http_failure(&res,
|
||
json::from_str(&json_err).ok(),
|
||
json::from_str(&json_err).ok()) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return match json::from_str::<ErrorResponse>(&json_err){
|
||
Err(_) => Err(Error::Failure(res)),
|
||
Ok(serr) => Err(Error::BadRequest(serr))
|
||
}
|
||
}
|
||
let result_value = {
|
||
let mut json_response = String::new();
|
||
res.read_to_string(&mut json_response).unwrap();
|
||
match json::from_str(&json_response) {
|
||
Ok(decoded) => (res, decoded),
|
||
Err(err) => {
|
||
dlg.response_json_decode_error(&json_response, &err);
|
||
return Err(Error::JsonDecodeError(json_response, err));
|
||
}
|
||
}
|
||
};
|
||
|
||
dlg.finished(true);
|
||
return Ok(result_value)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
/// The ID of the contact.
|
||
///
|
||
/// Sets the *id* 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 id(mut self, new_value: &str) -> ContactGetCall<'a, C, A> {
|
||
self._id = 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 Delegate) -> ContactGetCall<'a, C, 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 paramters
|
||
/// which have their own setter method. If done anyway, the request will fail.
|
||
///
|
||
/// # Additional Parameters
|
||
///
|
||
/// * *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. Overrides userIp if both are provided.
|
||
/// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
|
||
/// * *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.
|
||
/// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
|
||
/// * *userIp* (query-string) - IP address of the site where the request originates. Use this if you want to enforce per-user limits.
|
||
/// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
|
||
/// * *alt* (query-string) - Data format for the response.
|
||
pub fn param<T>(mut self, name: T, value: T) -> ContactGetCall<'a, C, 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::GlasTimeline`.
|
||
///
|
||
/// The `scope` will be added to a set of scopes. This is important as one can maintain access
|
||
/// tokens for more than one scope.
|
||
///
|
||
/// 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>(mut self, scope: T) -> ContactGetCall<'a, C, A>
|
||
where T: AsRef<str> {
|
||
self._scopes.insert(scope.as_ref().to_string(), ());
|
||
self
|
||
}
|
||
}
|
||
|
||
|
||
/// Deletes a contact.
|
||
///
|
||
/// A builder for the *delete* method supported by a *contact* resource.
|
||
/// It is not used directly, but through a `ContactMethods` instance.
|
||
///
|
||
/// # Example
|
||
///
|
||
/// Instantiate a resource method builder
|
||
///
|
||
/// ```test_harness,no_run
|
||
/// # extern crate hyper;
|
||
/// # extern crate yup_oauth2 as oauth2;
|
||
/// # extern crate google_mirror1 as mirror1;
|
||
/// # #[test] fn egal() {
|
||
/// # use std::default::Default;
|
||
/// # use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage};
|
||
/// # use mirror1::Mirror;
|
||
///
|
||
/// # let secret: ApplicationSecret = Default::default();
|
||
/// # let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate,
|
||
/// # hyper::Client::new(),
|
||
/// # <MemoryStorage as Default>::default(), None);
|
||
/// # let mut hub = Mirror::new(hyper::Client::new(), 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.contacts().delete("id")
|
||
/// .doit();
|
||
/// # }
|
||
/// ```
|
||
pub struct ContactDeleteCall<'a, C, A>
|
||
where C: 'a, A: 'a {
|
||
|
||
hub: &'a Mirror<C, A>,
|
||
_id: String,
|
||
_delegate: Option<&'a mut Delegate>,
|
||
_additional_params: HashMap<String, String>,
|
||
_scopes: BTreeMap<String, ()>
|
||
}
|
||
|
||
impl<'a, C, A> CallBuilder for ContactDeleteCall<'a, C, A> {}
|
||
|
||
impl<'a, C, A> ContactDeleteCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oauth2::GetToken {
|
||
|
||
|
||
/// Perform the operation you have build so far.
|
||
pub fn doit(mut self) -> Result<hyper::client::Response> {
|
||
use std::io::{Read, Seek};
|
||
use hyper::header::{ContentType, ContentLength, Authorization, Bearer, UserAgent, Location};
|
||
let mut dd = DefaultDelegate;
|
||
let mut dlg: &mut Delegate = match self._delegate {
|
||
Some(d) => d,
|
||
None => &mut dd
|
||
};
|
||
dlg.begin(MethodInfo { id: "mirror.contacts.delete",
|
||
http_method: hyper::method::Method::Delete });
|
||
let mut params: Vec<(&str, String)> = Vec::with_capacity((2 + self._additional_params.len()));
|
||
params.push(("id", self._id.to_string()));
|
||
for &field in ["id"].iter() {
|
||
if self._additional_params.contains_key(field) {
|
||
dlg.finished(false);
|
||
return Err(Error::FieldClash(field));
|
||
}
|
||
}
|
||
for (name, value) in self._additional_params.iter() {
|
||
params.push((&name, value.clone()));
|
||
}
|
||
|
||
|
||
let mut url = self.hub._base_url.clone() + "contacts/{id}";
|
||
if self._scopes.len() == 0 {
|
||
self._scopes.insert(Scope::GlasTimeline.as_ref().to_string(), ());
|
||
}
|
||
|
||
for &(find_this, param_name) in [("{id}", "id")].iter() {
|
||
let mut replace_with: Option<&str> = None;
|
||
for &(name, ref value) in params.iter() {
|
||
if name == param_name {
|
||
replace_with = Some(value);
|
||
break;
|
||
}
|
||
}
|
||
url = url.replace(find_this, replace_with.expect("to find substitution value in params"));
|
||
}
|
||
{
|
||
let mut indices_for_removal: Vec<usize> = Vec::with_capacity(1);
|
||
for param_name in ["id"].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);
|
||
}
|
||
}
|
||
|
||
if params.len() > 0 {
|
||
url.push('?');
|
||
url.push_str(&url::form_urlencoded::serialize(params));
|
||
}
|
||
|
||
|
||
|
||
loop {
|
||
let token = match self.hub.auth.borrow_mut().token(self._scopes.keys()) {
|
||
Ok(token) => token,
|
||
Err(err) => {
|
||
match dlg.token(&*err) {
|
||
Some(token) => token,
|
||
None => {
|
||
dlg.finished(false);
|
||
return Err(Error::MissingToken(err))
|
||
}
|
||
}
|
||
}
|
||
};
|
||
let auth_header = Authorization(Bearer { token: token.access_token });
|
||
let mut req_result = {
|
||
let mut client = &mut *self.hub.client.borrow_mut();
|
||
let mut req = client.borrow_mut().request(hyper::method::Method::Delete, &url)
|
||
.header(UserAgent(self.hub._user_agent.clone()))
|
||
.header(auth_header.clone());
|
||
|
||
dlg.pre_request();
|
||
req.send()
|
||
};
|
||
|
||
match req_result {
|
||
Err(err) => {
|
||
if let oauth2::Retry::After(d) = dlg.http_error(&err) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return Err(Error::HttpError(err))
|
||
}
|
||
Ok(mut res) => {
|
||
if !res.status.is_success() {
|
||
let mut json_err = String::new();
|
||
res.read_to_string(&mut json_err).unwrap();
|
||
if let oauth2::Retry::After(d) = dlg.http_failure(&res,
|
||
json::from_str(&json_err).ok(),
|
||
json::from_str(&json_err).ok()) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return match json::from_str::<ErrorResponse>(&json_err){
|
||
Err(_) => Err(Error::Failure(res)),
|
||
Ok(serr) => Err(Error::BadRequest(serr))
|
||
}
|
||
}
|
||
let result_value = res;
|
||
|
||
dlg.finished(true);
|
||
return Ok(result_value)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
/// The ID of the contact.
|
||
///
|
||
/// Sets the *id* 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 id(mut self, new_value: &str) -> ContactDeleteCall<'a, C, A> {
|
||
self._id = 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 Delegate) -> ContactDeleteCall<'a, C, 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 paramters
|
||
/// which have their own setter method. If done anyway, the request will fail.
|
||
///
|
||
/// # Additional Parameters
|
||
///
|
||
/// * *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. Overrides userIp if both are provided.
|
||
/// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
|
||
/// * *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.
|
||
/// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
|
||
/// * *userIp* (query-string) - IP address of the site where the request originates. Use this if you want to enforce per-user limits.
|
||
/// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
|
||
/// * *alt* (query-string) - Data format for the response.
|
||
pub fn param<T>(mut self, name: T, value: T) -> ContactDeleteCall<'a, C, 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::GlasTimeline`.
|
||
///
|
||
/// The `scope` will be added to a set of scopes. This is important as one can maintain access
|
||
/// tokens for more than one scope.
|
||
///
|
||
/// 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>(mut self, scope: T) -> ContactDeleteCall<'a, C, A>
|
||
where T: AsRef<str> {
|
||
self._scopes.insert(scope.as_ref().to_string(), ());
|
||
self
|
||
}
|
||
}
|
||
|
||
|
||
/// Inserts a new contact.
|
||
///
|
||
/// A builder for the *insert* method supported by a *contact* resource.
|
||
/// It is not used directly, but through a `ContactMethods` instance.
|
||
///
|
||
/// # Example
|
||
///
|
||
/// Instantiate a resource method builder
|
||
///
|
||
/// ```test_harness,no_run
|
||
/// # extern crate hyper;
|
||
/// # extern crate yup_oauth2 as oauth2;
|
||
/// # extern crate google_mirror1 as mirror1;
|
||
/// use mirror1::Contact;
|
||
/// # #[test] fn egal() {
|
||
/// # use std::default::Default;
|
||
/// # use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage};
|
||
/// # use mirror1::Mirror;
|
||
///
|
||
/// # let secret: ApplicationSecret = Default::default();
|
||
/// # let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate,
|
||
/// # hyper::Client::new(),
|
||
/// # <MemoryStorage as Default>::default(), None);
|
||
/// # let mut hub = Mirror::new(hyper::Client::new(), 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 = Contact::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.contacts().insert(req)
|
||
/// .doit();
|
||
/// # }
|
||
/// ```
|
||
pub struct ContactInsertCall<'a, C, A>
|
||
where C: 'a, A: 'a {
|
||
|
||
hub: &'a Mirror<C, A>,
|
||
_request: Contact,
|
||
_delegate: Option<&'a mut Delegate>,
|
||
_additional_params: HashMap<String, String>,
|
||
_scopes: BTreeMap<String, ()>
|
||
}
|
||
|
||
impl<'a, C, A> CallBuilder for ContactInsertCall<'a, C, A> {}
|
||
|
||
impl<'a, C, A> ContactInsertCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oauth2::GetToken {
|
||
|
||
|
||
/// Perform the operation you have build so far.
|
||
pub fn doit(mut self) -> Result<(hyper::client::Response, Contact)> {
|
||
use std::io::{Read, Seek};
|
||
use hyper::header::{ContentType, ContentLength, Authorization, Bearer, UserAgent, Location};
|
||
let mut dd = DefaultDelegate;
|
||
let mut dlg: &mut Delegate = match self._delegate {
|
||
Some(d) => d,
|
||
None => &mut dd
|
||
};
|
||
dlg.begin(MethodInfo { id: "mirror.contacts.insert",
|
||
http_method: hyper::method::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(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() + "contacts";
|
||
if self._scopes.len() == 0 {
|
||
self._scopes.insert(Scope::GlasTimeline.as_ref().to_string(), ());
|
||
}
|
||
|
||
|
||
if params.len() > 0 {
|
||
url.push('?');
|
||
url.push_str(&url::form_urlencoded::serialize(params));
|
||
}
|
||
|
||
let mut json_mime_type = mime::Mime(mime::TopLevel::Application, mime::SubLevel::Json, Default::default());
|
||
let mut request_value_reader =
|
||
{
|
||
let mut value = json::value::to_value(&self._request).expect("serde to work");
|
||
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.borrow_mut().token(self._scopes.keys()) {
|
||
Ok(token) => token,
|
||
Err(err) => {
|
||
match dlg.token(&*err) {
|
||
Some(token) => token,
|
||
None => {
|
||
dlg.finished(false);
|
||
return Err(Error::MissingToken(err))
|
||
}
|
||
}
|
||
}
|
||
};
|
||
let auth_header = Authorization(Bearer { token: token.access_token });
|
||
request_value_reader.seek(io::SeekFrom::Start(0)).unwrap();
|
||
let mut req_result = {
|
||
let mut client = &mut *self.hub.client.borrow_mut();
|
||
let mut req = client.borrow_mut().request(hyper::method::Method::Post, &url)
|
||
.header(UserAgent(self.hub._user_agent.clone()))
|
||
.header(auth_header.clone())
|
||
.header(ContentType(json_mime_type.clone()))
|
||
.header(ContentLength(request_size as u64))
|
||
.body(&mut request_value_reader);
|
||
|
||
dlg.pre_request();
|
||
req.send()
|
||
};
|
||
|
||
match req_result {
|
||
Err(err) => {
|
||
if let oauth2::Retry::After(d) = dlg.http_error(&err) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return Err(Error::HttpError(err))
|
||
}
|
||
Ok(mut res) => {
|
||
if !res.status.is_success() {
|
||
let mut json_err = String::new();
|
||
res.read_to_string(&mut json_err).unwrap();
|
||
if let oauth2::Retry::After(d) = dlg.http_failure(&res,
|
||
json::from_str(&json_err).ok(),
|
||
json::from_str(&json_err).ok()) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return match json::from_str::<ErrorResponse>(&json_err){
|
||
Err(_) => Err(Error::Failure(res)),
|
||
Ok(serr) => Err(Error::BadRequest(serr))
|
||
}
|
||
}
|
||
let result_value = {
|
||
let mut json_response = String::new();
|
||
res.read_to_string(&mut json_response).unwrap();
|
||
match json::from_str(&json_response) {
|
||
Ok(decoded) => (res, decoded),
|
||
Err(err) => {
|
||
dlg.response_json_decode_error(&json_response, &err);
|
||
return Err(Error::JsonDecodeError(json_response, 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: Contact) -> ContactInsertCall<'a, C, 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 Delegate) -> ContactInsertCall<'a, C, 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 paramters
|
||
/// which have their own setter method. If done anyway, the request will fail.
|
||
///
|
||
/// # Additional Parameters
|
||
///
|
||
/// * *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. Overrides userIp if both are provided.
|
||
/// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
|
||
/// * *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.
|
||
/// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
|
||
/// * *userIp* (query-string) - IP address of the site where the request originates. Use this if you want to enforce per-user limits.
|
||
/// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
|
||
/// * *alt* (query-string) - Data format for the response.
|
||
pub fn param<T>(mut self, name: T, value: T) -> ContactInsertCall<'a, C, 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::GlasTimeline`.
|
||
///
|
||
/// The `scope` will be added to a set of scopes. This is important as one can maintain access
|
||
/// tokens for more than one scope.
|
||
///
|
||
/// 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>(mut self, scope: T) -> ContactInsertCall<'a, C, A>
|
||
where T: AsRef<str> {
|
||
self._scopes.insert(scope.as_ref().to_string(), ());
|
||
self
|
||
}
|
||
}
|
||
|
||
|
||
/// Updates a contact in place. This method supports patch semantics.
|
||
///
|
||
/// A builder for the *patch* method supported by a *contact* resource.
|
||
/// It is not used directly, but through a `ContactMethods` instance.
|
||
///
|
||
/// # Example
|
||
///
|
||
/// Instantiate a resource method builder
|
||
///
|
||
/// ```test_harness,no_run
|
||
/// # extern crate hyper;
|
||
/// # extern crate yup_oauth2 as oauth2;
|
||
/// # extern crate google_mirror1 as mirror1;
|
||
/// use mirror1::Contact;
|
||
/// # #[test] fn egal() {
|
||
/// # use std::default::Default;
|
||
/// # use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage};
|
||
/// # use mirror1::Mirror;
|
||
///
|
||
/// # let secret: ApplicationSecret = Default::default();
|
||
/// # let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate,
|
||
/// # hyper::Client::new(),
|
||
/// # <MemoryStorage as Default>::default(), None);
|
||
/// # let mut hub = Mirror::new(hyper::Client::new(), 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 = Contact::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.contacts().patch(req, "id")
|
||
/// .doit();
|
||
/// # }
|
||
/// ```
|
||
pub struct ContactPatchCall<'a, C, A>
|
||
where C: 'a, A: 'a {
|
||
|
||
hub: &'a Mirror<C, A>,
|
||
_request: Contact,
|
||
_id: String,
|
||
_delegate: Option<&'a mut Delegate>,
|
||
_additional_params: HashMap<String, String>,
|
||
_scopes: BTreeMap<String, ()>
|
||
}
|
||
|
||
impl<'a, C, A> CallBuilder for ContactPatchCall<'a, C, A> {}
|
||
|
||
impl<'a, C, A> ContactPatchCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oauth2::GetToken {
|
||
|
||
|
||
/// Perform the operation you have build so far.
|
||
pub fn doit(mut self) -> Result<(hyper::client::Response, Contact)> {
|
||
use std::io::{Read, Seek};
|
||
use hyper::header::{ContentType, ContentLength, Authorization, Bearer, UserAgent, Location};
|
||
let mut dd = DefaultDelegate;
|
||
let mut dlg: &mut Delegate = match self._delegate {
|
||
Some(d) => d,
|
||
None => &mut dd
|
||
};
|
||
dlg.begin(MethodInfo { id: "mirror.contacts.patch",
|
||
http_method: hyper::method::Method::Patch });
|
||
let mut params: Vec<(&str, String)> = Vec::with_capacity((4 + self._additional_params.len()));
|
||
params.push(("id", self._id.to_string()));
|
||
for &field in ["alt", "id"].iter() {
|
||
if self._additional_params.contains_key(field) {
|
||
dlg.finished(false);
|
||
return Err(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() + "contacts/{id}";
|
||
if self._scopes.len() == 0 {
|
||
self._scopes.insert(Scope::GlasTimeline.as_ref().to_string(), ());
|
||
}
|
||
|
||
for &(find_this, param_name) in [("{id}", "id")].iter() {
|
||
let mut replace_with: Option<&str> = None;
|
||
for &(name, ref value) in params.iter() {
|
||
if name == param_name {
|
||
replace_with = Some(value);
|
||
break;
|
||
}
|
||
}
|
||
url = url.replace(find_this, replace_with.expect("to find substitution value in params"));
|
||
}
|
||
{
|
||
let mut indices_for_removal: Vec<usize> = Vec::with_capacity(1);
|
||
for param_name in ["id"].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);
|
||
}
|
||
}
|
||
|
||
if params.len() > 0 {
|
||
url.push('?');
|
||
url.push_str(&url::form_urlencoded::serialize(params));
|
||
}
|
||
|
||
let mut json_mime_type = mime::Mime(mime::TopLevel::Application, mime::SubLevel::Json, Default::default());
|
||
let mut request_value_reader =
|
||
{
|
||
let mut value = json::value::to_value(&self._request).expect("serde to work");
|
||
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.borrow_mut().token(self._scopes.keys()) {
|
||
Ok(token) => token,
|
||
Err(err) => {
|
||
match dlg.token(&*err) {
|
||
Some(token) => token,
|
||
None => {
|
||
dlg.finished(false);
|
||
return Err(Error::MissingToken(err))
|
||
}
|
||
}
|
||
}
|
||
};
|
||
let auth_header = Authorization(Bearer { token: token.access_token });
|
||
request_value_reader.seek(io::SeekFrom::Start(0)).unwrap();
|
||
let mut req_result = {
|
||
let mut client = &mut *self.hub.client.borrow_mut();
|
||
let mut req = client.borrow_mut().request(hyper::method::Method::Patch, &url)
|
||
.header(UserAgent(self.hub._user_agent.clone()))
|
||
.header(auth_header.clone())
|
||
.header(ContentType(json_mime_type.clone()))
|
||
.header(ContentLength(request_size as u64))
|
||
.body(&mut request_value_reader);
|
||
|
||
dlg.pre_request();
|
||
req.send()
|
||
};
|
||
|
||
match req_result {
|
||
Err(err) => {
|
||
if let oauth2::Retry::After(d) = dlg.http_error(&err) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return Err(Error::HttpError(err))
|
||
}
|
||
Ok(mut res) => {
|
||
if !res.status.is_success() {
|
||
let mut json_err = String::new();
|
||
res.read_to_string(&mut json_err).unwrap();
|
||
if let oauth2::Retry::After(d) = dlg.http_failure(&res,
|
||
json::from_str(&json_err).ok(),
|
||
json::from_str(&json_err).ok()) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return match json::from_str::<ErrorResponse>(&json_err){
|
||
Err(_) => Err(Error::Failure(res)),
|
||
Ok(serr) => Err(Error::BadRequest(serr))
|
||
}
|
||
}
|
||
let result_value = {
|
||
let mut json_response = String::new();
|
||
res.read_to_string(&mut json_response).unwrap();
|
||
match json::from_str(&json_response) {
|
||
Ok(decoded) => (res, decoded),
|
||
Err(err) => {
|
||
dlg.response_json_decode_error(&json_response, &err);
|
||
return Err(Error::JsonDecodeError(json_response, 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: Contact) -> ContactPatchCall<'a, C, A> {
|
||
self._request = new_value;
|
||
self
|
||
}
|
||
/// The ID of the contact.
|
||
///
|
||
/// Sets the *id* 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 id(mut self, new_value: &str) -> ContactPatchCall<'a, C, A> {
|
||
self._id = 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 Delegate) -> ContactPatchCall<'a, C, 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 paramters
|
||
/// which have their own setter method. If done anyway, the request will fail.
|
||
///
|
||
/// # Additional Parameters
|
||
///
|
||
/// * *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. Overrides userIp if both are provided.
|
||
/// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
|
||
/// * *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.
|
||
/// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
|
||
/// * *userIp* (query-string) - IP address of the site where the request originates. Use this if you want to enforce per-user limits.
|
||
/// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
|
||
/// * *alt* (query-string) - Data format for the response.
|
||
pub fn param<T>(mut self, name: T, value: T) -> ContactPatchCall<'a, C, 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::GlasTimeline`.
|
||
///
|
||
/// The `scope` will be added to a set of scopes. This is important as one can maintain access
|
||
/// tokens for more than one scope.
|
||
///
|
||
/// 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>(mut self, scope: T) -> ContactPatchCall<'a, C, A>
|
||
where T: AsRef<str> {
|
||
self._scopes.insert(scope.as_ref().to_string(), ());
|
||
self
|
||
}
|
||
}
|
||
|
||
|
||
/// Retrieves a list of contacts for the authenticated user.
|
||
///
|
||
/// A builder for the *list* method supported by a *contact* resource.
|
||
/// It is not used directly, but through a `ContactMethods` instance.
|
||
///
|
||
/// # Example
|
||
///
|
||
/// Instantiate a resource method builder
|
||
///
|
||
/// ```test_harness,no_run
|
||
/// # extern crate hyper;
|
||
/// # extern crate yup_oauth2 as oauth2;
|
||
/// # extern crate google_mirror1 as mirror1;
|
||
/// # #[test] fn egal() {
|
||
/// # use std::default::Default;
|
||
/// # use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage};
|
||
/// # use mirror1::Mirror;
|
||
///
|
||
/// # let secret: ApplicationSecret = Default::default();
|
||
/// # let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate,
|
||
/// # hyper::Client::new(),
|
||
/// # <MemoryStorage as Default>::default(), None);
|
||
/// # let mut hub = Mirror::new(hyper::Client::new(), 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.contacts().list()
|
||
/// .doit();
|
||
/// # }
|
||
/// ```
|
||
pub struct ContactListCall<'a, C, A>
|
||
where C: 'a, A: 'a {
|
||
|
||
hub: &'a Mirror<C, A>,
|
||
_delegate: Option<&'a mut Delegate>,
|
||
_additional_params: HashMap<String, String>,
|
||
_scopes: BTreeMap<String, ()>
|
||
}
|
||
|
||
impl<'a, C, A> CallBuilder for ContactListCall<'a, C, A> {}
|
||
|
||
impl<'a, C, A> ContactListCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oauth2::GetToken {
|
||
|
||
|
||
/// Perform the operation you have build so far.
|
||
pub fn doit(mut self) -> Result<(hyper::client::Response, ContactsListResponse)> {
|
||
use std::io::{Read, Seek};
|
||
use hyper::header::{ContentType, ContentLength, Authorization, Bearer, UserAgent, Location};
|
||
let mut dd = DefaultDelegate;
|
||
let mut dlg: &mut Delegate = match self._delegate {
|
||
Some(d) => d,
|
||
None => &mut dd
|
||
};
|
||
dlg.begin(MethodInfo { id: "mirror.contacts.list",
|
||
http_method: hyper::method::Method::Get });
|
||
let mut params: Vec<(&str, String)> = Vec::with_capacity((2 + self._additional_params.len()));
|
||
for &field in ["alt"].iter() {
|
||
if self._additional_params.contains_key(field) {
|
||
dlg.finished(false);
|
||
return Err(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() + "contacts";
|
||
if self._scopes.len() == 0 {
|
||
self._scopes.insert(Scope::GlasTimeline.as_ref().to_string(), ());
|
||
}
|
||
|
||
|
||
if params.len() > 0 {
|
||
url.push('?');
|
||
url.push_str(&url::form_urlencoded::serialize(params));
|
||
}
|
||
|
||
|
||
|
||
loop {
|
||
let token = match self.hub.auth.borrow_mut().token(self._scopes.keys()) {
|
||
Ok(token) => token,
|
||
Err(err) => {
|
||
match dlg.token(&*err) {
|
||
Some(token) => token,
|
||
None => {
|
||
dlg.finished(false);
|
||
return Err(Error::MissingToken(err))
|
||
}
|
||
}
|
||
}
|
||
};
|
||
let auth_header = Authorization(Bearer { token: token.access_token });
|
||
let mut req_result = {
|
||
let mut client = &mut *self.hub.client.borrow_mut();
|
||
let mut req = client.borrow_mut().request(hyper::method::Method::Get, &url)
|
||
.header(UserAgent(self.hub._user_agent.clone()))
|
||
.header(auth_header.clone());
|
||
|
||
dlg.pre_request();
|
||
req.send()
|
||
};
|
||
|
||
match req_result {
|
||
Err(err) => {
|
||
if let oauth2::Retry::After(d) = dlg.http_error(&err) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return Err(Error::HttpError(err))
|
||
}
|
||
Ok(mut res) => {
|
||
if !res.status.is_success() {
|
||
let mut json_err = String::new();
|
||
res.read_to_string(&mut json_err).unwrap();
|
||
if let oauth2::Retry::After(d) = dlg.http_failure(&res,
|
||
json::from_str(&json_err).ok(),
|
||
json::from_str(&json_err).ok()) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return match json::from_str::<ErrorResponse>(&json_err){
|
||
Err(_) => Err(Error::Failure(res)),
|
||
Ok(serr) => Err(Error::BadRequest(serr))
|
||
}
|
||
}
|
||
let result_value = {
|
||
let mut json_response = String::new();
|
||
res.read_to_string(&mut json_response).unwrap();
|
||
match json::from_str(&json_response) {
|
||
Ok(decoded) => (res, decoded),
|
||
Err(err) => {
|
||
dlg.response_json_decode_error(&json_response, &err);
|
||
return Err(Error::JsonDecodeError(json_response, err));
|
||
}
|
||
}
|
||
};
|
||
|
||
dlg.finished(true);
|
||
return Ok(result_value)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
/// 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 Delegate) -> ContactListCall<'a, C, 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 paramters
|
||
/// which have their own setter method. If done anyway, the request will fail.
|
||
///
|
||
/// # Additional Parameters
|
||
///
|
||
/// * *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. Overrides userIp if both are provided.
|
||
/// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
|
||
/// * *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.
|
||
/// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
|
||
/// * *userIp* (query-string) - IP address of the site where the request originates. Use this if you want to enforce per-user limits.
|
||
/// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
|
||
/// * *alt* (query-string) - Data format for the response.
|
||
pub fn param<T>(mut self, name: T, value: T) -> ContactListCall<'a, C, 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::GlasTimeline`.
|
||
///
|
||
/// The `scope` will be added to a set of scopes. This is important as one can maintain access
|
||
/// tokens for more than one scope.
|
||
///
|
||
/// 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>(mut self, scope: T) -> ContactListCall<'a, C, A>
|
||
where T: AsRef<str> {
|
||
self._scopes.insert(scope.as_ref().to_string(), ());
|
||
self
|
||
}
|
||
}
|
||
|
||
|
||
/// Updates a contact in place.
|
||
///
|
||
/// A builder for the *update* method supported by a *contact* resource.
|
||
/// It is not used directly, but through a `ContactMethods` instance.
|
||
///
|
||
/// # Example
|
||
///
|
||
/// Instantiate a resource method builder
|
||
///
|
||
/// ```test_harness,no_run
|
||
/// # extern crate hyper;
|
||
/// # extern crate yup_oauth2 as oauth2;
|
||
/// # extern crate google_mirror1 as mirror1;
|
||
/// use mirror1::Contact;
|
||
/// # #[test] fn egal() {
|
||
/// # use std::default::Default;
|
||
/// # use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage};
|
||
/// # use mirror1::Mirror;
|
||
///
|
||
/// # let secret: ApplicationSecret = Default::default();
|
||
/// # let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate,
|
||
/// # hyper::Client::new(),
|
||
/// # <MemoryStorage as Default>::default(), None);
|
||
/// # let mut hub = Mirror::new(hyper::Client::new(), 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 = Contact::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.contacts().update(req, "id")
|
||
/// .doit();
|
||
/// # }
|
||
/// ```
|
||
pub struct ContactUpdateCall<'a, C, A>
|
||
where C: 'a, A: 'a {
|
||
|
||
hub: &'a Mirror<C, A>,
|
||
_request: Contact,
|
||
_id: String,
|
||
_delegate: Option<&'a mut Delegate>,
|
||
_additional_params: HashMap<String, String>,
|
||
_scopes: BTreeMap<String, ()>
|
||
}
|
||
|
||
impl<'a, C, A> CallBuilder for ContactUpdateCall<'a, C, A> {}
|
||
|
||
impl<'a, C, A> ContactUpdateCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oauth2::GetToken {
|
||
|
||
|
||
/// Perform the operation you have build so far.
|
||
pub fn doit(mut self) -> Result<(hyper::client::Response, Contact)> {
|
||
use std::io::{Read, Seek};
|
||
use hyper::header::{ContentType, ContentLength, Authorization, Bearer, UserAgent, Location};
|
||
let mut dd = DefaultDelegate;
|
||
let mut dlg: &mut Delegate = match self._delegate {
|
||
Some(d) => d,
|
||
None => &mut dd
|
||
};
|
||
dlg.begin(MethodInfo { id: "mirror.contacts.update",
|
||
http_method: hyper::method::Method::Put });
|
||
let mut params: Vec<(&str, String)> = Vec::with_capacity((4 + self._additional_params.len()));
|
||
params.push(("id", self._id.to_string()));
|
||
for &field in ["alt", "id"].iter() {
|
||
if self._additional_params.contains_key(field) {
|
||
dlg.finished(false);
|
||
return Err(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() + "contacts/{id}";
|
||
if self._scopes.len() == 0 {
|
||
self._scopes.insert(Scope::GlasTimeline.as_ref().to_string(), ());
|
||
}
|
||
|
||
for &(find_this, param_name) in [("{id}", "id")].iter() {
|
||
let mut replace_with: Option<&str> = None;
|
||
for &(name, ref value) in params.iter() {
|
||
if name == param_name {
|
||
replace_with = Some(value);
|
||
break;
|
||
}
|
||
}
|
||
url = url.replace(find_this, replace_with.expect("to find substitution value in params"));
|
||
}
|
||
{
|
||
let mut indices_for_removal: Vec<usize> = Vec::with_capacity(1);
|
||
for param_name in ["id"].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);
|
||
}
|
||
}
|
||
|
||
if params.len() > 0 {
|
||
url.push('?');
|
||
url.push_str(&url::form_urlencoded::serialize(params));
|
||
}
|
||
|
||
let mut json_mime_type = mime::Mime(mime::TopLevel::Application, mime::SubLevel::Json, Default::default());
|
||
let mut request_value_reader =
|
||
{
|
||
let mut value = json::value::to_value(&self._request).expect("serde to work");
|
||
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.borrow_mut().token(self._scopes.keys()) {
|
||
Ok(token) => token,
|
||
Err(err) => {
|
||
match dlg.token(&*err) {
|
||
Some(token) => token,
|
||
None => {
|
||
dlg.finished(false);
|
||
return Err(Error::MissingToken(err))
|
||
}
|
||
}
|
||
}
|
||
};
|
||
let auth_header = Authorization(Bearer { token: token.access_token });
|
||
request_value_reader.seek(io::SeekFrom::Start(0)).unwrap();
|
||
let mut req_result = {
|
||
let mut client = &mut *self.hub.client.borrow_mut();
|
||
let mut req = client.borrow_mut().request(hyper::method::Method::Put, &url)
|
||
.header(UserAgent(self.hub._user_agent.clone()))
|
||
.header(auth_header.clone())
|
||
.header(ContentType(json_mime_type.clone()))
|
||
.header(ContentLength(request_size as u64))
|
||
.body(&mut request_value_reader);
|
||
|
||
dlg.pre_request();
|
||
req.send()
|
||
};
|
||
|
||
match req_result {
|
||
Err(err) => {
|
||
if let oauth2::Retry::After(d) = dlg.http_error(&err) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return Err(Error::HttpError(err))
|
||
}
|
||
Ok(mut res) => {
|
||
if !res.status.is_success() {
|
||
let mut json_err = String::new();
|
||
res.read_to_string(&mut json_err).unwrap();
|
||
if let oauth2::Retry::After(d) = dlg.http_failure(&res,
|
||
json::from_str(&json_err).ok(),
|
||
json::from_str(&json_err).ok()) {
|
||
sleep(d);
|
||
continue;
|
||
}
|
||
dlg.finished(false);
|
||
return match json::from_str::<ErrorResponse>(&json_err){
|
||
Err(_) => Err(Error::Failure(res)),
|
||
Ok(serr) => Err(Error::BadRequest(serr))
|
||
}
|
||
}
|
||
let result_value = {
|
||
let mut json_response = String::new();
|
||
res.read_to_string(&mut json_response).unwrap();
|
||
match json::from_str(&json_response) {
|
||
Ok(decoded) => (res, decoded),
|
||
Err(err) => {
|
||
dlg.response_json_decode_error(&json_response, &err);
|
||
return Err(Error::JsonDecodeError(json_response, 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: Contact) -> ContactUpdateCall<'a, C, A> {
|
||
self._request = new_value;
|
||
self
|
||
}
|
||
/// The ID of the contact.
|
||
///
|
||
/// Sets the *id* 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 id(mut self, new_value: &str) -> ContactUpdateCall<'a, C, A> {
|
||
self._id = 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 Delegate) -> ContactUpdateCall<'a, C, 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 paramters
|
||
/// which have their own setter method. If done anyway, the request will fail.
|
||
///
|
||
/// # Additional Parameters
|
||
///
|
||
/// * *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. Overrides userIp if both are provided.
|
||
/// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
|
||
/// * *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.
|
||
/// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
|
||
/// * *userIp* (query-string) - IP address of the site where the request originates. Use this if you want to enforce per-user limits.
|
||
/// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
|
||
/// * *alt* (query-string) - Data format for the response.
|
||
pub fn param<T>(mut self, name: T, value: T) -> ContactUpdateCall<'a, C, 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::GlasTimeline`.
|
||
///
|
||
/// The `scope` will be added to a set of scopes. This is important as one can maintain access
|
||
/// tokens for more than one scope.
|
||
///
|
||
/// 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>(mut self, scope: T) -> ContactUpdateCall<'a, C, A>
|
||
where T: AsRef<str> {
|
||
self._scopes.insert(scope.as_ref().to_string(), ());
|
||
self
|
||
}
|
||
}
|
||
|
||
|