use std::collections::HashMap;
use std::cell::RefCell;
use std::default::Default;
use std::collections::BTreeSet;
use std::error::Error as StdError;
use serde_json as json;
use std::io;
use std::fs;
use std::mem;
use hyper::client::connect;
use tokio::io::{AsyncRead, AsyncWrite};
use tokio::time::sleep;
use tower_service;
use serde::{Serialize, Deserialize};
use crate::{client, client::GetToken, client::serde_with};
#[derive(Clone)]
pub struct Webfonts<S> {
pub client: hyper::Client<S, hyper::body::Body>,
pub auth: Box<dyn client::GetToken>,
_user_agent: String,
_base_url: String,
_root_url: String,
}
impl<'a, S> client::Hub for Webfonts<S> {}
impl<'a, S> Webfonts<S> {
pub fn new<A: 'static + client::GetToken>(client: hyper::Client<S, hyper::body::Body>, auth: A) -> Webfonts<S> {
Webfonts {
client,
auth: Box::new(auth),
_user_agent: "google-api-rust-client/5.0.3".to_string(),
_base_url: "https://webfonts.googleapis.com/".to_string(),
_root_url: "https://webfonts.googleapis.com/".to_string(),
}
}
pub fn webfonts(&'a self) -> WebfontMethods<'a, S> {
WebfontMethods { 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)
}
}
#[serde_with::serde_as(crate = "::client::serde_with")]
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct Webfont {
pub category: Option<String>,
pub family: Option<String>,
pub files: Option<HashMap<String, String>>,
pub kind: Option<String>,
#[serde(rename="lastModified")]
pub last_modified: Option<String>,
pub subsets: Option<Vec<String>>,
pub variants: Option<Vec<String>>,
pub version: Option<String>,
}
impl client::Resource for Webfont {}
#[serde_with::serde_as(crate = "::client::serde_with")]
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct WebfontList {
pub items: Option<Vec<Webfont>>,
pub kind: Option<String>,
}
impl client::ResponseResult for WebfontList {}
pub struct WebfontMethods<'a, S>
where S: 'a {
hub: &'a Webfonts<S>,
}
impl<'a, S> client::MethodsBuilder for WebfontMethods<'a, S> {}
impl<'a, S> WebfontMethods<'a, S> {
pub fn list(&self) -> WebfontListCall<'a, S> {
WebfontListCall {
hub: self.hub,
_sort: Default::default(),
_delegate: Default::default(),
_additional_params: Default::default(),
}
}
}
pub struct WebfontListCall<'a, S>
where S: 'a {
hub: &'a Webfonts<S>,
_sort: Option<String>,
_delegate: Option<&'a mut dyn client::Delegate>,
_additional_params: HashMap<String, String>,
}
impl<'a, S> client::CallBuilder for WebfontListCall<'a, S> {}
impl<'a, S> WebfontListCall<'a, S>
where
S: tower_service::Service<http::Uri> + Clone + Send + Sync + 'static,
S::Response: hyper::client::connect::Connection + AsyncRead + AsyncWrite + Send + Unpin + 'static,
S::Future: Send + Unpin + 'static,
S::Error: Into<Box<dyn StdError + Send + Sync>>,
{
pub async fn doit(mut self) -> client::Result<(hyper::Response<hyper::body::Body>, WebfontList)> {
use std::io::{Read, Seek};
use hyper::header::{CONTENT_TYPE, CONTENT_LENGTH, AUTHORIZATION, USER_AGENT, LOCATION};
use client::{ToParts, url::Params};
use std::borrow::Cow;
let mut dd = client::DefaultDelegate;
let mut dlg: &mut dyn client::Delegate = self._delegate.unwrap_or(&mut dd);
dlg.begin(client::MethodInfo { id: "webfonts.webfonts.list",
http_method: hyper::Method::GET });
for &field in ["alt", "sort"].iter() {
if self._additional_params.contains_key(field) {
dlg.finished(false);
return Err(client::Error::FieldClash(field));
}
}
let mut params = Params::with_capacity(3 + self._additional_params.len());
if let Some(value) = self._sort.as_ref() {
params.push("sort", value);
}
params.extend(self._additional_params.iter());
params.push("alt", "json");
let mut url = self.hub._base_url.clone() + "v1/webfonts";
match dlg.api_key() {
Some(value) => params.push("key", value),
None => {
dlg.finished(false);
return Err(client::Error::MissingAPIKey)
}
}
let url = params.parse_with_url(&url);
loop {
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());
let request = req_builder
.body(hyper::body::Body::empty());
client.request(request.unwrap()).await
};
match req_result {
Err(err) => {
if let client::Retry::After(d) = dlg.http_error(&err) {
sleep(d).await;
continue;
}
dlg.finished(false);
return Err(client::Error::HttpError(err))
}
Ok(mut res) => {
if !res.status().is_success() {
let res_body_string = client::get_body_as_string(res.body_mut()).await;
let (parts, _) = res.into_parts();
let body = hyper::Body::from(res_body_string.clone());
let restored_response = hyper::Response::from_parts(parts, body);
let server_response = json::from_str::<serde_json::Value>(&res_body_string).ok();
if let client::Retry::After(d) = dlg.http_failure(&restored_response, server_response.clone()) {
sleep(d).await;
continue;
}
dlg.finished(false);
return match server_response {
Some(error_value) => Err(client::Error::BadRequest(error_value)),
None => Err(client::Error::Failure(restored_response)),
}
}
let result_value = {
let res_body_string = client::get_body_as_string(res.body_mut()).await;
match json::from_str(&res_body_string) {
Ok(decoded) => (res, decoded),
Err(err) => {
dlg.response_json_decode_error(&res_body_string, &err);
return Err(client::Error::JsonDecodeError(res_body_string, err));
}
}
};
dlg.finished(true);
return Ok(result_value)
}
}
}
}
pub fn sort(mut self, new_value: &str) -> WebfontListCall<'a, S> {
self._sort = Some(new_value.to_string());
self
}
pub fn delegate(mut self, new_value: &'a mut dyn client::Delegate) -> WebfontListCall<'a, S> {
self._delegate = Some(new_value);
self
}
pub fn param<T>(mut self, name: T, value: T) -> WebfontListCall<'a, S>
where T: AsRef<str> {
self._additional_params.insert(name.as_ref().to_string(), value.as_ref().to_string());
self
}
}