fix(cmn) re-export important types from cmn

That way, 'cmn' becomes our private module. All URLs were updated
to reflect that.

This commit also contains an early implementation of the
'transfer_status' method, which will require plenty of work.
This commit is contained in:
Sebastian Thiel
2015-03-22 09:26:49 +01:00
parent ffef7dda57
commit f73204c6b9
6 changed files with 38 additions and 22 deletions

View File

@@ -52,7 +52,7 @@ use std::io;
use std::fs;
use std::thread::sleep;
pub use cmn::{MultiPartReader, ToParts, MethodInfo, Result, CallBuilder, Hub, ReadSeek, Part, ResponseResult, RequestValue, NestedType, Delegate, DefaultDelegate};
pub use cmn::{MultiPartReader, ToParts, MethodInfo, Result, CallBuilder, Hub, ReadSeek, Part, ResponseResult, RequestValue, NestedType, Delegate, DefaultDelegate, ResourceMethodsBuilder, Resource};
// ##############

View File

@@ -23,11 +23,11 @@
# fr == fattest resource, the fatter, the more important, right ?
fr = find_fattest_resource(c)
hub_url = 'struct.' + hub_type(c.schemas, util.canonical_name()) + '.html'
method_builder_url = 'cmn/trait.' + CALL_BUILDER_MARKERT_TRAIT + '.html'
delegate_url = 'cmn/trait.Delegate.html'
request_trait_url = 'cmn/trait.' + REQUEST_MARKER_TRAIT + '.html'
response_trait_url = 'cmn/trait.' + RESPONSE_MARKER_TRAIT + '.html'
part_trait_url = 'cmn/trait.' + PART_MARKER_TRAIT + '.html'
method_builder_url = 'trait.' + CALL_BUILDER_MARKERT_TRAIT + '.html'
delegate_url = 'trait.Delegate.html'
request_trait_url = 'trait.' + REQUEST_MARKER_TRAIT + '.html'
response_trait_url = 'trait.' + RESPONSE_MARKER_TRAIT + '.html'
part_trait_url = 'trait.' + PART_MARKER_TRAIT + '.html'
doc_base_url = cargo.doc_base_url + '/' + util.crate_name() + '/'
@@ -131,7 +131,7 @@ The API is structured into the following primary items:
* **${link('Hub', hub_url)}**
* a central object to maintain state and allow accessing all *Activities*
* **${link('Resources', 'cmn/trait.' + RESOURCE_MARKER_TRAIT + '.html')}**
* **${link('Resources', 'trait.' + RESOURCE_MARKER_TRAIT + '.html')}**
* primary types that you can apply *Activities* to
* a collection of properties and *Parts*
* **${link('Parts', part_trait_url)}**
@@ -179,7 +179,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/enum.Result.html')} enumeration as return value of
All errors produced by the system are provided either as ${link('Result', 'enum.Result.html')} 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)}.
@@ -187,9 +187,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.
${'##'} About Uploads and Downlods
If a method supports downloads, the response body, which is part of the ${link('Result', 'cmn/enum.Result.html')}, should be
If a method supports downloads, the response body, which is part of the ${link('Result', 'enum.Result.html')}, should be
read by you to obtain the media.
If such a method also supports a ${link('Response Result', 'cmn/trait.ResponseResult.html')}, it will return that by default.
If such a method also supports a ${link('Response Result', 'trait.ResponseResult.html')}, 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}`.

View File

@@ -359,11 +359,11 @@ ${'.' + action_name | indent_by(13)}(${action_args});
match result {
Result::HttpError(err) => println!("HTTPERROR: {:?}", err),
Result::MissingAPIKey => println!("Missing API Key"),
Result::MissingToken => println!("Missing Token"),
Result::Failure(_) => println!("General Failure (Response doesn't print)"),
Result::FieldClash(clashed_field) => println!("FIELD CLASH: {:?}", clashed_field),
Result::JsonDecodeError(err) => println!("Json failed to decode: {:?}", err),
Result::MissingAPIKey => println!("Auth: Missing API Key - used if there are no scopes"),
Result::MissingToken => println!("OAuth2: Missing Token"),
Result::Failure(_) => println!("General Failure (hyper::client::Response doesn't print)"),
Result::FieldClash(clashed_field) => println!("You added custom parameter which is part of builder: {:?}", clashed_field),
Result::JsonDecodeError(err) => println!("Couldn't understand server reply - maybe API needs update: {:?}", err),
Result::Success(_) => println!("Success (value doesn't print)"),
}
% endif
@@ -667,7 +667,7 @@ else {
${delegate_finish}(false);
return Result::MissingToken
}
let auth_header = Authorization(token.unwrap().access_token);
let auth_header = Authorization("Bearer ".to_string() + &token.unwrap().access_token);
% endif
% if request_value:
request_value_reader.seek(io::SeekFrom::Start(0)).unwrap();
@@ -708,7 +708,7 @@ else {
.header(UserAgent(self.hub._user_agent.clone()))\
% if supports_scopes(auth):
.header(auth_header)\
.header(auth_header.clone())\
% endif
% if request_value:
% if not simple_media_param:
@@ -781,6 +781,8 @@ else {
client: &mut client.borrow_mut(),
delegate: dlg,
auth: &mut *self.hub.auth.borrow_mut(),
user_agent: &self.hub._user_agent,
auth_token: auth_header.0.clone(),
url: url,
reader: &mut reader,
media_type: reader_mime_type.clone(),

View File

@@ -48,7 +48,7 @@ pub struct ${ThisType}
hub: &'a ${hub_type_name}${hub_type_params_s()},
}
impl${rb_params} cmn::ResourceMethodsBuilder for ${ThisType} {}
impl${rb_params} ResourceMethodsBuilder for ${ThisType} {}
## Builder Creators Methods ####################
impl${rb_params} ${ThisType} {

View File

@@ -35,8 +35,6 @@ RESERVED_WORDS = set(('abstract', 'alignof', 'as', 'become', 'box', 'break', 'co
'return', 'sizeof', 'static', 'self', 'struct', 'super', 'true', 'trait', 'type', 'typeof',
'unsafe', 'unsized', 'use', 'virtual', 'where', 'while', 'yield'))
RESERVED_TYPES = set(("Result", ))
_words = [w.strip(',') for w in "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.".split(' ')]
RUST_TYPE_RND_MAP = {'bool': lambda: str(bool(randint(0, 1))).lower(),
'u32' : lambda: randint(0, 100),
@@ -74,6 +72,8 @@ DELEGATE_PROPERTY_NAME = 'delegate'
TO_PARTS_MARKER = 'ToParts'
UNUSED_TYPE_MARKER = 'UnusedType'
RESERVED_TYPES = set(("Result", RESOURCE_MARKER_TRAIT))
PROTOCOL_TYPE_INFO = {
'simple' : {
'arg_name': 'stream',
@@ -403,7 +403,7 @@ def schema_markers(s, c, transitive=True):
for fqan, iot in activities.iteritems():
_, resource, _ = activity_split(fqan)
if resource and activity_name_to_type_name(resource).lower() == sid.lower():
res.add('cmn::%s' % RESOURCE_MARKER_TRAIT)
res.add(RESOURCE_MARKER_TRAIT)
m = c.fqan_map[to_fqan(*activity_split(fqan))]
params, _ = build_all_params(c, m)
part_prop, _ = parts_from_params(params)

View File

@@ -5,7 +5,7 @@ use std;
use mime::{Mime, TopLevel, SubLevel, Attr, Value};
use oauth2;
use hyper;
use hyper::header::{ContentType, ContentLength, Headers};
use hyper::header::{ContentType, ContentLength, Headers, UserAgent, Authorization};
use hyper::http::LINE_ENDING;
use hyper::method::Method;
@@ -361,6 +361,8 @@ pub struct ResumableUploadHelper<'a, NC: 'a, A: 'a> {
pub client: &'a mut hyper::client::Client<NC>,
pub delegate: &'a mut Delegate,
pub auth: &'a mut A,
pub user_agent: &'a str,
pub auth_token: String,
pub url: &'a str,
pub reader: &'a mut ReadSeek,
pub media_type: Mime,
@@ -370,7 +372,19 @@ pub struct ResumableUploadHelper<'a, NC: 'a, A: 'a> {
impl<'a, NC, A> ResumableUploadHelper<'a, NC, A>
where NC: hyper::net::NetworkConnector,
A: oauth2::GetToken {
fn query_transfer_status(&'a mut self) -> (u64, hyper::HttpResult<hyper::client::Response>) {
self.client.post(self.url)
.header(UserAgent(self.user_agent.to_string()))
.header(Authorization("Bearer ".to_string() + &self.auth_token));
(0, Err(hyper::error::HttpError::HttpStatusError))
}
pub fn upload(&'a mut self) -> hyper::HttpResult<hyper::client::Response> {
let (start, result) = self.query_transfer_status();
if let Err(_) = result {
return result
}
Err(hyper::error::HttpError::HttpStatusError)
}
}