#![allow(clippy::ptr_arg)]
use std::collections::{BTreeSet, HashMap};
use tokio::time::sleep;
#[derive(PartialEq, Eq, Ord, PartialOrd, Hash, Debug, Clone, Copy)]
pub enum Scope {
Activity,
}
impl AsRef<str> for Scope {
fn as_ref(&self) -> &str {
match *self {
Scope::Activity => "https://www.googleapis.com/auth/activity",
}
}
}
#[allow(clippy::derivable_impls)]
impl Default for Scope {
fn default() -> Scope {
Scope::Activity
}
}
#[derive(Clone)]
pub struct Appsactivity<C> {
pub client: common::Client<C>,
pub auth: Box<dyn common::GetToken>,
_user_agent: String,
_base_url: String,
_root_url: String,
}
impl<C> common::Hub for Appsactivity<C> {}
impl<'a, C> Appsactivity<C> {
pub fn new<A: 'static + common::GetToken>(
client: common::Client<C>,
auth: A,
) -> Appsactivity<C> {
Appsactivity {
client,
auth: Box::new(auth),
_user_agent: "google-api-rust-client/6.0.0".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> {
ActivityMethods { hub: self }
}
pub fn user_agent(&mut self, agent_name: String) -> String {
std::mem::replace(&mut self._user_agent, agent_name)
}
pub fn base_url(&mut self, new_base_url: String) -> String {
std::mem::replace(&mut self._base_url, new_base_url)
}
pub fn root_url(&mut self, new_root_url: String) -> String {
std::mem::replace(&mut self._root_url, new_root_url)
}
}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[serde_with::serde_as]
#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct Activity {
#[serde(rename = "combinedEvent")]
pub combined_event: Option<Event>,
#[serde(rename = "singleEvents")]
pub single_events: Option<Vec<Event>>,
}
impl common::Part for Activity {}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[serde_with::serde_as]
#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct Event {
#[serde(rename = "additionalEventTypes")]
pub additional_event_types: Option<Vec<String>>,
#[serde(rename = "eventTimeMillis")]
#[serde_as(as = "Option<serde_with::DisplayFromStr>")]
pub event_time_millis: Option<u64>,
#[serde(rename = "fromUserDeletion")]
pub from_user_deletion: Option<bool>,
#[serde(rename = "move")]
pub move_: Option<Move>,
#[serde(rename = "permissionChanges")]
pub permission_changes: Option<Vec<PermissionChange>>,
#[serde(rename = "primaryEventType")]
pub primary_event_type: Option<String>,
pub rename: Option<Rename>,
pub target: Option<Target>,
pub user: Option<User>,
}
impl common::Part for Event {}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[serde_with::serde_as]
#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct ListActivitiesResponse {
pub activities: Option<Vec<Activity>>,
#[serde(rename = "nextPageToken")]
pub next_page_token: Option<String>,
}
impl common::ResponseResult for ListActivitiesResponse {}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[serde_with::serde_as]
#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct Move {
#[serde(rename = "addedParents")]
pub added_parents: Option<Vec<Parent>>,
#[serde(rename = "removedParents")]
pub removed_parents: Option<Vec<Parent>>,
}
impl common::Part for Move {}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[serde_with::serde_as]
#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct Parent {
pub id: Option<String>,
#[serde(rename = "isRoot")]
pub is_root: Option<bool>,
pub title: Option<String>,
}
impl common::Part for Parent {}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[serde_with::serde_as]
#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct Permission {
pub name: Option<String>,
#[serde(rename = "permissionId")]
pub permission_id: Option<String>,
pub role: Option<String>,
#[serde(rename = "type")]
pub type_: Option<String>,
pub user: Option<User>,
#[serde(rename = "withLink")]
pub with_link: Option<bool>,
}
impl common::Part for Permission {}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[serde_with::serde_as]
#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct PermissionChange {
#[serde(rename = "addedPermissions")]
pub added_permissions: Option<Vec<Permission>>,
#[serde(rename = "removedPermissions")]
pub removed_permissions: Option<Vec<Permission>>,
}
impl common::Part for PermissionChange {}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[serde_with::serde_as]
#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct Photo {
pub url: Option<String>,
}
impl common::Part for Photo {}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[serde_with::serde_as]
#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct Rename {
#[serde(rename = "newTitle")]
pub new_title: Option<String>,
#[serde(rename = "oldTitle")]
pub old_title: Option<String>,
}
impl common::Part for Rename {}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[serde_with::serde_as]
#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct Target {
pub id: Option<String>,
#[serde(rename = "mimeType")]
pub mime_type: Option<String>,
pub name: Option<String>,
}
impl common::Part for Target {}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[serde_with::serde_as]
#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct User {
#[serde(rename = "isDeleted")]
pub is_deleted: Option<bool>,
#[serde(rename = "isMe")]
pub is_me: Option<bool>,
pub name: Option<String>,
#[serde(rename = "permissionId")]
pub permission_id: Option<String>,
pub photo: Option<Photo>,
}
impl common::Part for User {}
pub struct ActivityMethods<'a, C>
where
C: 'a,
{
hub: &'a Appsactivity<C>,
}
impl<'a, C> common::MethodsBuilder for ActivityMethods<'a, C> {}
impl<'a, C> ActivityMethods<'a, C> {
pub fn list(&self) -> ActivityListCall<'a, C> {
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(),
_additional_params: Default::default(),
_scopes: Default::default(),
}
}
}
pub struct ActivityListCall<'a, C>
where
C: 'a,
{
hub: &'a Appsactivity<C>,
_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 dyn common::Delegate>,
_additional_params: HashMap<String, String>,
_scopes: BTreeSet<String>,
}
impl<'a, C> common::CallBuilder for ActivityListCall<'a, C> {}
impl<'a, C> ActivityListCall<'a, C>
where
C: common::Connector,
{
pub async fn doit(mut self) -> common::Result<(common::Response, ListActivitiesResponse)> {
use std::borrow::Cow;
use std::io::{Read, Seek};
use common::{url::Params, ToParts};
use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
let mut dd = common::DefaultDelegate;
let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
dlg.begin(common::MethodInfo {
id: "appsactivity.activities.list",
http_method: hyper::Method::GET,
});
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(common::Error::FieldClash(field));
}
}
let mut params = Params::with_capacity(9 + self._additional_params.len());
if let Some(value) = self._user_id.as_ref() {
params.push("userId", value);
}
if let Some(value) = self._source.as_ref() {
params.push("source", value);
}
if let Some(value) = self._page_token.as_ref() {
params.push("pageToken", value);
}
if let Some(value) = self._page_size.as_ref() {
params.push("pageSize", value.to_string());
}
if let Some(value) = self._grouping_strategy.as_ref() {
params.push("groupingStrategy", value);
}
if let Some(value) = self._drive_file_id.as_ref() {
params.push("drive.fileId", value);
}
if let Some(value) = self._drive_ancestor_id.as_ref() {
params.push("drive.ancestorId", value);
}
params.extend(self._additional_params.iter());
params.push("alt", "json");
let mut url = self.hub._base_url.clone() + "activities";
if self._scopes.is_empty() {
self._scopes.insert(Scope::Activity.as_ref().to_string());
}
let url = params.parse_with_url(&url);
loop {
let token = match self
.hub
.auth
.get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
.await
{
Ok(token) => token,
Err(e) => match dlg.token(e) {
Ok(token) => token,
Err(e) => {
dlg.finished(false);
return Err(common::Error::MissingToken(e));
}
},
};
let mut req_result = {
let client = &self.hub.client;
dlg.pre_request();
let mut req_builder = hyper::Request::builder()
.method(hyper::Method::GET)
.uri(url.as_str())
.header(USER_AGENT, self.hub._user_agent.clone());
if let Some(token) = token.as_ref() {
req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
}
let request = req_builder
.header(CONTENT_LENGTH, 0_u64)
.body(common::to_body::<String>(None));
client.request(request.unwrap()).await
};
match req_result {
Err(err) => {
if let common::Retry::After(d) = dlg.http_error(&err) {
sleep(d).await;
continue;
}
dlg.finished(false);
return Err(common::Error::HttpError(err));
}
Ok(res) => {
let (mut parts, body) = res.into_parts();
let mut body = common::Body::new(body);
if !parts.status.is_success() {
let bytes = common::to_bytes(body).await.unwrap_or_default();
let error = serde_json::from_str(&common::to_string(&bytes));
let response = common::to_response(parts, bytes.into());
if let common::Retry::After(d) =
dlg.http_failure(&response, error.as_ref().ok())
{
sleep(d).await;
continue;
}
dlg.finished(false);
return Err(match error {
Ok(value) => common::Error::BadRequest(value),
_ => common::Error::Failure(response),
});
}
let response = {
let bytes = common::to_bytes(body).await.unwrap_or_default();
let encoded = common::to_string(&bytes);
match serde_json::from_str(&encoded) {
Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
Err(error) => {
dlg.response_json_decode_error(&encoded, &error);
return Err(common::Error::JsonDecodeError(
encoded.to_string(),
error,
));
}
}
};
dlg.finished(true);
return Ok(response);
}
}
}
}
pub fn user_id(mut self, new_value: &str) -> ActivityListCall<'a, C> {
self._user_id = Some(new_value.to_string());
self
}
pub fn source(mut self, new_value: &str) -> ActivityListCall<'a, C> {
self._source = Some(new_value.to_string());
self
}
pub fn page_token(mut self, new_value: &str) -> ActivityListCall<'a, C> {
self._page_token = Some(new_value.to_string());
self
}
pub fn page_size(mut self, new_value: i32) -> ActivityListCall<'a, C> {
self._page_size = Some(new_value);
self
}
pub fn grouping_strategy(mut self, new_value: &str) -> ActivityListCall<'a, C> {
self._grouping_strategy = Some(new_value.to_string());
self
}
pub fn drive_file_id(mut self, new_value: &str) -> ActivityListCall<'a, C> {
self._drive_file_id = Some(new_value.to_string());
self
}
pub fn drive_ancestor_id(mut self, new_value: &str) -> ActivityListCall<'a, C> {
self._drive_ancestor_id = Some(new_value.to_string());
self
}
pub fn delegate(mut self, new_value: &'a mut dyn common::Delegate) -> ActivityListCall<'a, C> {
self._delegate = Some(new_value);
self
}
pub fn param<T>(mut self, name: T, value: T) -> ActivityListCall<'a, C>
where
T: AsRef<str>,
{
self._additional_params
.insert(name.as_ref().to_string(), value.as_ref().to_string());
self
}
pub fn add_scope<St>(mut self, scope: St) -> ActivityListCall<'a, C>
where
St: AsRef<str>,
{
self._scopes.insert(String::from(scope.as_ref()));
self
}
pub fn add_scopes<I, St>(mut self, scopes: I) -> ActivityListCall<'a, C>
where
I: IntoIterator<Item = St>,
St: AsRef<str>,
{
self._scopes
.extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
self
}
pub fn clear_scopes(mut self) -> ActivityListCall<'a, C> {
self._scopes.clear();
self
}
}