#![allow(unused_imports, unused_mut, dead_code)]
#[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};
#[derive(PartialEq, Eq, Hash)]
pub enum Scope {
Drive,
Activity,
DriveMetadata,
DriveMetadataReadonly,
DriveReadonly,
}
impl AsRef<str> for Scope {
fn as_ref(&self) -> &str {
match *self {
Scope::Drive => "https://www.googleapis.com/auth/drive",
Scope::Activity => "https://www.googleapis.com/auth/activity",
Scope::DriveMetadata => "https://www.googleapis.com/auth/drive.metadata",
Scope::DriveMetadataReadonly => "https://www.googleapis.com/auth/drive.metadata.readonly",
Scope::DriveReadonly => "https://www.googleapis.com/auth/drive.readonly",
}
}
}
impl Default for Scope {
fn default() -> Scope {
Scope::DriveMetadataReadonly
}
}
pub struct Appsactivity<C, A> {
client: RefCell<C>,
auth: RefCell<A>,
_user_agent: String,
_base_url: String,
_root_url: String,
}
impl<'a, C, A> Hub for Appsactivity<C, A> {}
impl<'a, C, A> Appsactivity<C, A>
where C: BorrowMut<hyper::Client>, A: oauth2::GetToken {
pub fn new(client: C, authenticator: A) -> Appsactivity<C, A> {
Appsactivity {
client: RefCell::new(client),
auth: RefCell::new(authenticator),
_user_agent: "google-api-rust-client/1.0.6".to_string(),
_base_url: "https://www.googleapis.com/appsactivity/v1/".to_string(),
_root_url: "https://www.googleapis.com/".to_string(),
}
}
pub fn activities(&'a self) -> ActivityMethods<'a, C, A> {
ActivityMethods { hub: &self }
}
pub fn user_agent(&mut self, agent_name: String) -> String {
mem::replace(&mut self._user_agent, agent_name)
}
pub fn base_url(&mut self, new_base_url: String) -> String {
mem::replace(&mut self._base_url, new_base_url)
}
pub fn root_url(&mut self, new_root_url: String) -> String {
mem::replace(&mut self._root_url, new_root_url)
}
}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct Rename {
#[serde(rename="newTitle")]
pub new_title: Option<String>,
#[serde(rename="oldTitle")]
pub old_title: Option<String>,
}
impl Part for Rename {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct PermissionChange {
#[serde(rename="removedPermissions")]
pub removed_permissions: Option<Vec<Permission>>,
#[serde(rename="addedPermissions")]
pub added_permissions: Option<Vec<Permission>>,
}
impl Part for PermissionChange {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct Target {
#[serde(rename="mimeType")]
pub mime_type: Option<String>,
pub id: Option<String>,
pub name: Option<String>,
}
impl Part for Target {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct Parent {
pub id: Option<String>,
#[serde(rename="isRoot")]
pub is_root: Option<bool>,
pub title: Option<String>,
}
impl Part for Parent {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct Permission {
#[serde(rename="withLink")]
pub with_link: Option<bool>,
#[serde(rename="permissionId")]
pub permission_id: Option<String>,
pub role: Option<String>,
pub name: Option<String>,
#[serde(rename="type")]
pub type_: Option<String>,
pub user: Option<User>,
}
impl Part for Permission {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct Photo {
pub url: Option<String>,
}
impl Part for Photo {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct Move {
#[serde(rename="removedParents")]
pub removed_parents: Option<Vec<Parent>>,
#[serde(rename="addedParents")]
pub added_parents: Option<Vec<Parent>>,
}
impl Part for Move {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct ListActivitiesResponse {
#[serde(rename="nextPageToken")]
pub next_page_token: Option<String>,
pub activities: Option<Vec<Activity>>,
}
impl ResponseResult for ListActivitiesResponse {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct User {
pub photo: Option<Photo>,
#[serde(rename="permissionId")]
pub permission_id: Option<String>,
#[serde(rename="isDeleted")]
pub is_deleted: Option<bool>,
#[serde(rename="isMe")]
pub is_me: Option<bool>,
pub name: Option<String>,
}
impl Part for User {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct Activity {
#[serde(rename="combinedEvent")]
pub combined_event: Option<Event>,
#[serde(rename="singleEvents")]
pub single_events: Option<Vec<Event>>,
}
impl Part for Activity {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct Event {
pub rename: Option<Rename>,
pub target: Option<Target>,
#[serde(rename="additionalEventTypes")]
pub additional_event_types: Option<Vec<String>>,
#[serde(rename="move")]
pub move_: Option<Move>,
#[serde(rename="permissionChanges")]
pub permission_changes: Option<Vec<PermissionChange>>,
pub user: Option<User>,
#[serde(rename="eventTimeMillis")]
pub event_time_millis: Option<String>,
#[serde(rename="primaryEventType")]
pub primary_event_type: Option<String>,
#[serde(rename="fromUserDeletion")]
pub from_user_deletion: Option<bool>,
}
impl Part for Event {}
pub struct ActivityMethods<'a, C, A>
where C: 'a, A: 'a {
hub: &'a Appsactivity<C, A>,
}
impl<'a, C, A> MethodsBuilder for ActivityMethods<'a, C, A> {}
impl<'a, C, A> ActivityMethods<'a, C, A> {
pub fn list(&self) -> ActivityListCall<'a, C, A> {
ActivityListCall {
hub: self.hub,
_user_id: Default::default(),
_source: Default::default(),
_page_token: Default::default(),
_page_size: Default::default(),
_grouping_strategy: Default::default(),
_drive_file_id: Default::default(),
_drive_ancestor_id: Default::default(),
_delegate: Default::default(),
_scopes: Default::default(),
_additional_params: Default::default(),
}
}
}
pub struct ActivityListCall<'a, C, A>
where C: 'a, A: 'a {
hub: &'a Appsactivity<C, A>,
_user_id: Option<String>,
_source: Option<String>,
_page_token: Option<String>,
_page_size: Option<i32>,
_grouping_strategy: Option<String>,
_drive_file_id: Option<String>,
_drive_ancestor_id: Option<String>,
_delegate: Option<&'a mut Delegate>,
_additional_params: HashMap<String, String>,
_scopes: BTreeMap<String, ()>
}
impl<'a, C, A> CallBuilder for ActivityListCall<'a, C, A> {}
impl<'a, C, A> ActivityListCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oauth2::GetToken {
pub fn doit(mut self) -> Result<(hyper::client::Response, ListActivitiesResponse)> {
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: "appsactivity.activities.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._user_id {
params.push(("userId", value.to_string()));
}
if let Some(value) = self._source {
params.push(("source", value.to_string()));
}
if let Some(value) = self._page_token {
params.push(("pageToken", value.to_string()));
}
if let Some(value) = self._page_size {
params.push(("pageSize", value.to_string()));
}
if let Some(value) = self._grouping_strategy {
params.push(("groupingStrategy", value.to_string()));
}
if let Some(value) = self._drive_file_id {
params.push(("drive.fileId", value.to_string()));
}
if let Some(value) = self._drive_ancestor_id {
params.push(("drive.ancestorId", value.to_string()));
}
for &field in ["alt", "userId", "source", "pageToken", "pageSize", "groupingStrategy", "drive.fileId", "drive.ancestorId"].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() + "activities";
if self._scopes.len() == 0 {
self._scopes.insert(Scope::DriveMetadataReadonly.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)
}
}
}
}
pub fn user_id(mut self, new_value: &str) -> ActivityListCall<'a, C, A> {
self._user_id = Some(new_value.to_string());
self
}
pub fn source(mut self, new_value: &str) -> ActivityListCall<'a, C, A> {
self._source = Some(new_value.to_string());
self
}
pub fn page_token(mut self, new_value: &str) -> ActivityListCall<'a, C, A> {
self._page_token = Some(new_value.to_string());
self
}
pub fn page_size(mut self, new_value: i32) -> ActivityListCall<'a, C, A> {
self._page_size = Some(new_value);
self
}
pub fn grouping_strategy(mut self, new_value: &str) -> ActivityListCall<'a, C, A> {
self._grouping_strategy = Some(new_value.to_string());
self
}
pub fn drive_file_id(mut self, new_value: &str) -> ActivityListCall<'a, C, A> {
self._drive_file_id = Some(new_value.to_string());
self
}
pub fn drive_ancestor_id(mut self, new_value: &str) -> ActivityListCall<'a, C, A> {
self._drive_ancestor_id = Some(new_value.to_string());
self
}
pub fn delegate(mut self, new_value: &'a mut Delegate) -> ActivityListCall<'a, C, A> {
self._delegate = Some(new_value);
self
}
pub fn param<T>(mut self, name: T, value: T) -> ActivityListCall<'a, C, A>
where T: AsRef<str> {
self._additional_params.insert(name.as_ref().to_string(), value.as_ref().to_string());
self
}
pub fn add_scope<T, S>(mut self, scope: T) -> ActivityListCall<'a, C, A>
where T: Into<Option<S>>,
S: AsRef<str> {
match scope.into() {
Some(scope) => self._scopes.insert(scope.as_ref().to_string(), ()),
None => None,
};
self
}
}