Files
google-apis-rs/gen/admin1_reports/src/lib.rs
Sebastian Thiel 3bc930ae47 fix(version-up): 0.1.0 release
* Added all APIs to source control
* upped crate version
2015-03-22 20:30:01 +01:00

2467 lines
100 KiB
Rust

// DO NOT EDIT !
// This file was generated automatically from 'src/mako/lib.rs.mako'
// DO NOT EDIT !
//! This documentation was generated from *reports* crate version *0.1.0+20150115*, where *20150115* is the exact revision of the *admin:reports_v1* schema built by the [mako](http://www.makotemplates.org/) code generator *v0.1.0*.
//!
//! Everything else about the *reports* *v1_reports* API can be found at the
//! [official documentation site](https://developers.google.com/admin-sdk/reports/).
//! The original source code is [on github](https://github.com/Byron/google-apis-rs/tree/master/gen/admin1_reports).
//! # Features
//!
//! Handle the following *Resources* with ease from the central [hub](struct.Reports.html) ...
//!
//! * [activities](struct.Activity.html)
//! * [*list*](struct.ActivityListCall.html) and [*watch*](struct.ActivityWatchCall.html)
//! * [channels](struct.Channel.html)
//! * [*stop*](struct.ChannelStopCall.html)
//! * customer usage reports
//! * [*get*](struct.CustomerUsageReportGetCall.html)
//! * user usage report
//! * [*get*](struct.UserUsageReportGetCall.html)
//!
//!
//! Subscription supported by ...
//!
//! * [*watch activities*](struct.ActivityWatchCall.html)
//! * [*list activities*](struct.ActivityListCall.html)
//!
//!
//!
//! Not what you are looking for ? Find all other Google APIs in their Rust [documentation index](../index.html).
//!
//! # Structure of this Library
//!
//! The API is structured into the following primary items:
//!
//! * **[Hub](struct.Reports.html)**
//! * a central object to maintain state and allow accessing all *Activities*
//! * **[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*
//!
//! Generally speaking, you can invoke *Activities* like this:
//!
//! ```Rust,ignore
//! let r = hub.resource().activity(...).doit()
//! ```
//!
//! Or specifically ...
//!
//! ```ignore
//! let r = hub.activities().watch(...).doit()
//! let r = hub.channels().stop(...).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-admin1_reports = "*"
//! ```
//!
//! ## A complete example
//!
//! ```test_harness,no_run
//! extern crate hyper;
//! extern crate "yup-oauth2" as oauth2;
//! extern crate "google-admin1_reports" as admin1_reports;
//! use admin1_reports::Channel;
//! use admin1_reports::Result;
//! # #[test] fn egal() {
//! use std::default::Default;
//! use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage};
//! use admin1_reports::Reports;
//!
//! // 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 = Reports::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: Channel = Default::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.activities().watch(&req, "userKey", "applicationName")
//! .start_time("labore")
//! .page_token("sea")
//! .max_results(-90)
//! .filters("dolores")
//! .event_name("gubergren")
//! .end_time("sadipscing")
//! .customer_id("aliquyam")
//! .actor_ip_address("ea")
//! .doit();
//!
//! match result {
//! Result::HttpError(err) => println!("HTTPERROR: {:?}", err),
//! Result::MissingAPIKey => println!("Auth: Missing API Key - used if there are no scopes"),
//! Result::MissingToken => println!("OAuth2: Missing Token"),
//! Result::Cancelled => println!("Operation cancelled by user"),
//! Result::UploadSizeLimitExceeded(size, max_size) => println!("Upload size too big: {} of {}", size, max_size),
//! Result::Failure(_) => println!("General Failure (hyper::client::Response doesn't print)"),
//! Result::FieldClash(clashed_field) => println!("You added custom parameter which is part of builder: {:?}", clashed_field),
//! Result::JsonDecodeError(err) => println!("Couldn't understand server reply - maybe API needs update: {:?}", err),
//! Result::Success(_) => println!("Success (value doesn't print)"),
//! }
//! # }
//! ```
//! ## 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](../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 Downlods
//! 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 identifyable 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 borrowed
//!
//! 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
//!
//!
#![feature(core,io,thread_sleep)]
// 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)]
// Required for serde annotations
#![feature(custom_derive, custom_attribute, plugin)]
#![plugin(serde_macros)]
#[macro_use]
extern crate hyper;
extern crate serde;
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 std::marker::PhantomData;
use serde::json;
use std::io;
use std::fs;
use std::thread::sleep;
pub use cmn::{MultiPartReader, ToParts, MethodInfo, Result, CallBuilder, Hub, ReadSeek, Part, ResponseResult, RequestValue, NestedType, Delegate, DefaultDelegate, ResourceMethodsBuilder, Resource, JsonServerError};
// ##############
// 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 audit reports of Google Apps for your domain
ReportAuditReadonly,
/// View usage reports of Google Apps for your domain
ReportUsageReadonly,
}
impl Str for Scope {
fn as_slice(&self) -> &str {
match *self {
Scope::ReportAuditReadonly => "https://www.googleapis.com/auth/admin.reports.audit.readonly",
Scope::ReportUsageReadonly => "https://www.googleapis.com/auth/admin.reports.usage.readonly",
}
}
}
impl Default for Scope {
fn default() -> Scope {
Scope::ReportAuditReadonly
}
}
// ########
// HUB ###
// ######
/// Central instance to access all Reports related resource activities
///
/// # Examples
///
/// Instantiate a new hub
///
/// ```test_harness,no_run
/// extern crate hyper;
/// extern crate "yup-oauth2" as oauth2;
/// extern crate "google-admin1_reports" as admin1_reports;
/// use admin1_reports::Channel;
/// use admin1_reports::Result;
/// # #[test] fn egal() {
/// use std::default::Default;
/// use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage};
/// use admin1_reports::Reports;
///
/// // 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 = Reports::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: Channel = Default::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.activities().watch(&req, "userKey", "applicationName")
/// .start_time("justo")
/// .page_token("et")
/// .max_results(-17)
/// .filters("diam")
/// .event_name("ipsum")
/// .end_time("Lorem")
/// .customer_id("et")
/// .actor_ip_address("duo")
/// .doit();
///
/// match result {
/// Result::HttpError(err) => println!("HTTPERROR: {:?}", err),
/// Result::MissingAPIKey => println!("Auth: Missing API Key - used if there are no scopes"),
/// Result::MissingToken => println!("OAuth2: Missing Token"),
/// Result::Cancelled => println!("Operation cancelled by user"),
/// Result::UploadSizeLimitExceeded(size, max_size) => println!("Upload size too big: {} of {}", size, max_size),
/// Result::Failure(_) => println!("General Failure (hyper::client::Response doesn't print)"),
/// Result::FieldClash(clashed_field) => println!("You added custom parameter which is part of builder: {:?}", clashed_field),
/// Result::JsonDecodeError(err) => println!("Couldn't understand server reply - maybe API needs update: {:?}", err),
/// Result::Success(_) => println!("Success (value doesn't print)"),
/// }
/// # }
/// ```
pub struct Reports<C, NC, A> {
client: RefCell<C>,
auth: RefCell<A>,
_user_agent: String,
_m: PhantomData<NC>
}
impl<'a, C, NC, A> Hub for Reports<C, NC, A> {}
impl<'a, C, NC, A> Reports<C, NC, A>
where NC: hyper::net::NetworkConnector, C: BorrowMut<hyper::Client<NC>>, A: oauth2::GetToken {
pub fn new(client: C, authenticator: A) -> Reports<C, NC, A> {
Reports {
client: RefCell::new(client),
auth: RefCell::new(authenticator),
_user_agent: "google-api-rust-client/0.1.0".to_string(),
_m: PhantomData
}
}
pub fn activities(&'a self) -> ActivityMethods<'a, C, NC, A> {
ActivityMethods { hub: &self }
}
pub fn channels(&'a self) -> ChannelMethods<'a, C, NC, A> {
ChannelMethods { hub: &self }
}
pub fn customer_usage_reports(&'a self) -> CustomerUsageReportMethods<'a, C, NC, A> {
CustomerUsageReportMethods { hub: &self }
}
pub fn user_usage_report(&'a self) -> UserUsageReportMethods<'a, C, NC, A> {
UserUsageReportMethods { hub: &self }
}
/// Set the user-agent header field to use in all requests to the server.
/// It defaults to `google-api-rust-client/0.1.0`.
///
/// Returns the previously set user-agent.
pub fn user_agent(&mut self, agent_name: String) -> String {
let prev = self._user_agent.clone();
self._user_agent = agent_name;
prev
}
}
// ############
// SCHEMAS ###
// ##########
/// JSON template for a collection of activites.
///
/// # 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 activities](struct.ActivityListCall.html) (response)
///
#[derive(Default, Clone, Debug, Deserialize)]
pub struct Activities {
/// Token for retrieving the next page
#[serde(alias="nextPageToken")]
pub next_page_token: String,
/// Each record in read response.
pub items: Vec<Activity>,
/// Kind of list response this is.
pub kind: String,
/// ETag of the resource.
pub etag: String,
}
impl ResponseResult for Activities {}
/// Key-Value pairs to give detailed information on the warning.
///
/// This type is not used in any activity, and only used as *part* of another schema.
///
#[derive(Default, Clone, Debug, Deserialize)]
pub struct UsageReportsWarningsData {
/// Key associated with a key-value pair to give detailed information on the warning.
pub key: String,
/// Value associated with a key-value pair to give detailed information on the warning.
pub value: String,
}
impl NestedType for UsageReportsWarningsData {}
impl Part for UsageReportsWarningsData {}
/// JSON template for a usage report.
///
/// This type is not used in any activity, and only used as *part* of another schema.
///
#[derive(Default, Clone, Debug, Deserialize)]
pub struct UsageReport {
/// The date to which the record belongs.
pub date: String,
/// The kind of object.
pub kind: String,
/// ETag of the resource.
pub etag: String,
/// Parameter value pairs for various applications.
pub parameters: Vec<UsageReportParameters>,
/// Information about the type of the item.
pub entity: UsageReportEntity,
}
impl Part for UsageReport {}
/// Parameter value pairs for various applications.
///
/// This type is not used in any activity, and only used as *part* of another schema.
///
#[derive(Default, Clone, Debug, Deserialize)]
pub struct UsageReportParameters {
/// Nested message value of the parameter.
#[serde(alias="msgValue")]
pub msg_value: Vec<HashMap<String, String>>,
/// RFC 3339 formatted value of the parameter.
#[serde(alias="datetimeValue")]
pub datetime_value: String,
/// The name of the parameter.
pub name: String,
/// String value of the parameter.
#[serde(alias="stringValue")]
pub string_value: String,
/// Boolean value of the parameter.
#[serde(alias="boolValue")]
pub bool_value: bool,
/// Integral value of the parameter.
#[serde(alias="intValue")]
pub int_value: String,
}
impl NestedType for UsageReportParameters {}
impl Part for UsageReportParameters {}
/// User doing the action.
///
/// This type is not used in any activity, and only used as *part* of another schema.
///
#[derive(Default, Clone, Debug, Deserialize)]
pub struct ActivityActor {
/// Obfuscated user id of the user.
#[serde(alias="profileId")]
pub profile_id: String,
/// Email address of the user.
pub email: String,
/// For OAuth 2LO API requests, consumer_key of the requestor.
pub key: String,
/// User or OAuth 2LO request.
#[serde(alias="callerType")]
pub caller_type: String,
}
impl NestedType for ActivityActor {}
impl Part for ActivityActor {}
/// Unique identifier for each activity record.
///
/// This type is not used in any activity, and only used as *part* of another schema.
///
#[derive(Default, Clone, Debug, Deserialize)]
pub struct ActivityId {
/// Application name to which the event belongs.
#[serde(alias="applicationName")]
pub application_name: String,
/// Unique qualifier if multiple events have the same time.
#[serde(alias="uniqueQualifier")]
pub unique_qualifier: String,
/// Obfuscated customer ID of the source customer.
#[serde(alias="customerId")]
pub customer_id: String,
/// Time of occurrence of the activity.
pub time: String,
}
impl NestedType for ActivityId {}
impl Part for ActivityId {}
/// Warnings if any.
///
/// This type is not used in any activity, and only used as *part* of another schema.
///
#[derive(Default, Clone, Debug, Deserialize)]
pub struct UsageReportsWarnings {
/// Human readable message for the warning.
pub message: String,
/// Machine readable code / warning type.
pub code: String,
/// Key-Value pairs to give detailed information on the warning.
pub data: Vec<UsageReportsWarningsData>,
}
impl NestedType for UsageReportsWarnings {}
impl Part for UsageReportsWarnings {}
/// JSON template for a collection of usage reports.
///
/// # 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 user usage report](struct.UserUsageReportGetCall.html) (response)
/// * [get customer usage reports](struct.CustomerUsageReportGetCall.html) (response)
///
#[derive(Default, Clone, Debug, Deserialize)]
pub struct UsageReports {
/// Token for retrieving the next page
#[serde(alias="nextPageToken")]
pub next_page_token: String,
/// The kind of object.
pub kind: String,
/// ETag of the resource.
pub etag: String,
/// Various application parameter records.
#[serde(alias="usageReports")]
pub usage_reports: Vec<UsageReport>,
/// Warnings if any.
pub warnings: Vec<UsageReportsWarnings>,
}
impl ResponseResult for UsageReports {}
/// JSON template for the activity resource.
///
/// This type is not used in any activity, and only used as *part* of another schema.
///
#[derive(Default, Clone, Debug, Deserialize)]
pub struct Activity {
/// Kind of resource this is.
pub kind: String,
/// ETag of the entry.
pub etag: String,
/// Activity events.
pub events: Vec<ActivityEvents>,
/// IP Address of the user doing the action.
#[serde(alias="ipAddress")]
pub ip_address: String,
/// Domain of source customer.
#[serde(alias="ownerDomain")]
pub owner_domain: String,
/// User doing the action.
pub actor: ActivityActor,
/// Unique identifier for each activity record.
pub id: ActivityId,
}
impl Part for Activity {}
/// Parameter value pairs for various applications.
///
/// This type is not used in any activity, and only used as *part* of another schema.
///
#[derive(Default, Clone, Debug, Deserialize)]
pub struct ActivityEventsParameters {
/// Boolean value of the parameter.
#[serde(alias="boolValue")]
pub bool_value: bool,
/// Multi-string value of the parameter.
#[serde(alias="multiValue")]
pub multi_value: Vec<String>,
/// The name of the parameter.
pub name: String,
/// Multi-int value of the parameter.
#[serde(alias="multiIntValue")]
pub multi_int_value: Vec<String>,
/// Integral value of the parameter.
#[serde(alias="intValue")]
pub int_value: String,
/// String value of the parameter.
pub value: String,
}
impl NestedType for ActivityEventsParameters {}
impl Part for ActivityEventsParameters {}
/// Activity events.
///
/// This type is not used in any activity, and only used as *part* of another schema.
///
#[derive(Default, Clone, Debug, Deserialize)]
pub struct ActivityEvents {
/// Type of event.
#[serde(alias="type")]
pub type_: String,
/// Name of event.
pub name: String,
/// Parameter value pairs for various applications.
pub parameters: Vec<ActivityEventsParameters>,
}
impl NestedType for ActivityEvents {}
impl Part for ActivityEvents {}
/// Information about the type of the item.
///
/// This type is not used in any activity, and only used as *part* of another schema.
///
#[derive(Default, Clone, Debug, Deserialize)]
pub struct UsageReportEntity {
/// Obfuscated user id for the record.
#[serde(alias="profileId")]
pub profile_id: String,
/// user's email.
#[serde(alias="userEmail")]
pub user_email: String,
/// The type of item, can be a customer or user.
#[serde(alias="type")]
pub type_: String,
/// Obfuscated customer id for the record.
#[serde(alias="customerId")]
pub customer_id: String,
}
impl NestedType for UsageReportEntity {}
impl Part for UsageReportEntity {}
/// An notification channel used to watch for resource changes.
///
/// # 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*).
///
/// * [watch activities](struct.ActivityWatchCall.html) (request|response)
/// * [stop channels](struct.ChannelStopCall.html) (request)
///
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct Channel {
/// A version-specific identifier for the watched resource.
#[serde(alias="resourceUri")]
pub resource_uri: Option<String>,
/// Identifies this as a notification channel used to watch for changes to a resource. Value: the fixed string "api#channel".
pub kind: Option<String>,
/// An opaque ID that identifies the resource being watched on this channel. Stable across different API versions.
#[serde(alias="resourceId")]
pub resource_id: Option<String>,
/// A UUID or similar unique string that identifies this channel.
pub id: Option<String>,
/// An arbitrary string delivered to the target address with each notification delivered over this channel. Optional.
pub token: Option<String>,
/// Additional parameters controlling delivery channel behavior. Optional.
pub params: Option<HashMap<String, String>>,
/// Date and time of notification channel expiration, expressed as a Unix timestamp, in milliseconds. Optional.
pub expiration: Option<String>,
/// The address where notifications are delivered for this channel.
pub address: Option<String>,
/// The type of delivery mechanism used for this channel.
#[serde(alias="type")]
pub type_: Option<String>,
/// A Boolean value to indicate whether payload is wanted. Optional.
pub payload: Option<bool>,
}
impl RequestValue for Channel {}
impl Resource for Channel {}
impl ResponseResult for Channel {}
// ###################
// MethodBuilders ###
// #################
/// A builder providing access to all methods supported on *channel* resources.
/// It is not used directly, but through the `Reports` hub.
///
/// # Example
///
/// Instantiate a resource builder
///
/// ```test_harness,no_run
/// extern crate hyper;
/// extern crate "yup-oauth2" as oauth2;
/// extern crate "google-admin1_reports" as admin1_reports;
///
/// # #[test] fn egal() {
/// use std::default::Default;
/// use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage};
/// use admin1_reports::Reports;
///
/// let secret: ApplicationSecret = Default::default();
/// let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate,
/// hyper::Client::new(),
/// <MemoryStorage as Default>::default(), None);
/// let mut hub = Reports::new(hyper::Client::new(), auth);
/// // Usually you wouldn't bind this to a variable, but keep calling *CallBuilders*
/// // like `stop(...)`
/// // to build up your call.
/// let rb = hub.channels();
/// # }
/// ```
pub struct ChannelMethods<'a, C, NC, A>
where C: 'a, NC: 'a, A: 'a {
hub: &'a Reports<C, NC, A>,
}
impl<'a, C, NC, A> ResourceMethodsBuilder for ChannelMethods<'a, C, NC, A> {}
impl<'a, C, NC, A> ChannelMethods<'a, C, NC, A> {
/// Create a builder to help you perform the following task:
///
/// Stop watching resources through this channel
pub fn stop(&self, request: &Channel) -> ChannelStopCall<'a, C, NC, A> {
ChannelStopCall {
hub: self.hub,
_request: request.clone(),
_delegate: Default::default(),
_scopes: Default::default(),
_additional_params: Default::default(),
}
}
}
/// A builder providing access to all methods supported on *activity* resources.
/// It is not used directly, but through the `Reports` hub.
///
/// # Example
///
/// Instantiate a resource builder
///
/// ```test_harness,no_run
/// extern crate hyper;
/// extern crate "yup-oauth2" as oauth2;
/// extern crate "google-admin1_reports" as admin1_reports;
///
/// # #[test] fn egal() {
/// use std::default::Default;
/// use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage};
/// use admin1_reports::Reports;
///
/// let secret: ApplicationSecret = Default::default();
/// let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate,
/// hyper::Client::new(),
/// <MemoryStorage as Default>::default(), None);
/// let mut hub = Reports::new(hyper::Client::new(), auth);
/// // Usually you wouldn't bind this to a variable, but keep calling *CallBuilders*
/// // like `list(...)` and `watch(...)`
/// // to build up your call.
/// let rb = hub.activities();
/// # }
/// ```
pub struct ActivityMethods<'a, C, NC, A>
where C: 'a, NC: 'a, A: 'a {
hub: &'a Reports<C, NC, A>,
}
impl<'a, C, NC, A> ResourceMethodsBuilder for ActivityMethods<'a, C, NC, A> {}
impl<'a, C, NC, A> ActivityMethods<'a, C, NC, A> {
/// Create a builder to help you perform the following task:
///
/// Push changes to activities
pub fn watch(&self, request: &Channel, user_key: &str, application_name: &str) -> ActivityWatchCall<'a, C, NC, A> {
ActivityWatchCall {
hub: self.hub,
_request: request.clone(),
_user_key: user_key.to_string(),
_application_name: application_name.to_string(),
_start_time: Default::default(),
_page_token: Default::default(),
_max_results: Default::default(),
_filters: Default::default(),
_event_name: Default::default(),
_end_time: Default::default(),
_customer_id: Default::default(),
_actor_ip_address: Default::default(),
_delegate: Default::default(),
_scopes: Default::default(),
_additional_params: Default::default(),
}
}
/// Create a builder to help you perform the following task:
///
/// Retrieves a list of activities for a specific customer and application.
pub fn list(&self, user_key: &str, application_name: &str) -> ActivityListCall<'a, C, NC, A> {
ActivityListCall {
hub: self.hub,
_user_key: user_key.to_string(),
_application_name: application_name.to_string(),
_start_time: Default::default(),
_page_token: Default::default(),
_max_results: Default::default(),
_filters: Default::default(),
_event_name: Default::default(),
_end_time: Default::default(),
_customer_id: Default::default(),
_actor_ip_address: Default::default(),
_delegate: Default::default(),
_scopes: Default::default(),
_additional_params: Default::default(),
}
}
}
/// A builder providing access to all methods supported on *customerUsageReport* resources.
/// It is not used directly, but through the `Reports` hub.
///
/// # Example
///
/// Instantiate a resource builder
///
/// ```test_harness,no_run
/// extern crate hyper;
/// extern crate "yup-oauth2" as oauth2;
/// extern crate "google-admin1_reports" as admin1_reports;
///
/// # #[test] fn egal() {
/// use std::default::Default;
/// use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage};
/// use admin1_reports::Reports;
///
/// let secret: ApplicationSecret = Default::default();
/// let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate,
/// hyper::Client::new(),
/// <MemoryStorage as Default>::default(), None);
/// let mut hub = Reports::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.customer_usage_reports();
/// # }
/// ```
pub struct CustomerUsageReportMethods<'a, C, NC, A>
where C: 'a, NC: 'a, A: 'a {
hub: &'a Reports<C, NC, A>,
}
impl<'a, C, NC, A> ResourceMethodsBuilder for CustomerUsageReportMethods<'a, C, NC, A> {}
impl<'a, C, NC, A> CustomerUsageReportMethods<'a, C, NC, A> {
/// Create a builder to help you perform the following task:
///
/// Retrieves a report which is a collection of properties / statistics for a specific customer.
pub fn get(&self, date: &str) -> CustomerUsageReportGetCall<'a, C, NC, A> {
CustomerUsageReportGetCall {
hub: self.hub,
_date: date.to_string(),
_parameters: Default::default(),
_page_token: Default::default(),
_customer_id: Default::default(),
_delegate: Default::default(),
_scopes: Default::default(),
_additional_params: Default::default(),
}
}
}
/// A builder providing access to all methods supported on *userUsageReport* resources.
/// It is not used directly, but through the `Reports` hub.
///
/// # Example
///
/// Instantiate a resource builder
///
/// ```test_harness,no_run
/// extern crate hyper;
/// extern crate "yup-oauth2" as oauth2;
/// extern crate "google-admin1_reports" as admin1_reports;
///
/// # #[test] fn egal() {
/// use std::default::Default;
/// use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage};
/// use admin1_reports::Reports;
///
/// let secret: ApplicationSecret = Default::default();
/// let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate,
/// hyper::Client::new(),
/// <MemoryStorage as Default>::default(), None);
/// let mut hub = Reports::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.user_usage_report();
/// # }
/// ```
pub struct UserUsageReportMethods<'a, C, NC, A>
where C: 'a, NC: 'a, A: 'a {
hub: &'a Reports<C, NC, A>,
}
impl<'a, C, NC, A> ResourceMethodsBuilder for UserUsageReportMethods<'a, C, NC, A> {}
impl<'a, C, NC, A> UserUsageReportMethods<'a, C, NC, A> {
/// Create a builder to help you perform the following task:
///
/// Retrieves a report which is a collection of properties / statistics for a set of users.
pub fn get(&self, user_key: &str, date: &str) -> UserUsageReportGetCall<'a, C, NC, A> {
UserUsageReportGetCall {
hub: self.hub,
_user_key: user_key.to_string(),
_date: date.to_string(),
_parameters: Default::default(),
_page_token: Default::default(),
_max_results: Default::default(),
_filters: Default::default(),
_customer_id: Default::default(),
_delegate: Default::default(),
_scopes: Default::default(),
_additional_params: Default::default(),
}
}
}
// ###################
// CallBuilders ###
// #################
/// Stop watching resources through this channel
///
/// A builder for the *stop* method supported by a *channel* resource.
/// It is not used directly, but through a `ChannelMethods`.
///
/// # Example
///
/// Instantiate a resource method builder
///
/// ```test_harness,no_run
/// # extern crate hyper;
/// # extern crate "yup-oauth2" as oauth2;
/// # extern crate "google-admin1_reports" as admin1_reports;
/// use admin1_reports::Channel;
/// # #[test] fn egal() {
/// # use std::default::Default;
/// # use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage};
/// # use admin1_reports::Reports;
///
/// # let secret: ApplicationSecret = Default::default();
/// # let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate,
/// # hyper::Client::new(),
/// # <MemoryStorage as Default>::default(), None);
/// # let mut hub = Reports::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: Channel = Default::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.channels().stop(&req)
/// .doit();
/// # }
/// ```
pub struct ChannelStopCall<'a, C, NC, A>
where C: 'a, NC: 'a, A: 'a {
hub: &'a Reports<C, NC, A>,
_request: Channel,
_delegate: Option<&'a mut Delegate>,
_additional_params: HashMap<String, String>,
_scopes: BTreeMap<String, ()>
}
impl<'a, C, NC, A> CallBuilder for ChannelStopCall<'a, C, NC, A> {}
impl<'a, C, NC, A> ChannelStopCall<'a, C, NC, A> where NC: hyper::net::NetworkConnector, C: BorrowMut<hyper::Client<NC>>, 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, UserAgent, Location};
let mut dd = DefaultDelegate;
let mut dlg: &mut Delegate = match self._delegate {
Some(d) => d,
None => &mut dd
};
dlg.begin(MethodInfo { id: "admin.channels.stop",
http_method: hyper::method::Method::Post });
let mut params: Vec<(&str, String)> = Vec::with_capacity((2 + self._additional_params.len()));
for &field in [].iter() {
if self._additional_params.contains_key(field) {
dlg.finished(false);
return Result::FieldClash(field);
}
}
for (name, value) in self._additional_params.iter() {
params.push((&name, value.clone()));
}
let mut url = "https://www.googleapis.com/admin/reports/v1//admin/reports_v1/channels/stop".to_string();
if self._scopes.len() == 0 {
self._scopes.insert(Scope::ReportAuditReadonly.as_slice().to_string(), ());
}
if params.len() > 0 {
url.push('?');
url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice()))));
}
let mut json_mime_type = mime::Mime(mime::TopLevel::Application, mime::SubLevel::Json, Default::default());
let mut request_value_reader = io::Cursor::new(json::to_vec(&self._request));
let request_size = request_value_reader.seek(io::SeekFrom::End(0)).unwrap();
request_value_reader.seek(io::SeekFrom::Start(0)).unwrap();
loop {
let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys());
if token.is_none() {
token = dlg.token();
}
if token.is_none() {
dlg.finished(false);
return Result::MissingToken
}
let auth_header = Authorization(oauth2::Scheme { token_type: oauth2::TokenType::Bearer,
access_token: token.unwrap().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.as_slice())
.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 Result::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()) {
sleep(d);
continue;
}
dlg.finished(false);
return Result::Failure(res)
}
let result_value = res;
dlg.finished(true);
return Result::Success(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: &Channel) -> ChannelStopCall<'a, C, NC, A> {
self._request = new_value.clone();
self
}
/// Sets the *delegate* property to the given 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.
pub fn delegate(mut self, new_value: &'a mut Delegate) -> ChannelStopCall<'a, C, NC, 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) -> ChannelStopCall<'a, C, NC, A>
where T: Str {
self._additional_params.insert(name.as_slice().to_string(), value.as_slice().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 of relying on the
/// automated algorithm which simply prefers read-only scopes over those who are not.
///
/// 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) -> ChannelStopCall<'a, C, NC, A>
where T: Str {
self._scopes.insert(scope.as_slice().to_string(), ());
self
}
}
/// Push changes to activities
///
/// A builder for the *watch* method supported by a *activity* resource.
/// It is not used directly, but through a `ActivityMethods`.
///
/// # Example
///
/// Instantiate a resource method builder
///
/// ```test_harness,no_run
/// # extern crate hyper;
/// # extern crate "yup-oauth2" as oauth2;
/// # extern crate "google-admin1_reports" as admin1_reports;
/// use admin1_reports::Channel;
/// # #[test] fn egal() {
/// # use std::default::Default;
/// # use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage};
/// # use admin1_reports::Reports;
///
/// # let secret: ApplicationSecret = Default::default();
/// # let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate,
/// # hyper::Client::new(),
/// # <MemoryStorage as Default>::default(), None);
/// # let mut hub = Reports::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: Channel = Default::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.activities().watch(&req, "userKey", "applicationName")
/// .start_time("Lorem")
/// .page_token("eos")
/// .max_results(-81)
/// .filters("sadipscing")
/// .event_name("dolor")
/// .end_time("eirmod")
/// .customer_id("elitr")
/// .actor_ip_address("amet")
/// .doit();
/// # }
/// ```
pub struct ActivityWatchCall<'a, C, NC, A>
where C: 'a, NC: 'a, A: 'a {
hub: &'a Reports<C, NC, A>,
_request: Channel,
_user_key: String,
_application_name: String,
_start_time: Option<String>,
_page_token: Option<String>,
_max_results: Option<i32>,
_filters: Option<String>,
_event_name: Option<String>,
_end_time: Option<String>,
_customer_id: Option<String>,
_actor_ip_address: Option<String>,
_delegate: Option<&'a mut Delegate>,
_additional_params: HashMap<String, String>,
_scopes: BTreeMap<String, ()>
}
impl<'a, C, NC, A> CallBuilder for ActivityWatchCall<'a, C, NC, A> {}
impl<'a, C, NC, A> ActivityWatchCall<'a, C, NC, A> where NC: hyper::net::NetworkConnector, C: BorrowMut<hyper::Client<NC>>, A: oauth2::GetToken {
/// Perform the operation you have build so far.
pub fn doit(mut self) -> Result<(hyper::client::Response, Channel)> {
use std::io::{Read, Seek};
use hyper::header::{ContentType, ContentLength, Authorization, UserAgent, Location};
let mut dd = DefaultDelegate;
let mut dlg: &mut Delegate = match self._delegate {
Some(d) => d,
None => &mut dd
};
dlg.begin(MethodInfo { id: "reports.activities.watch",
http_method: hyper::method::Method::Post });
let mut params: Vec<(&str, String)> = Vec::with_capacity((13 + self._additional_params.len()));
params.push(("userKey", self._user_key.to_string()));
params.push(("applicationName", self._application_name.to_string()));
if let Some(value) = self._start_time {
params.push(("startTime", value.to_string()));
}
if let Some(value) = self._page_token {
params.push(("pageToken", value.to_string()));
}
if let Some(value) = self._max_results {
params.push(("maxResults", value.to_string()));
}
if let Some(value) = self._filters {
params.push(("filters", value.to_string()));
}
if let Some(value) = self._event_name {
params.push(("eventName", value.to_string()));
}
if let Some(value) = self._end_time {
params.push(("endTime", value.to_string()));
}
if let Some(value) = self._customer_id {
params.push(("customerId", value.to_string()));
}
if let Some(value) = self._actor_ip_address {
params.push(("actorIpAddress", value.to_string()));
}
for &field in ["alt", "userKey", "applicationName", "startTime", "pageToken", "maxResults", "filters", "eventName", "endTime", "customerId", "actorIpAddress"].iter() {
if self._additional_params.contains_key(field) {
dlg.finished(false);
return Result::FieldClash(field);
}
}
for (name, value) in self._additional_params.iter() {
params.push((&name, value.clone()));
}
params.push(("alt", "json".to_string()));
let mut url = "https://www.googleapis.com/admin/reports/v1/activity/users/{userKey}/applications/{applicationName}/watch".to_string();
if self._scopes.len() == 0 {
self._scopes.insert(Scope::ReportAuditReadonly.as_slice().to_string(), ());
}
for &(find_this, param_name) in [("{userKey}", "userKey"), ("{applicationName}", "applicationName")].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 ["userKey", "applicationName"].iter() {
for (index, &(ref name, _)) in params.iter().rev().enumerate() {
if name == param_name {
indices_for_removal.push(params.len() - index - 1);
break;
}
}
}
for &index in indices_for_removal.iter() {
params.remove(index);
}
}
if params.len() > 0 {
url.push('?');
url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice()))));
}
let mut json_mime_type = mime::Mime(mime::TopLevel::Application, mime::SubLevel::Json, Default::default());
let mut request_value_reader = io::Cursor::new(json::to_vec(&self._request));
let request_size = request_value_reader.seek(io::SeekFrom::End(0)).unwrap();
request_value_reader.seek(io::SeekFrom::Start(0)).unwrap();
loop {
let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys());
if token.is_none() {
token = dlg.token();
}
if token.is_none() {
dlg.finished(false);
return Result::MissingToken
}
let auth_header = Authorization(oauth2::Scheme { token_type: oauth2::TokenType::Bearer,
access_token: token.unwrap().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.as_slice())
.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 Result::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()) {
sleep(d);
continue;
}
dlg.finished(false);
return Result::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 Result::JsonDecodeError(err);
}
}
};
dlg.finished(true);
return Result::Success(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: &Channel) -> ActivityWatchCall<'a, C, NC, A> {
self._request = new_value.clone();
self
}
/// Sets the *user key* 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.
///
/// Represents the profile id or the user email for which the data should be filtered. When 'all' is specified as the userKey, it returns usageReports for all users.
pub fn user_key(mut self, new_value: &str) -> ActivityWatchCall<'a, C, NC, A> {
self._user_key = new_value.to_string();
self
}
/// Sets the *application 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.
///
/// Application name for which the events are to be retrieved.
pub fn application_name(mut self, new_value: &str) -> ActivityWatchCall<'a, C, NC, A> {
self._application_name = new_value.to_string();
self
}
/// Sets the *start time* query property to the given value.
///
///
/// Return events which occured at or after this time.
pub fn start_time(mut self, new_value: &str) -> ActivityWatchCall<'a, C, NC, A> {
self._start_time = Some(new_value.to_string());
self
}
/// Sets the *page token* query property to the given value.
///
///
/// Token to specify next page.
pub fn page_token(mut self, new_value: &str) -> ActivityWatchCall<'a, C, NC, A> {
self._page_token = Some(new_value.to_string());
self
}
/// Sets the *max results* query property to the given value.
///
///
/// Number of activity records to be shown in each page.
pub fn max_results(mut self, new_value: i32) -> ActivityWatchCall<'a, C, NC, A> {
self._max_results = Some(new_value);
self
}
/// Sets the *filters* query property to the given value.
///
///
/// Event parameters in the form [parameter1 name][operator][parameter1 value],[parameter2 name][operator][parameter2 value],...
pub fn filters(mut self, new_value: &str) -> ActivityWatchCall<'a, C, NC, A> {
self._filters = Some(new_value.to_string());
self
}
/// Sets the *event name* query property to the given value.
///
///
/// Name of the event being queried.
pub fn event_name(mut self, new_value: &str) -> ActivityWatchCall<'a, C, NC, A> {
self._event_name = Some(new_value.to_string());
self
}
/// Sets the *end time* query property to the given value.
///
///
/// Return events which occured at or before this time.
pub fn end_time(mut self, new_value: &str) -> ActivityWatchCall<'a, C, NC, A> {
self._end_time = Some(new_value.to_string());
self
}
/// Sets the *customer id* query property to the given value.
///
///
/// Represents the customer for which the data is to be fetched.
pub fn customer_id(mut self, new_value: &str) -> ActivityWatchCall<'a, C, NC, A> {
self._customer_id = Some(new_value.to_string());
self
}
/// Sets the *actor ip address* query property to the given value.
///
///
/// IP Address of host where the event was performed. Supports both IPv4 and IPv6 addresses.
pub fn actor_ip_address(mut self, new_value: &str) -> ActivityWatchCall<'a, C, NC, A> {
self._actor_ip_address = Some(new_value.to_string());
self
}
/// Sets the *delegate* property to the given 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.
pub fn delegate(mut self, new_value: &'a mut Delegate) -> ActivityWatchCall<'a, C, NC, 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) -> ActivityWatchCall<'a, C, NC, A>
where T: Str {
self._additional_params.insert(name.as_slice().to_string(), value.as_slice().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 of relying on the
/// automated algorithm which simply prefers read-only scopes over those who are not.
///
/// 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) -> ActivityWatchCall<'a, C, NC, A>
where T: Str {
self._scopes.insert(scope.as_slice().to_string(), ());
self
}
}
/// Retrieves a list of activities for a specific customer and application.
///
/// A builder for the *list* method supported by a *activity* resource.
/// It is not used directly, but through a `ActivityMethods`.
///
/// # Example
///
/// Instantiate a resource method builder
///
/// ```test_harness,no_run
/// # extern crate hyper;
/// # extern crate "yup-oauth2" as oauth2;
/// # extern crate "google-admin1_reports" as admin1_reports;
/// # #[test] fn egal() {
/// # use std::default::Default;
/// # use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage};
/// # use admin1_reports::Reports;
///
/// # let secret: ApplicationSecret = Default::default();
/// # let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate,
/// # hyper::Client::new(),
/// # <MemoryStorage as Default>::default(), None);
/// # let mut hub = Reports::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.activities().list("userKey", "applicationName")
/// .start_time("eirmod")
/// .page_token("dolore")
/// .max_results(-37)
/// .filters("aliquyam")
/// .event_name("accusam")
/// .end_time("Lorem")
/// .customer_id("sea")
/// .actor_ip_address("et")
/// .doit();
/// # }
/// ```
pub struct ActivityListCall<'a, C, NC, A>
where C: 'a, NC: 'a, A: 'a {
hub: &'a Reports<C, NC, A>,
_user_key: String,
_application_name: String,
_start_time: Option<String>,
_page_token: Option<String>,
_max_results: Option<i32>,
_filters: Option<String>,
_event_name: Option<String>,
_end_time: Option<String>,
_customer_id: Option<String>,
_actor_ip_address: Option<String>,
_delegate: Option<&'a mut Delegate>,
_additional_params: HashMap<String, String>,
_scopes: BTreeMap<String, ()>
}
impl<'a, C, NC, A> CallBuilder for ActivityListCall<'a, C, NC, A> {}
impl<'a, C, NC, A> ActivityListCall<'a, C, NC, A> where NC: hyper::net::NetworkConnector, C: BorrowMut<hyper::Client<NC>>, A: oauth2::GetToken {
/// Perform the operation you have build so far.
pub fn doit(mut self) -> Result<(hyper::client::Response, Activities)> {
use std::io::{Read, Seek};
use hyper::header::{ContentType, ContentLength, Authorization, UserAgent, Location};
let mut dd = DefaultDelegate;
let mut dlg: &mut Delegate = match self._delegate {
Some(d) => d,
None => &mut dd
};
dlg.begin(MethodInfo { id: "reports.activities.list",
http_method: hyper::method::Method::Get });
let mut params: Vec<(&str, String)> = Vec::with_capacity((12 + self._additional_params.len()));
params.push(("userKey", self._user_key.to_string()));
params.push(("applicationName", self._application_name.to_string()));
if let Some(value) = self._start_time {
params.push(("startTime", value.to_string()));
}
if let Some(value) = self._page_token {
params.push(("pageToken", value.to_string()));
}
if let Some(value) = self._max_results {
params.push(("maxResults", value.to_string()));
}
if let Some(value) = self._filters {
params.push(("filters", value.to_string()));
}
if let Some(value) = self._event_name {
params.push(("eventName", value.to_string()));
}
if let Some(value) = self._end_time {
params.push(("endTime", value.to_string()));
}
if let Some(value) = self._customer_id {
params.push(("customerId", value.to_string()));
}
if let Some(value) = self._actor_ip_address {
params.push(("actorIpAddress", value.to_string()));
}
for &field in ["alt", "userKey", "applicationName", "startTime", "pageToken", "maxResults", "filters", "eventName", "endTime", "customerId", "actorIpAddress"].iter() {
if self._additional_params.contains_key(field) {
dlg.finished(false);
return Result::FieldClash(field);
}
}
for (name, value) in self._additional_params.iter() {
params.push((&name, value.clone()));
}
params.push(("alt", "json".to_string()));
let mut url = "https://www.googleapis.com/admin/reports/v1/activity/users/{userKey}/applications/{applicationName}".to_string();
if self._scopes.len() == 0 {
self._scopes.insert(Scope::ReportAuditReadonly.as_slice().to_string(), ());
}
for &(find_this, param_name) in [("{userKey}", "userKey"), ("{applicationName}", "applicationName")].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 ["userKey", "applicationName"].iter() {
for (index, &(ref name, _)) in params.iter().rev().enumerate() {
if name == param_name {
indices_for_removal.push(params.len() - index - 1);
break;
}
}
}
for &index in indices_for_removal.iter() {
params.remove(index);
}
}
if params.len() > 0 {
url.push('?');
url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice()))));
}
loop {
let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys());
if token.is_none() {
token = dlg.token();
}
if token.is_none() {
dlg.finished(false);
return Result::MissingToken
}
let auth_header = Authorization(oauth2::Scheme { token_type: oauth2::TokenType::Bearer,
access_token: token.unwrap().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.as_slice())
.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 Result::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()) {
sleep(d);
continue;
}
dlg.finished(false);
return Result::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 Result::JsonDecodeError(err);
}
}
};
dlg.finished(true);
return Result::Success(result_value)
}
}
}
}
/// Sets the *user key* 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.
///
/// Represents the profile id or the user email for which the data should be filtered. When 'all' is specified as the userKey, it returns usageReports for all users.
pub fn user_key(mut self, new_value: &str) -> ActivityListCall<'a, C, NC, A> {
self._user_key = new_value.to_string();
self
}
/// Sets the *application 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.
///
/// Application name for which the events are to be retrieved.
pub fn application_name(mut self, new_value: &str) -> ActivityListCall<'a, C, NC, A> {
self._application_name = new_value.to_string();
self
}
/// Sets the *start time* query property to the given value.
///
///
/// Return events which occured at or after this time.
pub fn start_time(mut self, new_value: &str) -> ActivityListCall<'a, C, NC, A> {
self._start_time = Some(new_value.to_string());
self
}
/// Sets the *page token* query property to the given value.
///
///
/// Token to specify next page.
pub fn page_token(mut self, new_value: &str) -> ActivityListCall<'a, C, NC, A> {
self._page_token = Some(new_value.to_string());
self
}
/// Sets the *max results* query property to the given value.
///
///
/// Number of activity records to be shown in each page.
pub fn max_results(mut self, new_value: i32) -> ActivityListCall<'a, C, NC, A> {
self._max_results = Some(new_value);
self
}
/// Sets the *filters* query property to the given value.
///
///
/// Event parameters in the form [parameter1 name][operator][parameter1 value],[parameter2 name][operator][parameter2 value],...
pub fn filters(mut self, new_value: &str) -> ActivityListCall<'a, C, NC, A> {
self._filters = Some(new_value.to_string());
self
}
/// Sets the *event name* query property to the given value.
///
///
/// Name of the event being queried.
pub fn event_name(mut self, new_value: &str) -> ActivityListCall<'a, C, NC, A> {
self._event_name = Some(new_value.to_string());
self
}
/// Sets the *end time* query property to the given value.
///
///
/// Return events which occured at or before this time.
pub fn end_time(mut self, new_value: &str) -> ActivityListCall<'a, C, NC, A> {
self._end_time = Some(new_value.to_string());
self
}
/// Sets the *customer id* query property to the given value.
///
///
/// Represents the customer for which the data is to be fetched.
pub fn customer_id(mut self, new_value: &str) -> ActivityListCall<'a, C, NC, A> {
self._customer_id = Some(new_value.to_string());
self
}
/// Sets the *actor ip address* query property to the given value.
///
///
/// IP Address of host where the event was performed. Supports both IPv4 and IPv6 addresses.
pub fn actor_ip_address(mut self, new_value: &str) -> ActivityListCall<'a, C, NC, A> {
self._actor_ip_address = Some(new_value.to_string());
self
}
/// Sets the *delegate* property to the given 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.
pub fn delegate(mut self, new_value: &'a mut Delegate) -> ActivityListCall<'a, C, NC, 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) -> ActivityListCall<'a, C, NC, A>
where T: Str {
self._additional_params.insert(name.as_slice().to_string(), value.as_slice().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 of relying on the
/// automated algorithm which simply prefers read-only scopes over those who are not.
///
/// 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) -> ActivityListCall<'a, C, NC, A>
where T: Str {
self._scopes.insert(scope.as_slice().to_string(), ());
self
}
}
/// Retrieves a report which is a collection of properties / statistics for a specific customer.
///
/// A builder for the *get* method supported by a *customerUsageReport* resource.
/// It is not used directly, but through a `CustomerUsageReportMethods`.
///
/// # Example
///
/// Instantiate a resource method builder
///
/// ```test_harness,no_run
/// # extern crate hyper;
/// # extern crate "yup-oauth2" as oauth2;
/// # extern crate "google-admin1_reports" as admin1_reports;
/// # #[test] fn egal() {
/// # use std::default::Default;
/// # use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage};
/// # use admin1_reports::Reports;
///
/// # let secret: ApplicationSecret = Default::default();
/// # let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate,
/// # hyper::Client::new(),
/// # <MemoryStorage as Default>::default(), None);
/// # let mut hub = Reports::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.customer_usage_reports().get("date")
/// .parameters("et")
/// .page_token("eirmod")
/// .customer_id("sanctus")
/// .doit();
/// # }
/// ```
pub struct CustomerUsageReportGetCall<'a, C, NC, A>
where C: 'a, NC: 'a, A: 'a {
hub: &'a Reports<C, NC, A>,
_date: String,
_parameters: Option<String>,
_page_token: Option<String>,
_customer_id: Option<String>,
_delegate: Option<&'a mut Delegate>,
_additional_params: HashMap<String, String>,
_scopes: BTreeMap<String, ()>
}
impl<'a, C, NC, A> CallBuilder for CustomerUsageReportGetCall<'a, C, NC, A> {}
impl<'a, C, NC, A> CustomerUsageReportGetCall<'a, C, NC, A> where NC: hyper::net::NetworkConnector, C: BorrowMut<hyper::Client<NC>>, A: oauth2::GetToken {
/// Perform the operation you have build so far.
pub fn doit(mut self) -> Result<(hyper::client::Response, UsageReports)> {
use std::io::{Read, Seek};
use hyper::header::{ContentType, ContentLength, Authorization, UserAgent, Location};
let mut dd = DefaultDelegate;
let mut dlg: &mut Delegate = match self._delegate {
Some(d) => d,
None => &mut dd
};
dlg.begin(MethodInfo { id: "reports.customerUsageReports.get",
http_method: hyper::method::Method::Get });
let mut params: Vec<(&str, String)> = Vec::with_capacity((6 + self._additional_params.len()));
params.push(("date", self._date.to_string()));
if let Some(value) = self._parameters {
params.push(("parameters", value.to_string()));
}
if let Some(value) = self._page_token {
params.push(("pageToken", value.to_string()));
}
if let Some(value) = self._customer_id {
params.push(("customerId", value.to_string()));
}
for &field in ["alt", "date", "parameters", "pageToken", "customerId"].iter() {
if self._additional_params.contains_key(field) {
dlg.finished(false);
return Result::FieldClash(field);
}
}
for (name, value) in self._additional_params.iter() {
params.push((&name, value.clone()));
}
params.push(("alt", "json".to_string()));
let mut url = "https://www.googleapis.com/admin/reports/v1/usage/dates/{date}".to_string();
if self._scopes.len() == 0 {
self._scopes.insert(Scope::ReportAuditReadonly.as_slice().to_string(), ());
}
for &(find_this, param_name) in [("{date}", "date")].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 ["date"].iter() {
for (index, &(ref name, _)) in params.iter().rev().enumerate() {
if name == param_name {
indices_for_removal.push(params.len() - index - 1);
break;
}
}
}
for &index in indices_for_removal.iter() {
params.remove(index);
}
}
if params.len() > 0 {
url.push('?');
url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice()))));
}
loop {
let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys());
if token.is_none() {
token = dlg.token();
}
if token.is_none() {
dlg.finished(false);
return Result::MissingToken
}
let auth_header = Authorization(oauth2::Scheme { token_type: oauth2::TokenType::Bearer,
access_token: token.unwrap().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.as_slice())
.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 Result::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()) {
sleep(d);
continue;
}
dlg.finished(false);
return Result::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 Result::JsonDecodeError(err);
}
}
};
dlg.finished(true);
return Result::Success(result_value)
}
}
}
}
/// Sets the *date* 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.
///
/// Represents the date in yyyy-mm-dd format for which the data is to be fetched.
pub fn date(mut self, new_value: &str) -> CustomerUsageReportGetCall<'a, C, NC, A> {
self._date = new_value.to_string();
self
}
/// Sets the *parameters* query property to the given value.
///
///
/// Represents the application name, parameter name pairs to fetch in csv as app_name1:param_name1, app_name2:param_name2.
pub fn parameters(mut self, new_value: &str) -> CustomerUsageReportGetCall<'a, C, NC, A> {
self._parameters = Some(new_value.to_string());
self
}
/// Sets the *page token* query property to the given value.
///
///
/// Token to specify next page.
pub fn page_token(mut self, new_value: &str) -> CustomerUsageReportGetCall<'a, C, NC, A> {
self._page_token = Some(new_value.to_string());
self
}
/// Sets the *customer id* query property to the given value.
///
///
/// Represents the customer for which the data is to be fetched.
pub fn customer_id(mut self, new_value: &str) -> CustomerUsageReportGetCall<'a, C, NC, A> {
self._customer_id = Some(new_value.to_string());
self
}
/// Sets the *delegate* property to the given 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.
pub fn delegate(mut self, new_value: &'a mut Delegate) -> CustomerUsageReportGetCall<'a, C, NC, 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) -> CustomerUsageReportGetCall<'a, C, NC, A>
where T: Str {
self._additional_params.insert(name.as_slice().to_string(), value.as_slice().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 of relying on the
/// automated algorithm which simply prefers read-only scopes over those who are not.
///
/// 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) -> CustomerUsageReportGetCall<'a, C, NC, A>
where T: Str {
self._scopes.insert(scope.as_slice().to_string(), ());
self
}
}
/// Retrieves a report which is a collection of properties / statistics for a set of users.
///
/// A builder for the *get* method supported by a *userUsageReport* resource.
/// It is not used directly, but through a `UserUsageReportMethods`.
///
/// # Example
///
/// Instantiate a resource method builder
///
/// ```test_harness,no_run
/// # extern crate hyper;
/// # extern crate "yup-oauth2" as oauth2;
/// # extern crate "google-admin1_reports" as admin1_reports;
/// # #[test] fn egal() {
/// # use std::default::Default;
/// # use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage};
/// # use admin1_reports::Reports;
///
/// # let secret: ApplicationSecret = Default::default();
/// # let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate,
/// # hyper::Client::new(),
/// # <MemoryStorage as Default>::default(), None);
/// # let mut hub = Reports::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.user_usage_report().get("userKey", "date")
/// .parameters("et")
/// .page_token("consetetur")
/// .max_results(65)
/// .filters("ea")
/// .customer_id("sed")
/// .doit();
/// # }
/// ```
pub struct UserUsageReportGetCall<'a, C, NC, A>
where C: 'a, NC: 'a, A: 'a {
hub: &'a Reports<C, NC, A>,
_user_key: String,
_date: String,
_parameters: Option<String>,
_page_token: Option<String>,
_max_results: Option<u32>,
_filters: Option<String>,
_customer_id: Option<String>,
_delegate: Option<&'a mut Delegate>,
_additional_params: HashMap<String, String>,
_scopes: BTreeMap<String, ()>
}
impl<'a, C, NC, A> CallBuilder for UserUsageReportGetCall<'a, C, NC, A> {}
impl<'a, C, NC, A> UserUsageReportGetCall<'a, C, NC, A> where NC: hyper::net::NetworkConnector, C: BorrowMut<hyper::Client<NC>>, A: oauth2::GetToken {
/// Perform the operation you have build so far.
pub fn doit(mut self) -> Result<(hyper::client::Response, UsageReports)> {
use std::io::{Read, Seek};
use hyper::header::{ContentType, ContentLength, Authorization, UserAgent, Location};
let mut dd = DefaultDelegate;
let mut dlg: &mut Delegate = match self._delegate {
Some(d) => d,
None => &mut dd
};
dlg.begin(MethodInfo { id: "reports.userUsageReport.get",
http_method: hyper::method::Method::Get });
let mut params: Vec<(&str, String)> = Vec::with_capacity((9 + self._additional_params.len()));
params.push(("userKey", self._user_key.to_string()));
params.push(("date", self._date.to_string()));
if let Some(value) = self._parameters {
params.push(("parameters", value.to_string()));
}
if let Some(value) = self._page_token {
params.push(("pageToken", value.to_string()));
}
if let Some(value) = self._max_results {
params.push(("maxResults", value.to_string()));
}
if let Some(value) = self._filters {
params.push(("filters", value.to_string()));
}
if let Some(value) = self._customer_id {
params.push(("customerId", value.to_string()));
}
for &field in ["alt", "userKey", "date", "parameters", "pageToken", "maxResults", "filters", "customerId"].iter() {
if self._additional_params.contains_key(field) {
dlg.finished(false);
return Result::FieldClash(field);
}
}
for (name, value) in self._additional_params.iter() {
params.push((&name, value.clone()));
}
params.push(("alt", "json".to_string()));
let mut url = "https://www.googleapis.com/admin/reports/v1/usage/users/{userKey}/dates/{date}".to_string();
if self._scopes.len() == 0 {
self._scopes.insert(Scope::ReportAuditReadonly.as_slice().to_string(), ());
}
for &(find_this, param_name) in [("{userKey}", "userKey"), ("{date}", "date")].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 ["userKey", "date"].iter() {
for (index, &(ref name, _)) in params.iter().rev().enumerate() {
if name == param_name {
indices_for_removal.push(params.len() - index - 1);
break;
}
}
}
for &index in indices_for_removal.iter() {
params.remove(index);
}
}
if params.len() > 0 {
url.push('?');
url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice()))));
}
loop {
let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys());
if token.is_none() {
token = dlg.token();
}
if token.is_none() {
dlg.finished(false);
return Result::MissingToken
}
let auth_header = Authorization(oauth2::Scheme { token_type: oauth2::TokenType::Bearer,
access_token: token.unwrap().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.as_slice())
.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 Result::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()) {
sleep(d);
continue;
}
dlg.finished(false);
return Result::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 Result::JsonDecodeError(err);
}
}
};
dlg.finished(true);
return Result::Success(result_value)
}
}
}
}
/// Sets the *user key* 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.
///
/// Represents the profile id or the user email for which the data should be filtered.
pub fn user_key(mut self, new_value: &str) -> UserUsageReportGetCall<'a, C, NC, A> {
self._user_key = new_value.to_string();
self
}
/// Sets the *date* 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.
///
/// Represents the date in yyyy-mm-dd format for which the data is to be fetched.
pub fn date(mut self, new_value: &str) -> UserUsageReportGetCall<'a, C, NC, A> {
self._date = new_value.to_string();
self
}
/// Sets the *parameters* query property to the given value.
///
///
/// Represents the application name, parameter name pairs to fetch in csv as app_name1:param_name1, app_name2:param_name2.
pub fn parameters(mut self, new_value: &str) -> UserUsageReportGetCall<'a, C, NC, A> {
self._parameters = Some(new_value.to_string());
self
}
/// Sets the *page token* query property to the given value.
///
///
/// Token to specify next page.
pub fn page_token(mut self, new_value: &str) -> UserUsageReportGetCall<'a, C, NC, A> {
self._page_token = Some(new_value.to_string());
self
}
/// Sets the *max results* query property to the given value.
///
///
/// Maximum number of results to return. Maximum allowed is 1000
pub fn max_results(mut self, new_value: u32) -> UserUsageReportGetCall<'a, C, NC, A> {
self._max_results = Some(new_value);
self
}
/// Sets the *filters* query property to the given value.
///
///
/// Represents the set of filters including parameter operator value.
pub fn filters(mut self, new_value: &str) -> UserUsageReportGetCall<'a, C, NC, A> {
self._filters = Some(new_value.to_string());
self
}
/// Sets the *customer id* query property to the given value.
///
///
/// Represents the customer for which the data is to be fetched.
pub fn customer_id(mut self, new_value: &str) -> UserUsageReportGetCall<'a, C, NC, A> {
self._customer_id = Some(new_value.to_string());
self
}
/// Sets the *delegate* property to the given 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.
pub fn delegate(mut self, new_value: &'a mut Delegate) -> UserUsageReportGetCall<'a, C, NC, 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) -> UserUsageReportGetCall<'a, C, NC, A>
where T: Str {
self._additional_params.insert(name.as_slice().to_string(), value.as_slice().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 of relying on the
/// automated algorithm which simply prefers read-only scopes over those who are not.
///
/// 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) -> UserUsageReportGetCall<'a, C, NC, A>
where T: Str {
self._scopes.insert(scope.as_slice().to_string(), ());
self
}
}