feat(make): cli depends on API, generically

This allows us to build efficiently. CLI programs can now have their
own cmn.rs implementation, which we can test standalone with
`cargo test`.

The primary makefile currently just explicitly pulls in the type-*.yaml,
one day we could possibly put it into a loop.

Fixes #11
This commit is contained in:
Sebastian Thiel
2015-03-24 12:55:24 +01:00
parent caaf62e51d
commit cefd606b53
37 changed files with 3014 additions and 2483 deletions

View File

@@ -1,5 +1,5 @@
// DO NOT EDIT !
// This file was generated automatically from 'src/mako/lib.rs.mako'
// This file was generated automatically from 'src/mako/api/lib.rs.mako'
// DO NOT EDIT !
//! This documentation was generated from *Groups Migration* crate version *0.1.1+20140416*, where *20140416* is the exact revision of the *groupsmigration:v1* schema built by the [mako](http://www.makotemplates.org/) code generator *v0.1.1*.
@@ -29,6 +29,8 @@
//!
//! * **[Hub](struct.GroupsMigration.html)**
//! * a central object to maintain state and allow accessing all *Activities*
//! * creates [*Method Builders*](trait.MethodsBuilder.html) which in turn
//! allow access to individual [*Call Builders*](trait.CallBuilder.html)
//! * **[Resources](trait.Resource.html)**
//! * primary types that you can apply *Activities* to
//! * a collection of properties and *Parts*
@@ -38,6 +40,8 @@
//! * **[Activities](trait.CallBuilder.html)**
//! * operations to apply to *Resources*
//!
//! All *structures* are marked with applicable traits to further categorize them and ease browsing.
//!
//! Generally speaking, you can invoke *Activities* like this:
//!
//! ```Rust,ignore
@@ -72,7 +76,7 @@
//! extern crate hyper;
//! extern crate "yup-oauth2" as oauth2;
//! extern crate "google-groupsmigration1" as groupsmigration1;
//! use groupsmigration1::Result;
//! use groupsmigration1::{Result, Error};
//! use std::fs;
//! # #[test] fn egal() {
//! use std::default::Default;
@@ -98,15 +102,17 @@
//! .upload(fs::File::open("file.ext").unwrap(), "application/octet-stream".parse().unwrap());
//!
//! match result {
//! Result::HttpError(err) => println!("HTTPERROR: {:?}", err),
//! Result::MissingAPIKey => println!("Auth: Missing API Key - used if there are no scopes"),
//! Result::MissingToken => println!("OAuth2: Missing Token"),
//! Result::Cancelled => println!("Operation cancelled by user"),
//! Result::UploadSizeLimitExceeded(size, max_size) => println!("Upload size too big: {} of {}", size, max_size),
//! 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)"),
//! Err(e) => match e {
//! Error::HttpError(err) => println!("HTTPERROR: {:?}", err),
//! Error::MissingAPIKey => println!("Auth: Missing API Key - used if there are no scopes"),
//! Error::MissingToken => println!("OAuth2: Missing Token"),
//! Error::Cancelled => println!("Operation canceled by user"),
//! Error::UploadSizeLimitExceeded(size, max_size) => println!("Upload size too big: {} of {}", size, max_size),
//! Error::Failure(_) => println!("General Failure (hyper::client::Response doesn't print)"),
//! Error::FieldClash(clashed_field) => println!("You added custom parameter which is part of builder: {:?}", clashed_field),
//! Error::JsonDecodeError(err) => println!("Couldn't understand server reply - maybe API needs update: {:?}", err),
//! },
//! Ok(_) => println!("Success (value doesn't print)"),
//! }
//! # }
//! ```
@@ -119,7 +125,7 @@
//! When delegates handle errors or intermediate values, they may have a chance to instruct the system to retry. This
//! makes the system potentially resilient to all kinds of errors.
//!
//! ## Uploads and Downlods
//! ## Uploads and Downloads
//! If a method supports downloads, the response body, which is part of the [Result](enum.Result.html), should be
//! read by you to obtain the media.
//! If such a method also supports a [Response Result](trait.ResponseResult.html), it will return that by default.
@@ -142,8 +148,9 @@
//! ## Optional Parts in Server-Requests
//!
//! All structures provided by this library are made to be [enocodable](trait.RequestValue.html) and
//! [decodable](trait.ResponseResult.html) via json. Optionals are used to indicate that partial requests are responses are valid.
//! Most optionals are are considered [Parts](trait.Part.html) which are identifyable by name, which will be sent to
//! [decodable](trait.ResponseResult.html) via *json*. Optionals are used to indicate that partial requests are responses
//! are valid.
//! Most optionals are are considered [Parts](trait.Part.html) which are identifiable by name, which will be sent to
//! the server to indicate either the set parts of the request or the desired parts in the response.
//!
//! ## Builder Arguments
@@ -192,7 +199,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, ResourceMethodsBuilder, Resource, JsonServerError};
pub use cmn::{MultiPartReader, ToParts, MethodInfo, Result, Error, CallBuilder, Hub, ReadSeek, Part, ResponseResult, RequestValue, NestedType, Delegate, DefaultDelegate, MethodsBuilder, Resource, JsonServerError};
// ##############
@@ -238,7 +245,7 @@ impl Default for Scope {
/// extern crate hyper;
/// extern crate "yup-oauth2" as oauth2;
/// extern crate "google-groupsmigration1" as groupsmigration1;
/// use groupsmigration1::Result;
/// use groupsmigration1::{Result, Error};
/// use std::fs;
/// # #[test] fn egal() {
/// use std::default::Default;
@@ -264,15 +271,17 @@ impl Default for Scope {
/// .upload(fs::File::open("file.ext").unwrap(), "application/octet-stream".parse().unwrap());
///
/// match result {
/// Result::HttpError(err) => println!("HTTPERROR: {:?}", err),
/// Result::MissingAPIKey => println!("Auth: Missing API Key - used if there are no scopes"),
/// Result::MissingToken => println!("OAuth2: Missing Token"),
/// Result::Cancelled => println!("Operation cancelled by user"),
/// Result::UploadSizeLimitExceeded(size, max_size) => println!("Upload size too big: {} of {}", size, max_size),
/// 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)"),
/// Err(e) => match e {
/// Error::HttpError(err) => println!("HTTPERROR: {:?}", err),
/// Error::MissingAPIKey => println!("Auth: Missing API Key - used if there are no scopes"),
/// Error::MissingToken => println!("OAuth2: Missing Token"),
/// Error::Cancelled => println!("Operation canceled by user"),
/// Error::UploadSizeLimitExceeded(size, max_size) => println!("Upload size too big: {} of {}", size, max_size),
/// Error::Failure(_) => println!("General Failure (hyper::client::Response doesn't print)"),
/// Error::FieldClash(clashed_field) => println!("You added custom parameter which is part of builder: {:?}", clashed_field),
/// Error::JsonDecodeError(err) => println!("Couldn't understand server reply - maybe API needs update: {:?}", err),
/// },
/// Ok(_) => println!("Success (value doesn't print)"),
/// }
/// # }
/// ```
@@ -328,9 +337,9 @@ impl<'a, C, NC, A> GroupsMigration<C, NC, A>
///
#[derive(Default, Clone, Debug, Deserialize)]
pub struct Groups {
/// The kind of insert resource this is.
/// The kind of insert resource this is.
pub kind: String,
/// The status of the insert request.
/// The status of the insert request.
#[serde(alias="responseCode")]
pub response_code: String,
}
@@ -377,13 +386,17 @@ pub struct ArchiveMethods<'a, C, NC, A>
hub: &'a GroupsMigration<C, NC, A>,
}
impl<'a, C, NC, A> ResourceMethodsBuilder for ArchiveMethods<'a, C, NC, A> {}
impl<'a, C, NC, A> MethodsBuilder for ArchiveMethods<'a, C, NC, A> {}
impl<'a, C, NC, A> ArchiveMethods<'a, C, NC, A> {
/// Create a builder to help you perform the following task:
///
/// Inserts a new mail into the archive of the Google group.
/// Inserts a new mail into the archive of the Google group.
///
/// # Arguments
///
/// * `groupId` - The group ID
pub fn insert(&self, group_id: &str) -> ArchiveInsertCall<'a, C, NC, A> {
ArchiveInsertCall {
hub: self.hub,
@@ -406,7 +419,7 @@ impl<'a, C, NC, A> ArchiveMethods<'a, C, NC, A> {
/// Inserts a new mail into the archive of the Google group.
///
/// A builder for the *insert* method supported by a *archive* resource.
/// It is not used directly, but through a `ArchiveMethods`.
/// It is not used directly, but through a `ArchiveMethods` instance.
///
/// # Example
///
@@ -466,7 +479,7 @@ impl<'a, C, NC, A> ArchiveInsertCall<'a, C, NC, A> where NC: hyper::net::Network
for &field in ["alt", "groupId"].iter() {
if self._additional_params.contains_key(field) {
dlg.finished(false);
return Result::FieldClash(field);
return Err(Error::FieldClash(field));
}
}
for (name, value) in self._additional_params.iter() {
@@ -529,7 +542,7 @@ impl<'a, C, NC, A> ArchiveInsertCall<'a, C, NC, A> where NC: hyper::net::Network
}
if token.is_none() {
dlg.finished(false);
return Result::MissingToken
return Err(Error::MissingToken)
}
let auth_header = Authorization(oauth2::Scheme { token_type: oauth2::TokenType::Bearer,
access_token: token.unwrap().access_token });
@@ -555,7 +568,7 @@ impl<'a, C, NC, A> ArchiveInsertCall<'a, C, NC, A> where NC: hyper::net::Network
let size = reader.seek(io::SeekFrom::End(0)).unwrap();
reader.seek(io::SeekFrom::Start(0)).unwrap();
if size > 16777216 {
return Result::UploadSizeLimitExceeded(size, 16777216)
return Err(Error::UploadSizeLimitExceeded(size, 16777216))
}
req = req.header(ContentType(reader_mime_type.clone()))
.header(ContentLength(size))
@@ -568,7 +581,6 @@ impl<'a, C, NC, A> ArchiveInsertCall<'a, C, NC, A> where NC: hyper::net::Network
dlg.pre_request();
req.send()
}
};
@@ -579,7 +591,7 @@ impl<'a, C, NC, A> ArchiveInsertCall<'a, C, NC, A> where NC: hyper::net::Network
continue;
}
dlg.finished(false);
return Result::HttpError(err)
return Err(Error::HttpError(err))
}
Ok(mut res) => {
if !res.status.is_success() {
@@ -590,13 +602,13 @@ impl<'a, C, NC, A> ArchiveInsertCall<'a, C, NC, A> where NC: hyper::net::Network
continue;
}
dlg.finished(false);
return Result::Failure(res)
return Err(Error::Failure(res))
}
if protocol == "resumable" {
let size = reader.seek(io::SeekFrom::End(0)).unwrap();
reader.seek(io::SeekFrom::Start(0)).unwrap();
if size > 16777216 {
return Result::UploadSizeLimitExceeded(size, 16777216)
return Err(Error::UploadSizeLimitExceeded(size, 16777216))
}
let mut client = &mut *self.hub.client.borrow_mut();
let upload_result = {
@@ -621,17 +633,17 @@ impl<'a, C, NC, A> ArchiveInsertCall<'a, C, NC, A> where NC: hyper::net::Network
match upload_result {
None => {
dlg.finished(false);
return Result::Cancelled
return Err(Error::Cancelled)
}
Some(Err(err)) => {
dlg.finished(false);
return Result::HttpError(err)
return Err(Error::HttpError(err))
}
Some(Ok(upload_result)) => {
res = upload_result;
if !res.status.is_success() {
dlg.finished(false);
return Result::Failure(res)
return Err(Error::Failure(res))
}
}
}
@@ -643,13 +655,13 @@ impl<'a, C, NC, A> ArchiveInsertCall<'a, C, NC, A> where NC: hyper::net::Network
Ok(decoded) => (res, decoded),
Err(err) => {
dlg.response_json_decode_error(&json_response, &err);
return Result::JsonDecodeError(err);
return Err(Error::JsonDecodeError(err));
}
}
};
dlg.finished(true);
return Result::Success(result_value)
return Ok(result_value)
}
}
}
@@ -665,11 +677,14 @@ impl<'a, C, NC, A> ArchiveInsertCall<'a, C, NC, A> where NC: hyper::net::Network
where RS: ReadSeek {
self.doit(stream, mime_type, "simple")
}
/// Upload media in a resumeable fashion.
/// Upload media in a resumable fashion.
/// Even if the upload fails or is interrupted, it can be resumed for a
/// certain amount of time as the server maintains state temporarily.
///
/// TODO: Write more about how delegation works in this particular case.
/// The delegate will be asked for an `upload_url()`, and if not provided, will be asked to store an upload URL
/// that was provided by the server, using `store_upload_url(...)`. The upload will be done in chunks, the delegate
/// may specify the `chunk_size()` and may cancel the operation before each chunk is uploaded, using
/// `cancel_chunk_upload(...)`.
///
/// * *max size*: 16MB
/// * *multipart*: yes
@@ -684,7 +699,7 @@ impl<'a, C, NC, A> ArchiveInsertCall<'a, C, NC, A> where NC: hyper::net::Network
/// Even though the property as already been set when instantiating this call,
/// we provide this method for API completeness.
///
/// The group ID
/// The group ID
pub fn group_id(mut self, new_value: &str) -> ArchiveInsertCall<'a, C, NC, A> {
self._group_id = new_value.to_string();
self