mirror of
https://github.com/OMGeeky/google-apis-rs.git
synced 2026-02-23 15:49:49 +01:00
rename cmn to client
Signed-off-by: Petros Angelatos <petrosagg@gmail.com>
This commit is contained in:
@@ -27,7 +27,7 @@ use std::mem;
|
||||
use std::thread::sleep;
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::cmn;
|
||||
use crate::client;
|
||||
|
||||
// ##############
|
||||
// UTILITIES ###
|
||||
@@ -57,7 +57,7 @@ pub struct ${hub_type}${ht_params} {
|
||||
_root_url: String,
|
||||
}
|
||||
|
||||
impl<'a, ${', '.join(HUB_TYPE_PARAMETERS)}> cmn::Hub for ${hub_type}${ht_params} {}
|
||||
impl<'a, ${', '.join(HUB_TYPE_PARAMETERS)}> client::Hub for ${hub_type}${ht_params} {}
|
||||
|
||||
impl<'a, ${', '.join(HUB_TYPE_PARAMETERS)}> ${hub_type}${ht_params}
|
||||
where ${', '.join(hub_type_bounds())} {
|
||||
|
||||
@@ -51,8 +51,8 @@ extern crate mime;
|
||||
extern crate url;
|
||||
|
||||
pub mod api;
|
||||
pub mod cmn;
|
||||
pub mod client;
|
||||
|
||||
// Re-export the hub type and some basic client structs
|
||||
pub use api::${hub_type};
|
||||
pub use cmn::{Result, Error, Delegate};
|
||||
pub use client::{Result, Error, Delegate};
|
||||
|
||||
@@ -192,7 +192,7 @@ ${self.hub_usage_example(c, rust_doc, fr=fr)}\
|
||||
|
||||
${'##'} Handling Errors
|
||||
|
||||
All errors produced by the system are provided either as ${link('Result', 'cmn::Result')} enumeration as return value of
|
||||
All errors produced by the system are provided either as ${link('Result', 'client::Result')} enumeration as return value of
|
||||
the ${api.terms.action}() methods, or handed as possibly intermediate results to either the
|
||||
${link('Hub Delegate', delegate_url)}, or the ${link('Authenticator Delegate', urls.authenticator_delegate)}.
|
||||
|
||||
@@ -200,9 +200,9 @@ When delegates handle errors or intermediate values, they may have a chance to i
|
||||
makes the system potentially resilient to all kinds of errors.
|
||||
|
||||
${'##'} Uploads and Downloads
|
||||
If a method supports downloads, the response body, which is part of the ${link('Result', 'cmn::Result')}, should be
|
||||
If a method supports downloads, the response body, which is part of the ${link('Result', 'client::Result')}, should be
|
||||
read by you to obtain the media.
|
||||
If such a method also supports a ${link('Response Result', 'cmn::ResponseResult')}, it will return that by default.
|
||||
If such a method also supports a ${link('Response Result', 'client::ResponseResult')}, 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: `${ADD_PARAM_MEDIA_EXAMPLE}`.
|
||||
|
||||
|
||||
@@ -412,7 +412,7 @@ match result {
|
||||
where = ''
|
||||
qualifier = 'pub '
|
||||
add_args = ''
|
||||
rtype = 'cmn::Result<hyper::client::Response>'
|
||||
rtype = 'client::Result<hyper::client::Response>'
|
||||
response_schema = method_response(c, m)
|
||||
|
||||
supports_download = m.get('supportsMediaDownload', False);
|
||||
@@ -420,7 +420,7 @@ match result {
|
||||
if response_schema:
|
||||
if not supports_download:
|
||||
reserved_params = ['alt']
|
||||
rtype = 'cmn::Result<(hyper::client::Response, %s)>' % (response_schema.id)
|
||||
rtype = 'client::Result<(hyper::client::Response, %s)>' % (response_schema.id)
|
||||
|
||||
mtype_param = 'RS'
|
||||
|
||||
@@ -430,7 +430,7 @@ match result {
|
||||
if media_params:
|
||||
type_params = '<%s>' % mtype_param
|
||||
qualifier = ''
|
||||
where = '\n\t\twhere ' + mtype_param + ': cmn::ReadSeek'
|
||||
where = '\n\t\twhere ' + mtype_param + ': client::ReadSeek'
|
||||
add_args = (', mut reader: %s, reader_mime_type: mime::Mime' % mtype_param) + ", protocol: &'static str"
|
||||
for p in media_params:
|
||||
if p.protocol == 'simple':
|
||||
@@ -465,7 +465,7 @@ match result {
|
||||
if media_params:
|
||||
max_size = media_params[0].max_size
|
||||
if max_size > 0:
|
||||
READER_SEEK += "if size > %i {\n\treturn Err(cmn::Error::UploadSizeLimitExceeded(size, %i))\n}" % (max_size, max_size)
|
||||
READER_SEEK += "if size > %i {\n\treturn Err(client::Error::UploadSizeLimitExceeded(size, %i))\n}" % (max_size, max_size)
|
||||
|
||||
special_cases = set()
|
||||
for possible_url in possible_urls:
|
||||
@@ -505,13 +505,13 @@ match result {
|
||||
% endif
|
||||
use std::io::{Read, Seek};
|
||||
use hyper::header::{ContentType, ContentLength, Authorization, Bearer, UserAgent, Location};
|
||||
use cmn::ToParts;
|
||||
let mut dd = cmn::DefaultDelegate;
|
||||
let mut dlg: &mut dyn cmn::Delegate = match ${delegate} {
|
||||
use client::ToParts;
|
||||
let mut dd = client::DefaultDelegate;
|
||||
let mut dlg: &mut dyn client::Delegate = match ${delegate} {
|
||||
Some(d) => d,
|
||||
None => &mut dd
|
||||
};
|
||||
dlg.begin(cmn::MethodInfo { id: "${m.id}",
|
||||
dlg.begin(client::MethodInfo { id: "${m.id}",
|
||||
http_method: ${method_name_to_variant(m.httpMethod)} });
|
||||
let mut params: Vec<(&str, String)> = Vec::with_capacity(${len(params) + len(reserved_params)} + ${paddfields}.len());
|
||||
<%
|
||||
@@ -558,7 +558,7 @@ match result {
|
||||
for &field in [${', '.join(enclose_in('"', reserved_params + [p.name for p in field_params]))}].iter() {
|
||||
if ${paddfields}.contains_key(field) {
|
||||
${delegate_finish}(false);
|
||||
return Err(cmn::Error::FieldClash(field));
|
||||
return Err(client::Error::FieldClash(field));
|
||||
}
|
||||
}
|
||||
for (name, value) in ${paddfields}.iter() {
|
||||
@@ -621,7 +621,7 @@ else {
|
||||
Some(value) => params.push(("key", value)),
|
||||
None => {
|
||||
${delegate_finish}(false);
|
||||
return Err(cmn::Error::MissingAPIKey)
|
||||
return Err(client::Error::MissingAPIKey)
|
||||
}
|
||||
}
|
||||
% endif
|
||||
@@ -679,7 +679,7 @@ else {
|
||||
let mut request_value_reader =
|
||||
{
|
||||
let mut value = json::value::to_value(&self.${property(REQUEST_VALUE_PROPERTY_NAME)}).expect("serde to work");
|
||||
cmn::remove_json_null_values(&mut value);
|
||||
client::remove_json_null_values(&mut value);
|
||||
let mut dst = io::Cursor::new(Vec::with_capacity(128));
|
||||
json::to_writer(&mut dst, &value).unwrap();
|
||||
dst
|
||||
@@ -703,7 +703,7 @@ else {
|
||||
Some(token) => token,
|
||||
None => {
|
||||
${delegate_finish}(false);
|
||||
return Err(cmn::Error::MissingToken(err))
|
||||
return Err(client::Error::MissingToken(err))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -719,7 +719,7 @@ else {
|
||||
should_ask_dlg_for_url = false;
|
||||
upload_url_from_server = false;
|
||||
let url = upload_url.as_ref().and_then(|s| Some(hyper::Url::parse(s).unwrap())).unwrap();
|
||||
hyper::client::Response::new(url, Box::new(cmn::DummyNetworkStream)).and_then(|mut res| {
|
||||
hyper::client::Response::new(url, Box::new(client::DummyNetworkStream)).and_then(|mut res| {
|
||||
res.status = hyper::status::StatusCode::Ok;
|
||||
res.headers.set(Location(upload_url.as_ref().unwrap().clone()));
|
||||
Ok(res)
|
||||
@@ -728,7 +728,7 @@ else {
|
||||
% endif
|
||||
<%block filter="indent_by(resumable_media_param and 4 or 0)">\
|
||||
% if request_value and simple_media_param:
|
||||
let mut mp_reader: cmn::MultiPartReader = Default::default();
|
||||
let mut mp_reader: client::MultiPartReader = Default::default();
|
||||
let (mut body_reader, content_type) = match protocol {
|
||||
"${simple_media_param.protocol}" => {
|
||||
mp_reader.reserve_exact(2);
|
||||
@@ -772,7 +772,7 @@ else {
|
||||
% if resumable_media_param:
|
||||
upload_url_from_server = true;
|
||||
if protocol == "${resumable_media_param.protocol}" {
|
||||
req = req.header(cmn::XUploadContentType(reader_mime_type.clone()));
|
||||
req = req.header(client::XUploadContentType(reader_mime_type.clone()));
|
||||
}
|
||||
% endif
|
||||
|
||||
@@ -791,16 +791,16 @@ else {
|
||||
continue;
|
||||
}
|
||||
${delegate_finish}(false);
|
||||
return Err(cmn::Error::HttpError(err))
|
||||
return Err(client::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();
|
||||
|
||||
let json_server_error = json::from_str::<cmn::JsonServerError>(&json_err).ok();
|
||||
let server_error = json::from_str::<cmn::ServerError>(&json_err)
|
||||
.or_else(|_| json::from_str::<cmn::ErrorResponse>(&json_err).map(|r| r.error))
|
||||
let json_server_error = json::from_str::<client::JsonServerError>(&json_err).ok();
|
||||
let server_error = json::from_str::<client::ServerError>(&json_err)
|
||||
.or_else(|_| json::from_str::<client::ErrorResponse>(&json_err).map(|r| r.error))
|
||||
.ok();
|
||||
|
||||
if let oauth2::Retry::After(d) = dlg.http_failure(&res,
|
||||
@@ -810,9 +810,9 @@ else {
|
||||
continue;
|
||||
}
|
||||
${delegate_finish}(false);
|
||||
return match json::from_str::<cmn::ErrorResponse>(&json_err){
|
||||
Err(_) => Err(cmn::Error::Failure(res)),
|
||||
Ok(serr) => Err(cmn::Error::BadRequest(serr))
|
||||
return match json::from_str::<client::ErrorResponse>(&json_err){
|
||||
Err(_) => Err(client::Error::Failure(res)),
|
||||
Ok(serr) => Err(client::Error::BadRequest(serr))
|
||||
}
|
||||
}
|
||||
% if resumable_media_param:
|
||||
@@ -825,7 +825,7 @@ else {
|
||||
dlg.store_upload_url(Some(url_str));
|
||||
}
|
||||
|
||||
cmn::ResumableUploadHelper {
|
||||
client::ResumableUploadHelper {
|
||||
client: &mut client.borrow_mut(),
|
||||
delegate: dlg,
|
||||
start_at: if upload_url_from_server { Some(0) } else { None },
|
||||
@@ -841,12 +841,12 @@ else {
|
||||
match upload_result {
|
||||
None => {
|
||||
${delegate_finish}(false);
|
||||
return Err(cmn::Error::Cancelled)
|
||||
return Err(client::Error::Cancelled)
|
||||
}
|
||||
Some(Err(err)) => {
|
||||
## Do not ask the delgate again, as it was asked by the helper !
|
||||
${delegate_finish}(false);
|
||||
return Err(cmn::Error::HttpError(err))
|
||||
return Err(client::Error::HttpError(err))
|
||||
}
|
||||
## Now the result contains the actual resource, if any ... it will be
|
||||
## decoded next
|
||||
@@ -856,7 +856,7 @@ else {
|
||||
## delegate was called in upload() already - don't tell him again
|
||||
dlg.store_upload_url(None);
|
||||
${delegate_finish}(false);
|
||||
return Err(cmn::Error::Failure(res))
|
||||
return Err(client::Error::Failure(res))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -875,7 +875,7 @@ if enable_resource_parsing \
|
||||
Ok(decoded) => (res, decoded),
|
||||
Err(err) => {
|
||||
dlg.response_json_decode_error(&json_response, &err);
|
||||
return Err(cmn::Error::JsonDecodeError(json_response, err));
|
||||
return Err(client::Error::JsonDecodeError(json_response, err));
|
||||
}
|
||||
}
|
||||
}\
|
||||
@@ -901,7 +901,7 @@ if enable_resource_parsing \
|
||||
/// * *${split_camelcase_s(item_name)}*: ${isinstance(item, (list, tuple)) and put_and(enclose_in("'", item)) or str(item)}
|
||||
% endfor
|
||||
pub fn ${upload_action_fn(api.terms.upload_action, p.type.suffix)}<${mtype_param}>(self, ${p.type.arg_name}: ${mtype_param}, mime_type: mime::Mime) -> ${rtype}
|
||||
where ${mtype_param}: cmn::ReadSeek {
|
||||
where ${mtype_param}: client::ReadSeek {
|
||||
self.${api.terms.action}(${p.type.arg_name}, mime_type, "${p.protocol}")
|
||||
}
|
||||
% endfor
|
||||
|
||||
@@ -95,7 +95,7 @@ impl${rb_params} ${ThisType} {
|
||||
% endfor
|
||||
% endif
|
||||
pub fn ${mangle_ident(a)}${type_params}(&self${method_args}) -> ${RType}${mb_tparams} {
|
||||
use cmn::ToParts;
|
||||
use client::ToParts;
|
||||
% if part_prop and request_value:
|
||||
let parts = ${mangle_ident(REQUEST_VALUE_PROPERTY_NAME)}.to_parts();
|
||||
% endif
|
||||
|
||||
Reference in New Issue
Block a user