#![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::*;
#[derive(PartialEq, Eq, Hash)]
pub enum Scope {
CloudPlatform,
}
impl AsRef<str> for Scope {
fn as_ref(&self) -> &str {
match *self {
Scope::CloudPlatform => "https://www.googleapis.com/auth/cloud-platform",
}
}
}
impl Default for Scope {
fn default() -> Scope {
Scope::CloudPlatform
}
}
pub struct CloudAsset<C, A> {
client: RefCell<C>,
auth: RefCell<A>,
_user_agent: String,
_base_url: String,
_root_url: String,
}
impl<'a, C, A> Hub for CloudAsset<C, A> {}
impl<'a, C, A> CloudAsset<C, A>
where C: BorrowMut<hyper::Client>, A: oauth2::GetToken {
pub fn new(client: C, authenticator: A) -> CloudAsset<C, A> {
CloudAsset {
client: RefCell::new(client),
auth: RefCell::new(authenticator),
_user_agent: "google-api-rust-client/1.0.10".to_string(),
_base_url: "https://cloudasset.googleapis.com/".to_string(),
_root_url: "https://cloudasset.googleapis.com/".to_string(),
}
}
pub fn methods(&'a self) -> MethodMethods<'a, C, A> {
MethodMethods { hub: &self }
}
pub fn operations(&'a self) -> OperationMethods<'a, C, A> {
OperationMethods { 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 AuditLogConfig {
#[serde(rename="exemptedMembers")]
pub exempted_members: Option<Vec<String>>,
#[serde(rename="logType")]
pub log_type: Option<String>,
}
impl Part for AuditLogConfig {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct GoogleCloudOrgpolicyV1RestoreDefault { _never_set: Option<bool> }
impl Part for GoogleCloudOrgpolicyV1RestoreDefault {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct ResourceType {
pub version: Option<String>,
#[serde(rename="resourceUrl")]
pub resource_url: Option<String>,
pub parent: Option<String>,
#[serde(rename="discoveryDocumentUri")]
pub discovery_document_uri: Option<String>,
pub data: Option<HashMap<String, String>>,
#[serde(rename="discoveryName")]
pub discovery_name: Option<String>,
}
impl Part for ResourceType {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct ExportAssetsRequest {
#[serde(rename="assetTypes")]
pub asset_types: Option<Vec<String>>,
#[serde(rename="contentType")]
pub content_type: Option<String>,
#[serde(rename="outputConfig")]
pub output_config: Option<OutputConfig>,
#[serde(rename="readTime")]
pub read_time: Option<String>,
}
impl RequestValue for ExportAssetsRequest {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct Expr {
pub description: Option<String>,
pub expression: Option<String>,
pub location: Option<String>,
pub title: Option<String>,
}
impl Part for Expr {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct TemporalAsset {
pub deleted: Option<bool>,
pub window: Option<TimeWindow>,
pub asset: Option<Asset>,
}
impl Part for TemporalAsset {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct Asset {
#[serde(rename="iamPolicy")]
pub iam_policy: Option<Policy>,
#[serde(rename="assetType")]
pub asset_type: Option<String>,
pub resource: Option<ResourceType>,
pub name: Option<String>,
#[serde(rename="orgPolicy")]
pub org_policy: Option<Vec<GoogleCloudOrgpolicyV1Policy>>,
}
impl Part for Asset {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct OutputConfig {
#[serde(rename="gcsDestination")]
pub gcs_destination: Option<GcsDestination>,
}
impl Part for OutputConfig {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct Policy {
#[serde(rename="auditConfigs")]
pub audit_configs: Option<Vec<AuditConfig>>,
pub etag: Option<String>,
pub bindings: Option<Vec<Binding>>,
pub version: Option<i32>,
}
impl Part for Policy {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct GoogleCloudOrgpolicyV1ListPolicy {
#[serde(rename="allValues")]
pub all_values: Option<String>,
#[serde(rename="allowedValues")]
pub allowed_values: Option<Vec<String>>,
#[serde(rename="inheritFromParent")]
pub inherit_from_parent: Option<bool>,
#[serde(rename="suggestedValue")]
pub suggested_value: Option<String>,
#[serde(rename="deniedValues")]
pub denied_values: Option<Vec<String>>,
}
impl Part for GoogleCloudOrgpolicyV1ListPolicy {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct Status {
pub message: Option<String>,
pub code: Option<i32>,
pub details: Option<Vec<HashMap<String, String>>>,
}
impl Part for Status {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct GoogleCloudOrgpolicyV1BooleanPolicy {
pub enforced: Option<bool>,
}
impl Part for GoogleCloudOrgpolicyV1BooleanPolicy {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct GoogleCloudOrgpolicyV1Policy {
#[serde(rename="updateTime")]
pub update_time: Option<String>,
pub version: Option<i32>,
pub etag: Option<String>,
pub constraint: Option<String>,
#[serde(rename="restoreDefault")]
pub restore_default: Option<GoogleCloudOrgpolicyV1RestoreDefault>,
#[serde(rename="listPolicy")]
pub list_policy: Option<GoogleCloudOrgpolicyV1ListPolicy>,
#[serde(rename="booleanPolicy")]
pub boolean_policy: Option<GoogleCloudOrgpolicyV1BooleanPolicy>,
}
impl Part for GoogleCloudOrgpolicyV1Policy {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct Binding {
pub role: Option<String>,
pub condition: Option<Expr>,
pub members: Option<Vec<String>>,
}
impl Part for Binding {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct BatchGetAssetsHistoryResponse {
pub assets: Option<Vec<TemporalAsset>>,
}
impl ResponseResult for BatchGetAssetsHistoryResponse {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct AuditConfig {
#[serde(rename="auditLogConfigs")]
pub audit_log_configs: Option<Vec<AuditLogConfig>>,
pub service: Option<String>,
}
impl Part for AuditConfig {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct TimeWindow {
#[serde(rename="endTime")]
pub end_time: Option<String>,
#[serde(rename="startTime")]
pub start_time: Option<String>,
}
impl Part for TimeWindow {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct Operation {
pub error: Option<Status>,
pub done: Option<bool>,
pub response: Option<HashMap<String, String>>,
pub name: Option<String>,
pub metadata: Option<HashMap<String, String>>,
}
impl Resource for Operation {}
impl ResponseResult for Operation {}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct GcsDestination {
#[serde(rename="uriPrefix")]
pub uri_prefix: Option<String>,
pub uri: Option<String>,
}
impl Part for GcsDestination {}
pub struct OperationMethods<'a, C, A>
where C: 'a, A: 'a {
hub: &'a CloudAsset<C, A>,
}
impl<'a, C, A> MethodsBuilder for OperationMethods<'a, C, A> {}
impl<'a, C, A> OperationMethods<'a, C, A> {
pub fn get(&self, name: &str) -> OperationGetCall<'a, C, A> {
OperationGetCall {
hub: self.hub,
_name: name.to_string(),
_delegate: Default::default(),
_scopes: Default::default(),
_additional_params: Default::default(),
}
}
}
pub struct MethodMethods<'a, C, A>
where C: 'a, A: 'a {
hub: &'a CloudAsset<C, A>,
}
impl<'a, C, A> MethodsBuilder for MethodMethods<'a, C, A> {}
impl<'a, C, A> MethodMethods<'a, C, A> {
pub fn batch_get_assets_history(&self, parent: &str) -> MethodBatchGetAssetsHistoryCall<'a, C, A> {
MethodBatchGetAssetsHistoryCall {
hub: self.hub,
_parent: parent.to_string(),
_read_time_window_start_time: Default::default(),
_read_time_window_end_time: Default::default(),
_content_type: Default::default(),
_asset_names: Default::default(),
_delegate: Default::default(),
_scopes: Default::default(),
_additional_params: Default::default(),
}
}
pub fn export_assets(&self, request: ExportAssetsRequest, parent: &str) -> MethodExportAssetCall<'a, C, A> {
MethodExportAssetCall {
hub: self.hub,
_request: request,
_parent: parent.to_string(),
_delegate: Default::default(),
_scopes: Default::default(),
_additional_params: Default::default(),
}
}
}
pub struct OperationGetCall<'a, C, A>
where C: 'a, A: 'a {
hub: &'a CloudAsset<C, A>,
_name: String,
_delegate: Option<&'a mut Delegate>,
_additional_params: HashMap<String, String>,
_scopes: BTreeMap<String, ()>
}
impl<'a, C, A> CallBuilder for OperationGetCall<'a, C, A> {}
impl<'a, C, A> OperationGetCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oauth2::GetToken {
pub fn doit(mut self) -> Result<(hyper::client::Response, Operation)> {
use url::percent_encoding::{percent_encode, DEFAULT_ENCODE_SET};
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: "cloudasset.operations.get",
http_method: hyper::method::Method::Get });
let mut params: Vec<(&str, String)> = Vec::with_capacity(3 + self._additional_params.len());
params.push(("name", self._name.to_string()));
for &field in ["alt", "name"].iter() {
if self._additional_params.contains_key(field) {
dlg.finished(false);
return Err(Error::FieldClash(field));
}
}
for (name, value) in self._additional_params.iter() {
params.push((&name, value.clone()));
}
params.push(("alt", "json".to_string()));
let mut url = self.hub._base_url.clone() + "v1/{+name}";
if self._scopes.len() == 0 {
self._scopes.insert(Scope::CloudPlatform.as_ref().to_string(), ());
}
for &(find_this, param_name) in [("{+name}", "name")].iter() {
let mut replace_with = String::new();
for &(name, ref value) in params.iter() {
if name == param_name {
replace_with = value.to_string();
break;
}
}
if find_this.as_bytes()[1] == '+' as u8 {
replace_with = percent_encode(replace_with.as_bytes(), DEFAULT_ENCODE_SET).to_string();
}
url = url.replace(find_this, &replace_with);
}
{
let mut indices_for_removal: Vec<usize> = Vec::with_capacity(1);
for param_name in ["name"].iter() {
if let Some(index) = params.iter().position(|t| &t.0 == param_name) {
indices_for_removal.push(index);
}
}
for &index in indices_for_removal.iter() {
params.remove(index);
}
}
let url = hyper::Url::parse_with_params(&url, params).unwrap();
loop {
let token = match self.hub.auth.borrow_mut().token(self._scopes.keys()) {
Ok(token) => token,
Err(err) => {
match dlg.token(&*err) {
Some(token) => token,
None => {
dlg.finished(false);
return Err(Error::MissingToken(err))
}
}
}
};
let auth_header = Authorization(Bearer { token: token.access_token });
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.clone())
.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 name(mut self, new_value: &str) -> OperationGetCall<'a, C, A> {
self._name = new_value.to_string();
self
}
pub fn delegate(mut self, new_value: &'a mut Delegate) -> OperationGetCall<'a, C, A> {
self._delegate = Some(new_value);
self
}
pub fn param<T>(mut self, name: T, value: T) -> OperationGetCall<'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) -> OperationGetCall<'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
}
}
pub struct MethodBatchGetAssetsHistoryCall<'a, C, A>
where C: 'a, A: 'a {
hub: &'a CloudAsset<C, A>,
_parent: String,
_read_time_window_start_time: Option<String>,
_read_time_window_end_time: Option<String>,
_content_type: Option<String>,
_asset_names: Vec<String>,
_delegate: Option<&'a mut Delegate>,
_additional_params: HashMap<String, String>,
_scopes: BTreeMap<String, ()>
}
impl<'a, C, A> CallBuilder for MethodBatchGetAssetsHistoryCall<'a, C, A> {}
impl<'a, C, A> MethodBatchGetAssetsHistoryCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oauth2::GetToken {
pub fn doit(mut self) -> Result<(hyper::client::Response, BatchGetAssetsHistoryResponse)> {
use url::percent_encoding::{percent_encode, DEFAULT_ENCODE_SET};
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: "cloudasset.batchGetAssetsHistory",
http_method: hyper::method::Method::Get });
let mut params: Vec<(&str, String)> = Vec::with_capacity(7 + self._additional_params.len());
params.push(("parent", self._parent.to_string()));
if let Some(value) = self._read_time_window_start_time {
params.push(("readTimeWindow.startTime", value.to_string()));
}
if let Some(value) = self._read_time_window_end_time {
params.push(("readTimeWindow.endTime", value.to_string()));
}
if let Some(value) = self._content_type {
params.push(("contentType", value.to_string()));
}
if self._asset_names.len() > 0 {
for f in self._asset_names.iter() {
params.push(("assetNames", f.to_string()));
}
}
for &field in ["alt", "parent", "readTimeWindow.startTime", "readTimeWindow.endTime", "contentType", "assetNames"].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() + "v1/{+parent}:batchGetAssetsHistory";
if self._scopes.len() == 0 {
self._scopes.insert(Scope::CloudPlatform.as_ref().to_string(), ());
}
for &(find_this, param_name) in [("{+parent}", "parent")].iter() {
let mut replace_with = String::new();
for &(name, ref value) in params.iter() {
if name == param_name {
replace_with = value.to_string();
break;
}
}
if find_this.as_bytes()[1] == '+' as u8 {
replace_with = percent_encode(replace_with.as_bytes(), DEFAULT_ENCODE_SET).to_string();
}
url = url.replace(find_this, &replace_with);
}
{
let mut indices_for_removal: Vec<usize> = Vec::with_capacity(1);
for param_name in ["parent"].iter() {
if let Some(index) = params.iter().position(|t| &t.0 == param_name) {
indices_for_removal.push(index);
}
}
for &index in indices_for_removal.iter() {
params.remove(index);
}
}
let url = hyper::Url::parse_with_params(&url, params).unwrap();
loop {
let token = match self.hub.auth.borrow_mut().token(self._scopes.keys()) {
Ok(token) => token,
Err(err) => {
match dlg.token(&*err) {
Some(token) => token,
None => {
dlg.finished(false);
return Err(Error::MissingToken(err))
}
}
}
};
let auth_header = Authorization(Bearer { token: token.access_token });
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.clone())
.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 parent(mut self, new_value: &str) -> MethodBatchGetAssetsHistoryCall<'a, C, A> {
self._parent = new_value.to_string();
self
}
pub fn read_time_window_start_time(mut self, new_value: &str) -> MethodBatchGetAssetsHistoryCall<'a, C, A> {
self._read_time_window_start_time = Some(new_value.to_string());
self
}
pub fn read_time_window_end_time(mut self, new_value: &str) -> MethodBatchGetAssetsHistoryCall<'a, C, A> {
self._read_time_window_end_time = Some(new_value.to_string());
self
}
pub fn content_type(mut self, new_value: &str) -> MethodBatchGetAssetsHistoryCall<'a, C, A> {
self._content_type = Some(new_value.to_string());
self
}
pub fn add_asset_names(mut self, new_value: &str) -> MethodBatchGetAssetsHistoryCall<'a, C, A> {
self._asset_names.push(new_value.to_string());
self
}
pub fn delegate(mut self, new_value: &'a mut Delegate) -> MethodBatchGetAssetsHistoryCall<'a, C, A> {
self._delegate = Some(new_value);
self
}
pub fn param<T>(mut self, name: T, value: T) -> MethodBatchGetAssetsHistoryCall<'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) -> MethodBatchGetAssetsHistoryCall<'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
}
}
pub struct MethodExportAssetCall<'a, C, A>
where C: 'a, A: 'a {
hub: &'a CloudAsset<C, A>,
_request: ExportAssetsRequest,
_parent: String,
_delegate: Option<&'a mut Delegate>,
_additional_params: HashMap<String, String>,
_scopes: BTreeMap<String, ()>
}
impl<'a, C, A> CallBuilder for MethodExportAssetCall<'a, C, A> {}
impl<'a, C, A> MethodExportAssetCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oauth2::GetToken {
pub fn doit(mut self) -> Result<(hyper::client::Response, Operation)> {
use url::percent_encoding::{percent_encode, DEFAULT_ENCODE_SET};
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: "cloudasset.exportAssets",
http_method: hyper::method::Method::Post });
let mut params: Vec<(&str, String)> = Vec::with_capacity(4 + self._additional_params.len());
params.push(("parent", self._parent.to_string()));
for &field in ["alt", "parent"].iter() {
if self._additional_params.contains_key(field) {
dlg.finished(false);
return Err(Error::FieldClash(field));
}
}
for (name, value) in self._additional_params.iter() {
params.push((&name, value.clone()));
}
params.push(("alt", "json".to_string()));
let mut url = self.hub._base_url.clone() + "v1/{+parent}:exportAssets";
if self._scopes.len() == 0 {
self._scopes.insert(Scope::CloudPlatform.as_ref().to_string(), ());
}
for &(find_this, param_name) in [("{+parent}", "parent")].iter() {
let mut replace_with = String::new();
for &(name, ref value) in params.iter() {
if name == param_name {
replace_with = value.to_string();
break;
}
}
if find_this.as_bytes()[1] == '+' as u8 {
replace_with = percent_encode(replace_with.as_bytes(), DEFAULT_ENCODE_SET).to_string();
}
url = url.replace(find_this, &replace_with);
}
{
let mut indices_for_removal: Vec<usize> = Vec::with_capacity(1);
for param_name in ["parent"].iter() {
if let Some(index) = params.iter().position(|t| &t.0 == param_name) {
indices_for_removal.push(index);
}
}
for &index in indices_for_removal.iter() {
params.remove(index);
}
}
let url = hyper::Url::parse_with_params(&url, params).unwrap();
let mut json_mime_type = mime::Mime(mime::TopLevel::Application, mime::SubLevel::Json, Default::default());
let mut request_value_reader =
{
let mut value = json::value::to_value(&self._request).expect("serde to work");
remove_json_null_values(&mut value);
let mut dst = io::Cursor::new(Vec::with_capacity(128));
json::to_writer(&mut dst, &value).unwrap();
dst
};
let request_size = request_value_reader.seek(io::SeekFrom::End(0)).unwrap();
request_value_reader.seek(io::SeekFrom::Start(0)).unwrap();
loop {
let token = match self.hub.auth.borrow_mut().token(self._scopes.keys()) {
Ok(token) => token,
Err(err) => {
match dlg.token(&*err) {
Some(token) => token,
None => {
dlg.finished(false);
return Err(Error::MissingToken(err))
}
}
}
};
let auth_header = Authorization(Bearer { token: token.access_token });
request_value_reader.seek(io::SeekFrom::Start(0)).unwrap();
let mut req_result = {
let mut client = &mut *self.hub.client.borrow_mut();
let mut req = client.borrow_mut().request(hyper::method::Method::Post, url.clone())
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone())
.header(ContentType(json_mime_type.clone()))
.header(ContentLength(request_size as u64))
.body(&mut request_value_reader);
dlg.pre_request();
req.send()
};
match req_result {
Err(err) => {
if let oauth2::Retry::After(d) = dlg.http_error(&err) {
sleep(d);
continue;
}
dlg.finished(false);
return Err(Error::HttpError(err))
}
Ok(mut res) => {
if !res.status.is_success() {
let mut json_err = String::new();
res.read_to_string(&mut json_err).unwrap();
if let oauth2::Retry::After(d) = dlg.http_failure(&res,
json::from_str(&json_err).ok(),
json::from_str(&json_err).ok()) {
sleep(d);
continue;
}
dlg.finished(false);
return match json::from_str::<ErrorResponse>(&json_err){
Err(_) => Err(Error::Failure(res)),
Ok(serr) => Err(Error::BadRequest(serr))
}
}
let result_value = {
let mut json_response = String::new();
res.read_to_string(&mut json_response).unwrap();
match json::from_str(&json_response) {
Ok(decoded) => (res, decoded),
Err(err) => {
dlg.response_json_decode_error(&json_response, &err);
return Err(Error::JsonDecodeError(json_response, err));
}
}
};
dlg.finished(true);
return Ok(result_value)
}
}
}
}
pub fn request(mut self, new_value: ExportAssetsRequest) -> MethodExportAssetCall<'a, C, A> {
self._request = new_value;
self
}
pub fn parent(mut self, new_value: &str) -> MethodExportAssetCall<'a, C, A> {
self._parent = new_value.to_string();
self
}
pub fn delegate(mut self, new_value: &'a mut Delegate) -> MethodExportAssetCall<'a, C, A> {
self._delegate = Some(new_value);
self
}
pub fn param<T>(mut self, name: T, value: T) -> MethodExportAssetCall<'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) -> MethodExportAssetCall<'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
}
}