fix(CLI): added latest reference CLI code

Just to have something to link to
This commit is contained in:
Sebastian Thiel
2015-05-02 10:22:55 +02:00
parent 89432cc646
commit d2a4e2ff8b
26 changed files with 16333 additions and 4482 deletions

View File

@@ -4,7 +4,7 @@
[package]
name = "google-drive2-cli"
version = "0.1.0+20150326"
version = "0.2.0+20150326"
authors = ["Sebastian Thiel <byronimo@gmail.com>"]
description = "A complete library to interact with drive (protocol v2)"
repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/drive2-cli"
@@ -20,9 +20,7 @@ name = "drive2"
hyper = "*"
mime = "*"
yup-oauth2 = "*"
docopt = "*"
docopt_macros = "*"
rustc-serialize = "*"
clap = "*"
yup-hyper-mock = "*"
serde = ">= 0.3.0"
serde_macros = "*"

View File

@@ -10,79 +10,96 @@ capabilities. Errors will be printed to standard error, and cause the program's
If data-structures are requested, these will be returned as pretty-printed JSON, to be useful as input to other tools.
Everything else about the *drive* API can be found at the
[official documentation site](https://developers.google.com/drive/).
# Usage
This documentation was generated from the *drive* API at revision *20150326*. The CLI is at version *0.1.0*.
This documentation was generated from the *drive* API at revision *20150326*. The CLI is at version *0.2.0*.
```bash
drive2 [options] about get [-p <v>...] [-o <out>]
drive2 [options] apps get <app-id> [-p <v>...] [-o <out>]
drive2 [options] apps list [-p <v>...] [-o <out>]
drive2 [options] changes get <change-id> [-p <v>...] [-o <out>]
drive2 [options] changes list [-p <v>...] [-o <out>]
drive2 [options] changes watch -r <kv>... [-p <v>...] [-o <out>]
drive2 [options] channels stop -r <kv>... [-p <v>...]
drive2 [options] children delete <folder-id> <child-id> [-p <v>...]
drive2 [options] children get <folder-id> <child-id> [-p <v>...] [-o <out>]
drive2 [options] children insert <folder-id> -r <kv>... [-p <v>...] [-o <out>]
drive2 [options] children list <folder-id> [-p <v>...] [-o <out>]
drive2 [options] comments delete <file-id> <comment-id> [-p <v>...]
drive2 [options] comments get <file-id> <comment-id> [-p <v>...] [-o <out>]
drive2 [options] comments insert <file-id> -r <kv>... [-p <v>...] [-o <out>]
drive2 [options] comments list <file-id> [-p <v>...] [-o <out>]
drive2 [options] comments patch <file-id> <comment-id> -r <kv>... [-p <v>...] [-o <out>]
drive2 [options] comments update <file-id> <comment-id> -r <kv>... [-p <v>...] [-o <out>]
drive2 [options] files copy <file-id> -r <kv>... [-p <v>...] [-o <out>]
drive2 [options] files delete <file-id> [-p <v>...]
drive2 [options] files empty-trash [-p <v>...]
drive2 [options] files get <file-id> [-p <v>...] [-o <out>]
drive2 [options] files insert -r <kv>... -u (simple|resumable) <file> <mime> [-p <v>...] [-o <out>]
drive2 [options] files list [-p <v>...] [-o <out>]
drive2 [options] files patch <file-id> -r <kv>... [-p <v>...] [-o <out>]
drive2 [options] files touch <file-id> [-p <v>...] [-o <out>]
drive2 [options] files trash <file-id> [-p <v>...] [-o <out>]
drive2 [options] files untrash <file-id> [-p <v>...] [-o <out>]
drive2 [options] files update <file-id> -r <kv>... -u (simple|resumable) <file> <mime> [-p <v>...] [-o <out>]
drive2 [options] files watch <file-id> -r <kv>... [-p <v>...] [-o <out>]
drive2 [options] parents delete <file-id> <parent-id> [-p <v>...]
drive2 [options] parents get <file-id> <parent-id> [-p <v>...] [-o <out>]
drive2 [options] parents insert <file-id> -r <kv>... [-p <v>...] [-o <out>]
drive2 [options] parents list <file-id> [-p <v>...] [-o <out>]
drive2 [options] permissions delete <file-id> <permission-id> [-p <v>...]
drive2 [options] permissions get <file-id> <permission-id> [-p <v>...] [-o <out>]
drive2 [options] permissions get-id-for-email <email> [-p <v>...] [-o <out>]
drive2 [options] permissions insert <file-id> -r <kv>... [-p <v>...] [-o <out>]
drive2 [options] permissions list <file-id> [-p <v>...] [-o <out>]
drive2 [options] permissions patch <file-id> <permission-id> -r <kv>... [-p <v>...] [-o <out>]
drive2 [options] permissions update <file-id> <permission-id> -r <kv>... [-p <v>...] [-o <out>]
drive2 [options] properties delete <file-id> <property-key> [-p <v>...]
drive2 [options] properties get <file-id> <property-key> [-p <v>...] [-o <out>]
drive2 [options] properties insert <file-id> -r <kv>... [-p <v>...] [-o <out>]
drive2 [options] properties list <file-id> [-p <v>...] [-o <out>]
drive2 [options] properties patch <file-id> <property-key> -r <kv>... [-p <v>...] [-o <out>]
drive2 [options] properties update <file-id> <property-key> -r <kv>... [-p <v>...] [-o <out>]
drive2 [options] realtime get <file-id> [-p <v>...] [-o <out>]
drive2 [options] realtime update <file-id> -u (simple|resumable) <file> <mime> [-p <v>...]
drive2 [options] replies delete <file-id> <comment-id> <reply-id> [-p <v>...]
drive2 [options] replies get <file-id> <comment-id> <reply-id> [-p <v>...] [-o <out>]
drive2 [options] replies insert <file-id> <comment-id> -r <kv>... [-p <v>...] [-o <out>]
drive2 [options] replies list <file-id> <comment-id> [-p <v>...] [-o <out>]
drive2 [options] replies patch <file-id> <comment-id> <reply-id> -r <kv>... [-p <v>...] [-o <out>]
drive2 [options] replies update <file-id> <comment-id> <reply-id> -r <kv>... [-p <v>...] [-o <out>]
drive2 [options] revisions delete <file-id> <revision-id> [-p <v>...]
drive2 [options] revisions get <file-id> <revision-id> [-p <v>...] [-o <out>]
drive2 [options] revisions list <file-id> [-p <v>...] [-o <out>]
drive2 [options] revisions patch <file-id> <revision-id> -r <kv>... [-p <v>...] [-o <out>]
drive2 [options] revisions update <file-id> <revision-id> -r <kv>... [-p <v>...] [-o <out>]
drive2 [options]
about
get [-p <v>]... [-o <out>]
apps
get <app-id> [-p <v>]... [-o <out>]
list [-p <v>]... [-o <out>]
changes
get <change-id> [-p <v>]... [-o <out>]
list [-p <v>]... [-o <out>]
watch (-r <kv>)... [-p <v>]... [-o <out>]
channels
stop (-r <kv>)... [-p <v>]...
children
delete <folder-id> <child-id> [-p <v>]...
get <folder-id> <child-id> [-p <v>]... [-o <out>]
insert <folder-id> (-r <kv>)... [-p <v>]... [-o <out>]
list <folder-id> [-p <v>]... [-o <out>]
comments
delete <file-id> <comment-id> [-p <v>]...
get <file-id> <comment-id> [-p <v>]... [-o <out>]
insert <file-id> (-r <kv>)... [-p <v>]... [-o <out>]
list <file-id> [-p <v>]... [-o <out>]
patch <file-id> <comment-id> (-r <kv>)... [-p <v>]... [-o <out>]
update <file-id> <comment-id> (-r <kv>)... [-p <v>]... [-o <out>]
files
copy <file-id> (-r <kv>)... [-p <v>]... [-o <out>]
delete <file-id> [-p <v>]...
empty-trash [-p <v>]...
get <file-id> [-p <v>]... [-o <out>]
insert (-r <kv>)... (-u (simple|resumable) -f <file> [-m <mime>]) [-p <v>]... [-o <out>]
list [-p <v>]... [-o <out>]
patch <file-id> (-r <kv>)... [-p <v>]... [-o <out>]
touch <file-id> [-p <v>]... [-o <out>]
trash <file-id> [-p <v>]... [-o <out>]
untrash <file-id> [-p <v>]... [-o <out>]
update <file-id> (-r <kv>)... (-u (simple|resumable) -f <file> [-m <mime>]) [-p <v>]... [-o <out>]
watch <file-id> (-r <kv>)... [-p <v>]... [-o <out>]
parents
delete <file-id> <parent-id> [-p <v>]...
get <file-id> <parent-id> [-p <v>]... [-o <out>]
insert <file-id> (-r <kv>)... [-p <v>]... [-o <out>]
list <file-id> [-p <v>]... [-o <out>]
permissions
delete <file-id> <permission-id> [-p <v>]...
get <file-id> <permission-id> [-p <v>]... [-o <out>]
get-id-for-email <email> [-p <v>]... [-o <out>]
insert <file-id> (-r <kv>)... [-p <v>]... [-o <out>]
list <file-id> [-p <v>]... [-o <out>]
patch <file-id> <permission-id> (-r <kv>)... [-p <v>]... [-o <out>]
update <file-id> <permission-id> (-r <kv>)... [-p <v>]... [-o <out>]
properties
delete <file-id> <property-key> [-p <v>]...
get <file-id> <property-key> [-p <v>]... [-o <out>]
insert <file-id> (-r <kv>)... [-p <v>]... [-o <out>]
list <file-id> [-p <v>]... [-o <out>]
patch <file-id> <property-key> (-r <kv>)... [-p <v>]... [-o <out>]
update <file-id> <property-key> (-r <kv>)... [-p <v>]... [-o <out>]
realtime
get <file-id> [-p <v>]... [-o <out>]
update <file-id> (-u (simple|resumable) -f <file> [-m <mime>]) [-p <v>]...
replies
delete <file-id> <comment-id> <reply-id> [-p <v>]...
get <file-id> <comment-id> <reply-id> [-p <v>]... [-o <out>]
insert <file-id> <comment-id> (-r <kv>)... [-p <v>]... [-o <out>]
list <file-id> <comment-id> [-p <v>]... [-o <out>]
patch <file-id> <comment-id> <reply-id> (-r <kv>)... [-p <v>]... [-o <out>]
update <file-id> <comment-id> <reply-id> (-r <kv>)... [-p <v>]... [-o <out>]
revisions
delete <file-id> <revision-id> [-p <v>]...
get <file-id> <revision-id> [-p <v>]... [-o <out>]
list <file-id> [-p <v>]... [-o <out>]
patch <file-id> <revision-id> (-r <kv>)... [-p <v>]... [-o <out>]
update <file-id> <revision-id> (-r <kv>)... [-p <v>]... [-o <out>]
drive2 --help
All documentation details can be found at
http://byron.github.io/google-apis-rs/google_drive2_cli/index.html
http://byron.github.io/google-apis-rs/google_drive2_cli
Configuration:
--scope <url>
[--scope <url>]...
Specify the authentication a method should be executed in. Each scope
requires the user to grant this application permission to use it.
requires the user to grant this application permission to use it.
If unset, it defaults to the shortest scope url for a particular method.
--config-dir <folder>
A directory into which we will store our persistent data. Defaults to

View File

@@ -1,4 +1,4 @@
site_name: drive v0.1.0+20150326
site_name: drive v0.2.0+20150326
site_url: http://byron.github.io/google-apis-rs/google-drive2-cli
site_description: Write integrating applications with bcore

View File

@@ -1,8 +1,9 @@
// COPY OF 'src/rust/cli/cmn.rs'
// DO NOT EDIT
use oauth2::{ApplicationSecret, ConsoleApplicationSecret, TokenStorage, Token};
use rustc_serialize::json;
use serde::json;
use mime::Mime;
use clap::{App, SubCommand};
use std::fs;
use std::env;
@@ -17,6 +18,46 @@ use std::default::Default;
const FIELD_SEP: char = '.';
pub enum CallType {
Upload(UploadProtocol),
Standard,
}
pub enum UploadProtocol {
Simple,
Resumable,
}
impl AsRef<str> for UploadProtocol {
fn as_ref(&self) -> &str {
match *self {
UploadProtocol::Simple => "simple",
UploadProtocol::Resumable => "resumable"
}
}
}
impl AsRef<str> for CallType {
fn as_ref(&self) -> &str {
match *self {
CallType::Upload(ref proto) => proto.as_ref(),
CallType::Standard => "standard-request"
}
}
}
impl FromStr for UploadProtocol {
type Err = String;
fn from_str(s: &str) -> Result<UploadProtocol, String> {
match s {
"simple" => Ok(UploadProtocol::Simple),
"resumable" => Ok(UploadProtocol::Resumable),
_ => Err(format!("Protocol '{}' is unknown", s)),
}
}
}
#[derive(Clone, Default)]
pub struct FieldCursor(Vec<String>);
@@ -112,6 +153,17 @@ pub fn parse_kv_arg<'a>(kv: &'a str, err: &mut InvalidOptionsError, for_hashmap:
}
}
pub fn protocol_from_str(name: &str, valid_protocols: Vec<String>, err: &mut InvalidOptionsError) -> CallType {
CallType::Upload(
match UploadProtocol::from_str(name) {
Ok(up) => up,
Err(msg) => {
err.issues.push(CLIError::InvalidUploadProtocol(name.to_string(), valid_protocols));
UploadProtocol::Simple
}
})
}
pub fn input_file_from_opts(file_path: &str, err: &mut InvalidOptionsError) -> Option<fs::File> {
match fs::File::open(file_path) {
Ok(f) => Some(f),
@@ -132,13 +184,14 @@ pub fn input_mime_from_opts(mime: &str, err: &mut InvalidOptionsError) -> Option
}
}
// May panic if we can't open the file - this is anticipated, we can't currently communicate this
// kind of error: TODO: fix this architecture :)
pub fn writer_from_opts(flag: bool, arg: &str) -> Box<Write> {
if !flag || arg == "-" {
Box::new(stdout())
} else {
Box::new(fs::OpenOptions::new().create(true).write(true).open(arg).unwrap())
pub fn writer_from_opts(arg: Option<&str>) -> Result<Box<Write>, io::Error> {
let f = arg.unwrap_or("-");
match f {
"-" => Ok(Box::new(stdout())),
_ => match fs::OpenOptions::new().create(true).write(true).open(f) {
Ok(f) => Ok(Box::new(f)),
Err(io_err) => Err(io_err),
}
}
}
@@ -151,7 +204,7 @@ pub fn arg_from_str<T>(arg: &str, err: &mut InvalidOptionsError,
match FromStr::from_str(arg) {
Err(perr) => {
err.issues.push(
CLIError::ParseError((arg_name, arg_type, arg.to_string(), format!("{}", perr)))
CLIError::ParseError(arg_name, arg_type, arg.to_string(), format!("{}", perr))
);
Default::default()
},
@@ -171,49 +224,47 @@ impl JsonTokenStorage {
}
impl TokenStorage for JsonTokenStorage {
type Error = io::Error;
type Error = json::Error;
// NOTE: logging might be interesting, currently we swallow all errors
fn set(&mut self, scope_hash: u64, _: &Vec<&str>, token: Option<Token>) -> Option<io::Error> {
fn set(&mut self, scope_hash: u64, _: &Vec<&str>, token: Option<Token>) -> Result<(), json::Error> {
match token {
None => {
match fs::remove_file(self.path(scope_hash)) {
Err(err) =>
match err.kind() {
io::ErrorKind::NotFound => None,
_ => Some(err)
io::ErrorKind::NotFound => Ok(()),
_ => Err(json::Error::IoError(err))
},
Ok(_) => None
Ok(_) => Ok(()),
}
}
Some(token) => {
let json_token = json::encode(&token).unwrap();
match fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)) {
Ok(mut f) => {
match f.write(json_token.as_bytes()) {
Ok(_) => None,
Err(io_err) => Some(io_err),
match json::to_writer_pretty(&mut f, &token) {
Ok(_) => Ok(()),
Err(io_err) => Err(json::Error::IoError(io_err)),
}
},
Err(io_err) => Some(io_err)
Err(io_err) => Err(json::Error::IoError(io_err))
}
}
}
}
fn get(&self, scope_hash: u64, _: &Vec<&str>) -> Result<Option<Token>, io::Error> {
fn get(&self, scope_hash: u64, _: &Vec<&str>) -> Result<Option<Token>, json::Error> {
match fs::File::open(&self.path(scope_hash)) {
Ok(mut f) => {
let mut json_string = String::new();
match f.read_to_string(&mut json_string) {
Ok(_) => Ok(Some(json::decode::<Token>(&json_string).unwrap())),
Err(io_err) => Err(io_err),
match json::de::from_reader(f) {
Ok(token) => Ok(Some(token)),
Err(err) => Err(err),
}
},
Err(io_err) => {
match io_err.kind() {
io::ErrorKind::NotFound => Ok(None),
_ => Err(io_err)
_ => Err(json::Error::IoError(io_err))
}
}
}
@@ -223,7 +274,7 @@ impl TokenStorage for JsonTokenStorage {
#[derive(Debug)]
pub enum ApplicationSecretError {
DecoderError((String, json::DecoderError)),
DecoderError((String, json::Error)),
FormatError(String),
}
@@ -311,11 +362,14 @@ impl fmt::Display for FieldError {
#[derive(Debug)]
pub enum CLIError {
Configuration(ConfigurationError),
ParseError((&'static str, &'static str, String, String)),
ParseError(&'static str, &'static str, String, String),
UnknownParameter(String),
InvalidUploadProtocol(String, Vec<String>),
InvalidKeyValueSyntax(String, bool),
Input(InputError),
Field(FieldError),
MissingCommandError,
MissingMethodError(String),
}
impl fmt::Display for CLIError {
@@ -324,7 +378,9 @@ impl fmt::Display for CLIError {
CLIError::Configuration(ref err) => write!(f, "Configuration -> {}", err),
CLIError::Input(ref err) => write!(f, "Input -> {}", err),
CLIError::Field(ref err) => write!(f, "Field -> {}", err),
CLIError::ParseError((arg_name, type_name, ref value, ref err_desc))
CLIError::InvalidUploadProtocol(ref proto_name, ref valid_names)
=> writeln!(f, "'{}' is not a valid upload protocol. Choose from one of {}", proto_name, valid_names.connect(", ")),
CLIError::ParseError(arg_name, type_name, ref value, ref err_desc)
=> writeln!(f, "Failed to parse argument '{}' with value '{}' as {} with error: {}",
arg_name, value, type_name, err_desc),
CLIError::UnknownParameter(ref param_name)
@@ -333,6 +389,8 @@ impl fmt::Display for CLIError {
let hashmap_info = if is_hashmap { "hashmap " } else { "" };
writeln!(f, "'{}' does not match {}pattern <key>=<value>", kv, hashmap_info)
},
CLIError::MissingCommandError => writeln!(f, "Please specify the main sub-command"),
CLIError::MissingMethodError(ref cmd) => writeln!(f, "Please specify the method to call on the '{}' command", cmd),
}
}
}
@@ -399,7 +457,7 @@ pub fn assure_config_dir_exists(dir: &str) -> Result<String, CLIError> {
pub fn application_secret_from_directory(dir: &str,
secret_basename: &str,
json_app_secret: &str)
json_console_secret: &str)
-> Result<ApplicationSecret, CLIError> {
let secret_path = Path::new(dir).join(secret_basename);
let secret_str = || secret_path.as_path().to_str().unwrap().to_string();
@@ -418,7 +476,10 @@ pub fn application_secret_from_directory(dir: &str,
err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) {
Err(cfe) => cfe,
Ok(mut f) => {
match f.write(json_app_secret.as_bytes()) {
// Assure we convert 'ugly' json string into pretty one
let console_secret: ConsoleApplicationSecret
= json::from_str(json_console_secret).unwrap();
match json::to_writer_pretty(&mut f, &console_secret) {
Err(io_err) => io_err,
Ok(_) => continue,
}
@@ -429,23 +490,24 @@ pub fn application_secret_from_directory(dir: &str,
return secret_io_error(err)
},
Ok(mut f) => {
let mut json_encoded_secret = String::new();
if let Err(io_err) = f.read_to_string(&mut json_encoded_secret) {
return secret_io_error(io_err)
}
match json::decode::<ConsoleApplicationSecret>(&json_encoded_secret) {
Err(json_decode_error) => return Err(CLIError::Configuration(
ConfigurationError::Secret(ApplicationSecretError::DecoderError(
(secret_str(), json_decode_error)
match json::de::from_reader::<_, ConsoleApplicationSecret>(f) {
Err(json::Error::IoError(err)) =>
return secret_io_error(err),
Err(json_err) =>
return Err(CLIError::Configuration(
ConfigurationError::Secret(
ApplicationSecretError::DecoderError(
(secret_str(), json_err)
)))),
Ok(console_secret) => match console_secret.installed {
Some(secret) => return Ok(secret),
None => return Err(
CLIError::Configuration(
ConfigurationError::Secret(
ApplicationSecretError::FormatError(secret_str())
)))
},
Ok(console_secret) =>
match console_secret.installed {
Some(secret) => return Ok(secret),
None => return Err(
CLIError::Configuration(
ConfigurationError::Secret(
ApplicationSecretError::FormatError(secret_str())
)))
},
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -4,7 +4,7 @@
[package]
name = "google-drive2"
version = "0.1.6+20150326"
version = "0.1.7+20150326"
authors = ["Sebastian Thiel <byronimo@gmail.com>"]
description = "A complete library to interact with drive (protocol v2)"
repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/drive2"

View File

@@ -5,7 +5,7 @@ DO NOT EDIT !
-->
The `google-drive2` library allows access to all features of the *Google drive* service.
This documentation was generated from *drive* crate version *0.1.6+20150326*, where *20150326* is the exact revision of the *drive:v2* schema built by the [mako](http://www.makotemplates.org/) code generator *v0.1.6*.
This documentation was generated from *drive* crate version *0.1.7+20150326*, where *20150326* is the exact revision of the *drive:v2* schema built by the [mako](http://www.makotemplates.org/) code generator *v0.1.7*.
Everything else about the *drive* *v2* API can be found at the
[official documentation site](https://developers.google.com/drive/).
@@ -230,7 +230,7 @@ These will always take a single argument, for which the following statements are
* [PODs][wiki-pod] are handed by copy
* strings are passed as `&str`
* [request values](http://byron.github.io/google-apis-rs/google_drive2/trait.RequestValue.html) are borrowed
* [request values](http://byron.github.io/google-apis-rs/google_drive2/trait.RequestValue.html) are moved
Arguments will always be copied or cloned into the builder, to make them independent of their original life times.

View File

@@ -173,7 +173,10 @@ pub trait Delegate {
/// Called after we have retrieved a new upload URL for a resumable upload to store it
/// in case we fail or cancel. That way, we can attempt to resume the upload later,
/// see `upload_url()`.
fn store_upload_url(&mut self, url: &str) {
/// It will also be called with None after a successful upload, which allows the delegate
/// to forget the URL. That way, we will not attempt to resume an upload that has already
/// finished.
fn store_upload_url(&mut self, url: Option<&str>) {
let _ = url;
}
@@ -459,6 +462,16 @@ impl<'a> Read for MultiPartReader<'a> {
header!{
#[doc="The `X-Upload-Content-Type` header."]
(XUploadContentType, "X-Upload-Content-Type") => [Mime]
xupload_content_type {
test_header!(
test1,
vec![b"text/plain"],
Some(HeaderField(
vec![Mime(TopLevel::Text, SubLevel::Plain, Vec::new())]
)));
}
}
#[derive(Clone, PartialEq, Debug)]

View File

@@ -2,7 +2,7 @@
// This file was generated automatically from 'src/mako/api/lib.rs.mako'
// DO NOT EDIT !
//! This documentation was generated from *drive* crate version *0.1.6+20150326*, where *20150326* is the exact revision of the *drive:v2* schema built by the [mako](http://www.makotemplates.org/) code generator *v0.1.6*.
//! This documentation was generated from *drive* crate version *0.1.7+20150326*, where *20150326* is the exact revision of the *drive:v2* schema built by the [mako](http://www.makotemplates.org/) code generator *v0.1.7*.
//!
//! Everything else about the *drive* *v2* API can be found at the
//! [official documentation site](https://developers.google.com/drive/).
@@ -231,7 +231,7 @@
//!
//! * [PODs][wiki-pod] are handed by copy
//! * strings are passed as `&str`
//! * [request values](trait.RequestValue.html) are borrowed
//! * [request values](trait.RequestValue.html) are moved
//!
//! Arguments will always be copied or cloned into the builder, to make them independent of their original life times.
//!
@@ -240,7 +240,6 @@
//! [google-go-api]: https://github.com/google/google-api-go-client
//!
//!
#![feature(std_misc)]
// Unused attributes happen thanks to defined, but unused structures
// We don't warn about this, as depending on the API, some data structures or facilities are never used.
// Instead of pre-determining this, we just disable the lint. It's manually tuned to not have any
@@ -418,7 +417,7 @@ impl<'a, C, A> Drive<C, A>
Drive {
client: RefCell::new(client),
auth: RefCell::new(authenticator),
_user_agent: "google-api-rust-client/0.1.6".to_string(),
_user_agent: "google-api-rust-client/0.1.7".to_string(),
}
}
@@ -463,7 +462,7 @@ impl<'a, C, A> Drive<C, A>
}
/// Set the user-agent header field to use in all requests to the server.
/// It defaults to `google-api-rust-client/0.1.6`.
/// It defaults to `google-api-rust-client/0.1.7`.
///
/// Returns the previously set user-agent.
pub fn user_agent(&mut self, agent_name: String) -> String {
@@ -3782,7 +3781,7 @@ impl<'a, C, A> FileWatchCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oau
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.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Post, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone())
.header(ContentType(json_mime_type.clone()))
@@ -4129,7 +4128,7 @@ impl<'a, C, A> FileInsertCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oa
_ => (&mut request_value_reader as &mut io::Read, ContentType(json_mime_type.clone())),
};
let mut client = &mut *self.hub.client.borrow_mut();
let mut req = client.borrow_mut().request(hyper::method::Method::Post, url.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Post, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone())
.header(content_type)
@@ -4179,7 +4178,7 @@ impl<'a, C, A> FileInsertCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oa
let upload_result = {
let url_str = &res.headers.get::<Location>().expect("Location header is part of protocol").0;
if upload_url_from_server {
dlg.store_upload_url(url_str);
dlg.store_upload_url(Some(url_str));
}
cmn::ResumableUploadHelper {
@@ -4207,6 +4206,7 @@ impl<'a, C, A> FileInsertCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oa
Some(Ok(upload_result)) => {
res = upload_result;
if !res.status.is_success() {
dlg.store_upload_url(None);
dlg.finished(false);
return Err(Error::Failure(res))
}
@@ -4500,7 +4500,7 @@ impl<'a, C, A> FileUntrashCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: o
access_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::Post, url.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Post, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone());
@@ -4786,7 +4786,7 @@ impl<'a, C, A> FileCopyCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oaut
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.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Post, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone())
.header(ContentType(json_mime_type.clone()))
@@ -5086,7 +5086,7 @@ impl<'a, C, A> FileTrashCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oau
access_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::Post, url.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Post, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone());
@@ -5298,7 +5298,7 @@ impl<'a, C, A> FileEmptyTrashCall<'a, C, A> where C: BorrowMut<hyper::Client>, A
access_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::Delete, url.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Delete, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone());
@@ -5516,7 +5516,7 @@ impl<'a, C, A> FileListCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oaut
access_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.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Get, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone());
@@ -5780,7 +5780,7 @@ impl<'a, C, A> FileTouchCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oau
access_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::Post, url.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Post, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone());
@@ -6133,7 +6133,7 @@ impl<'a, C, A> FileUpdateCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oa
_ => (&mut request_value_reader as &mut io::Read, ContentType(json_mime_type.clone())),
};
let mut client = &mut *self.hub.client.borrow_mut();
let mut req = client.borrow_mut().request(hyper::method::Method::Put, url.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Put, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone())
.header(content_type)
@@ -6183,7 +6183,7 @@ impl<'a, C, A> FileUpdateCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oa
let upload_result = {
let url_str = &res.headers.get::<Location>().expect("Location header is part of protocol").0;
if upload_url_from_server {
dlg.store_upload_url(url_str);
dlg.store_upload_url(Some(url_str));
}
cmn::ResumableUploadHelper {
@@ -6211,6 +6211,7 @@ impl<'a, C, A> FileUpdateCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oa
Some(Ok(upload_result)) => {
res = upload_result;
if !res.status.is_success() {
dlg.store_upload_url(None);
dlg.finished(false);
return Err(Error::Failure(res))
}
@@ -6541,7 +6542,7 @@ impl<'a, C, A> FileDeleteCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oa
access_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::Delete, url.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Delete, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone());
@@ -6842,7 +6843,7 @@ impl<'a, C, A> FilePatchCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oau
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::Patch, url.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Patch, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone())
.header(ContentType(json_mime_type.clone()))
@@ -7218,7 +7219,7 @@ impl<'a, C, A> FileGetCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oauth
access_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.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Get, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone());
@@ -7474,7 +7475,7 @@ impl<'a, C, A> AboutGetCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oaut
access_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.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Get, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone());
@@ -7754,7 +7755,7 @@ impl<'a, C, A> RealtimeUpdateCall<'a, C, A> where C: BorrowMut<hyper::Client>, A
response
} else {
let mut client = &mut *self.hub.client.borrow_mut();
let mut req = client.borrow_mut().request(hyper::method::Method::Put, url.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Put, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone());
if protocol == "simple" {
@@ -7812,7 +7813,7 @@ impl<'a, C, A> RealtimeUpdateCall<'a, C, A> where C: BorrowMut<hyper::Client>, A
let upload_result = {
let url_str = &res.headers.get::<Location>().expect("Location header is part of protocol").0;
if upload_url_from_server {
dlg.store_upload_url(url_str);
dlg.store_upload_url(Some(url_str));
}
cmn::ResumableUploadHelper {
@@ -7840,6 +7841,7 @@ impl<'a, C, A> RealtimeUpdateCall<'a, C, A> where C: BorrowMut<hyper::Client>, A
Some(Ok(upload_result)) => {
res = upload_result;
if !res.status.is_success() {
dlg.store_upload_url(None);
dlg.finished(false);
return Err(Error::Failure(res))
}
@@ -8082,7 +8084,7 @@ impl<'a, C, A> RealtimeGetCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: o
access_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.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Get, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone());
@@ -8318,7 +8320,7 @@ impl<'a, C, A> AppGetCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oauth2
access_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.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Get, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone());
@@ -8546,7 +8548,7 @@ impl<'a, C, A> AppListCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oauth
access_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.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Get, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone());
@@ -8797,7 +8799,7 @@ impl<'a, C, A> CommentDeleteCall<'a, C, A> where C: BorrowMut<hyper::Client>, A:
access_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::Delete, url.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Delete, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone());
@@ -9043,7 +9045,7 @@ impl<'a, C, A> CommentGetCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oa
access_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.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Get, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone());
@@ -9311,7 +9313,7 @@ impl<'a, C, A> CommentInsertCall<'a, C, A> where C: BorrowMut<hyper::Client>, A:
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.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Post, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone())
.header(ContentType(json_mime_type.clone()))
@@ -9576,7 +9578,7 @@ impl<'a, C, A> CommentPatchCall<'a, C, A> where C: BorrowMut<hyper::Client>, A:
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::Patch, url.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Patch, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone())
.header(ContentType(json_mime_type.clone()))
@@ -9851,7 +9853,7 @@ impl<'a, C, A> CommentUpdateCall<'a, C, A> where C: BorrowMut<hyper::Client>, A:
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::Put, url.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Put, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone())
.header(ContentType(json_mime_type.clone()))
@@ -10132,7 +10134,7 @@ impl<'a, C, A> CommentListCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: o
access_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.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Get, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone());
@@ -10414,7 +10416,7 @@ impl<'a, C, A> ChildrenListCall<'a, C, A> where C: BorrowMut<hyper::Client>, A:
access_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.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Get, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone());
@@ -10676,7 +10678,7 @@ impl<'a, C, A> ChildrenGetCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: o
access_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.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Get, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone());
@@ -10926,7 +10928,7 @@ impl<'a, C, A> ChildrenDeleteCall<'a, C, A> where C: BorrowMut<hyper::Client>, A
access_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::Delete, url.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Delete, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone());
@@ -11177,7 +11179,7 @@ impl<'a, C, A> ChildrenInsertCall<'a, C, A> where C: BorrowMut<hyper::Client>, A
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.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Post, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone())
.header(ContentType(json_mime_type.clone()))
@@ -11413,7 +11415,7 @@ impl<'a, C, A> ChannelStopCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: o
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.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Post, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone())
.header(ContentType(json_mime_type.clone()))
@@ -11644,7 +11646,7 @@ impl<'a, C, A> ParentListCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oa
access_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.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Get, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone());
@@ -11884,7 +11886,7 @@ impl<'a, C, A> ParentDeleteCall<'a, C, A> where C: BorrowMut<hyper::Client>, A:
access_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::Delete, url.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Delete, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone());
@@ -12135,7 +12137,7 @@ impl<'a, C, A> ParentInsertCall<'a, C, A> where C: BorrowMut<hyper::Client>, A:
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.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Post, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone())
.header(ContentType(json_mime_type.clone()))
@@ -12388,7 +12390,7 @@ impl<'a, C, A> ParentGetCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oau
access_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.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Get, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone());
@@ -12653,7 +12655,7 @@ impl<'a, C, A> ReplyPatchCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oa
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::Patch, url.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Patch, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone())
.header(ContentType(json_mime_type.clone()))
@@ -12941,7 +12943,7 @@ impl<'a, C, A> ReplyListCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oau
access_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.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Get, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone());
@@ -13220,7 +13222,7 @@ impl<'a, C, A> ReplyGetCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oaut
access_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.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Get, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone());
@@ -13500,7 +13502,7 @@ impl<'a, C, A> ReplyInsertCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: o
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.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Post, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone())
.header(ContentType(json_mime_type.clone()))
@@ -13764,7 +13766,7 @@ impl<'a, C, A> ReplyDeleteCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: o
access_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::Delete, url.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Delete, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone());
@@ -14029,7 +14031,7 @@ impl<'a, C, A> ReplyUpdateCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: o
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::Put, url.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Put, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone())
.header(ContentType(json_mime_type.clone()))
@@ -14301,7 +14303,7 @@ impl<'a, C, A> PermissionDeleteCall<'a, C, A> where C: BorrowMut<hyper::Client>,
access_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::Delete, url.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Delete, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone());
@@ -14562,7 +14564,7 @@ impl<'a, C, A> PermissionInsertCall<'a, C, A> where C: BorrowMut<hyper::Client>,
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.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Post, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone())
.header(ContentType(json_mime_type.clone()))
@@ -14846,7 +14848,7 @@ impl<'a, C, A> PermissionUpdateCall<'a, C, A> where C: BorrowMut<hyper::Client>,
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::Put, url.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Put, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone())
.header(ContentType(json_mime_type.clone()))
@@ -15133,7 +15135,7 @@ impl<'a, C, A> PermissionPatchCall<'a, C, A> where C: BorrowMut<hyper::Client>,
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::Patch, url.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Patch, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone())
.header(ContentType(json_mime_type.clone()))
@@ -15401,7 +15403,7 @@ impl<'a, C, A> PermissionListCall<'a, C, A> where C: BorrowMut<hyper::Client>, A
access_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.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Get, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone());
@@ -15642,7 +15644,7 @@ impl<'a, C, A> PermissionGetCall<'a, C, A> where C: BorrowMut<hyper::Client>, A:
access_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.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Get, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone());
@@ -15891,7 +15893,7 @@ impl<'a, C, A> PermissionGetIdForEmailCall<'a, C, A> where C: BorrowMut<hyper::C
access_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.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Get, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone());
@@ -16141,7 +16143,7 @@ impl<'a, C, A> ChangeWatchCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: o
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.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Post, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone())
.header(ContentType(json_mime_type.clone()))
@@ -16416,7 +16418,7 @@ impl<'a, C, A> ChangeListCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oa
access_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.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Get, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone());
@@ -16680,7 +16682,7 @@ impl<'a, C, A> ChangeGetCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: oau
access_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.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Get, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone());
@@ -16938,7 +16940,7 @@ impl<'a, C, A> PropertyPatchCall<'a, C, A> where C: BorrowMut<hyper::Client>, A:
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::Patch, url.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Patch, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone())
.header(ContentType(json_mime_type.clone()))
@@ -17212,7 +17214,7 @@ impl<'a, C, A> PropertyDeleteCall<'a, C, A> where C: BorrowMut<hyper::Client>, A
access_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::Delete, url.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Delete, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone());
@@ -17470,7 +17472,7 @@ impl<'a, C, A> PropertyInsertCall<'a, C, A> where C: BorrowMut<hyper::Client>, A
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.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Post, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone())
.header(ContentType(json_mime_type.clone()))
@@ -17721,7 +17723,7 @@ impl<'a, C, A> PropertyListCall<'a, C, A> where C: BorrowMut<hyper::Client>, A:
access_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.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Get, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone());
@@ -17979,7 +17981,7 @@ impl<'a, C, A> PropertyUpdateCall<'a, C, A> where C: BorrowMut<hyper::Client>, A
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::Put, url.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Put, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone())
.header(ContentType(json_mime_type.clone()))
@@ -18254,7 +18256,7 @@ impl<'a, C, A> PropertyGetCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: o
access_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.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Get, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone());
@@ -18512,7 +18514,7 @@ impl<'a, C, A> RevisionGetCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: o
access_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.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Get, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone());
@@ -18762,7 +18764,7 @@ impl<'a, C, A> RevisionDeleteCall<'a, C, A> where C: BorrowMut<hyper::Client>, A
access_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::Delete, url.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Delete, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone());
@@ -19015,7 +19017,7 @@ impl<'a, C, A> RevisionUpdateCall<'a, C, A> where C: BorrowMut<hyper::Client>, A
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::Put, url.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Put, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone())
.header(ContentType(json_mime_type.clone()))
@@ -19276,7 +19278,7 @@ impl<'a, C, A> RevisionListCall<'a, C, A> where C: BorrowMut<hyper::Client>, A:
access_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.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Get, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone());
@@ -19529,7 +19531,7 @@ impl<'a, C, A> RevisionPatchCall<'a, C, A> where C: BorrowMut<hyper::Client>, A:
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::Patch, url.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Patch, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone())
.header(ContentType(json_mime_type.clone()))

View File

@@ -4,7 +4,7 @@
[package]
name = "google-groupsmigration1-cli"
version = "0.1.0+20140416"
version = "0.2.0+20140416"
authors = ["Sebastian Thiel <byronimo@gmail.com>"]
description = "A complete library to interact with Groups Migration (protocol v1)"
repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/groupsmigration1-cli"
@@ -20,9 +20,7 @@ name = "groupsmigration1"
hyper = "*"
mime = "*"
yup-oauth2 = "*"
docopt = "*"
docopt_macros = "*"
rustc-serialize = "*"
clap = "*"
yup-hyper-mock = "*"
serde = ">= 0.3.0"
serde_macros = "*"

View File

@@ -10,21 +10,26 @@ capabilities. Errors will be printed to standard error, and cause the program's
If data-structures are requested, these will be returned as pretty-printed JSON, to be useful as input to other tools.
Everything else about the *Groups Migration* API can be found at the
[official documentation site](https://developers.google.com/google-apps/groups-migration/).
# Usage
This documentation was generated from the *Groups Migration* API at revision *20140416*. The CLI is at version *0.1.0*.
This documentation was generated from the *Groups Migration* API at revision *20140416*. The CLI is at version *0.2.0*.
```bash
groupsmigration1 [options] archive insert <group-id> -u (simple|resumable) <file> <mime> [-p <v>...] [-o <out>]
groupsmigration1 [options]
archive
insert <group-id> (-u (simple|resumable) -f <file> [-m <mime>]) [-p <v>]... [-o <out>]
groupsmigration1 --help
All documentation details can be found at
http://byron.github.io/google-apis-rs/google_groupsmigration1_cli/index.html
http://byron.github.io/google-apis-rs/google_groupsmigration1_cli
Configuration:
--scope <url>
[--scope <url>]...
Specify the authentication a method should be executed in. Each scope
requires the user to grant this application permission to use it.
requires the user to grant this application permission to use it.
If unset, it defaults to the shortest scope url for a particular method.
--config-dir <folder>
A directory into which we will store our persistent data. Defaults to

View File

@@ -1,4 +1,4 @@
site_name: Groups Migration v0.1.0+20140416
site_name: Groups Migration v0.2.0+20140416
site_url: http://byron.github.io/google-apis-rs/google-groupsmigration1-cli
site_description: Write integrating applications with bcore

View File

@@ -1,8 +1,9 @@
// COPY OF 'src/rust/cli/cmn.rs'
// DO NOT EDIT
use oauth2::{ApplicationSecret, ConsoleApplicationSecret, TokenStorage, Token};
use rustc_serialize::json;
use serde::json;
use mime::Mime;
use clap::{App, SubCommand};
use std::fs;
use std::env;
@@ -17,6 +18,46 @@ use std::default::Default;
const FIELD_SEP: char = '.';
pub enum CallType {
Upload(UploadProtocol),
Standard,
}
pub enum UploadProtocol {
Simple,
Resumable,
}
impl AsRef<str> for UploadProtocol {
fn as_ref(&self) -> &str {
match *self {
UploadProtocol::Simple => "simple",
UploadProtocol::Resumable => "resumable"
}
}
}
impl AsRef<str> for CallType {
fn as_ref(&self) -> &str {
match *self {
CallType::Upload(ref proto) => proto.as_ref(),
CallType::Standard => "standard-request"
}
}
}
impl FromStr for UploadProtocol {
type Err = String;
fn from_str(s: &str) -> Result<UploadProtocol, String> {
match s {
"simple" => Ok(UploadProtocol::Simple),
"resumable" => Ok(UploadProtocol::Resumable),
_ => Err(format!("Protocol '{}' is unknown", s)),
}
}
}
#[derive(Clone, Default)]
pub struct FieldCursor(Vec<String>);
@@ -112,6 +153,17 @@ pub fn parse_kv_arg<'a>(kv: &'a str, err: &mut InvalidOptionsError, for_hashmap:
}
}
pub fn protocol_from_str(name: &str, valid_protocols: Vec<String>, err: &mut InvalidOptionsError) -> CallType {
CallType::Upload(
match UploadProtocol::from_str(name) {
Ok(up) => up,
Err(msg) => {
err.issues.push(CLIError::InvalidUploadProtocol(name.to_string(), valid_protocols));
UploadProtocol::Simple
}
})
}
pub fn input_file_from_opts(file_path: &str, err: &mut InvalidOptionsError) -> Option<fs::File> {
match fs::File::open(file_path) {
Ok(f) => Some(f),
@@ -132,13 +184,14 @@ pub fn input_mime_from_opts(mime: &str, err: &mut InvalidOptionsError) -> Option
}
}
// May panic if we can't open the file - this is anticipated, we can't currently communicate this
// kind of error: TODO: fix this architecture :)
pub fn writer_from_opts(flag: bool, arg: &str) -> Box<Write> {
if !flag || arg == "-" {
Box::new(stdout())
} else {
Box::new(fs::OpenOptions::new().create(true).write(true).open(arg).unwrap())
pub fn writer_from_opts(arg: Option<&str>) -> Result<Box<Write>, io::Error> {
let f = arg.unwrap_or("-");
match f {
"-" => Ok(Box::new(stdout())),
_ => match fs::OpenOptions::new().create(true).write(true).open(f) {
Ok(f) => Ok(Box::new(f)),
Err(io_err) => Err(io_err),
}
}
}
@@ -151,7 +204,7 @@ pub fn arg_from_str<T>(arg: &str, err: &mut InvalidOptionsError,
match FromStr::from_str(arg) {
Err(perr) => {
err.issues.push(
CLIError::ParseError((arg_name, arg_type, arg.to_string(), format!("{}", perr)))
CLIError::ParseError(arg_name, arg_type, arg.to_string(), format!("{}", perr))
);
Default::default()
},
@@ -171,49 +224,47 @@ impl JsonTokenStorage {
}
impl TokenStorage for JsonTokenStorage {
type Error = io::Error;
type Error = json::Error;
// NOTE: logging might be interesting, currently we swallow all errors
fn set(&mut self, scope_hash: u64, _: &Vec<&str>, token: Option<Token>) -> Option<io::Error> {
fn set(&mut self, scope_hash: u64, _: &Vec<&str>, token: Option<Token>) -> Result<(), json::Error> {
match token {
None => {
match fs::remove_file(self.path(scope_hash)) {
Err(err) =>
match err.kind() {
io::ErrorKind::NotFound => None,
_ => Some(err)
io::ErrorKind::NotFound => Ok(()),
_ => Err(json::Error::IoError(err))
},
Ok(_) => None
Ok(_) => Ok(()),
}
}
Some(token) => {
let json_token = json::encode(&token).unwrap();
match fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)) {
Ok(mut f) => {
match f.write(json_token.as_bytes()) {
Ok(_) => None,
Err(io_err) => Some(io_err),
match json::to_writer_pretty(&mut f, &token) {
Ok(_) => Ok(()),
Err(io_err) => Err(json::Error::IoError(io_err)),
}
},
Err(io_err) => Some(io_err)
Err(io_err) => Err(json::Error::IoError(io_err))
}
}
}
}
fn get(&self, scope_hash: u64, _: &Vec<&str>) -> Result<Option<Token>, io::Error> {
fn get(&self, scope_hash: u64, _: &Vec<&str>) -> Result<Option<Token>, json::Error> {
match fs::File::open(&self.path(scope_hash)) {
Ok(mut f) => {
let mut json_string = String::new();
match f.read_to_string(&mut json_string) {
Ok(_) => Ok(Some(json::decode::<Token>(&json_string).unwrap())),
Err(io_err) => Err(io_err),
match json::de::from_reader(f) {
Ok(token) => Ok(Some(token)),
Err(err) => Err(err),
}
},
Err(io_err) => {
match io_err.kind() {
io::ErrorKind::NotFound => Ok(None),
_ => Err(io_err)
_ => Err(json::Error::IoError(io_err))
}
}
}
@@ -223,7 +274,7 @@ impl TokenStorage for JsonTokenStorage {
#[derive(Debug)]
pub enum ApplicationSecretError {
DecoderError((String, json::DecoderError)),
DecoderError((String, json::Error)),
FormatError(String),
}
@@ -311,11 +362,14 @@ impl fmt::Display for FieldError {
#[derive(Debug)]
pub enum CLIError {
Configuration(ConfigurationError),
ParseError((&'static str, &'static str, String, String)),
ParseError(&'static str, &'static str, String, String),
UnknownParameter(String),
InvalidUploadProtocol(String, Vec<String>),
InvalidKeyValueSyntax(String, bool),
Input(InputError),
Field(FieldError),
MissingCommandError,
MissingMethodError(String),
}
impl fmt::Display for CLIError {
@@ -324,7 +378,9 @@ impl fmt::Display for CLIError {
CLIError::Configuration(ref err) => write!(f, "Configuration -> {}", err),
CLIError::Input(ref err) => write!(f, "Input -> {}", err),
CLIError::Field(ref err) => write!(f, "Field -> {}", err),
CLIError::ParseError((arg_name, type_name, ref value, ref err_desc))
CLIError::InvalidUploadProtocol(ref proto_name, ref valid_names)
=> writeln!(f, "'{}' is not a valid upload protocol. Choose from one of {}", proto_name, valid_names.connect(", ")),
CLIError::ParseError(arg_name, type_name, ref value, ref err_desc)
=> writeln!(f, "Failed to parse argument '{}' with value '{}' as {} with error: {}",
arg_name, value, type_name, err_desc),
CLIError::UnknownParameter(ref param_name)
@@ -333,6 +389,8 @@ impl fmt::Display for CLIError {
let hashmap_info = if is_hashmap { "hashmap " } else { "" };
writeln!(f, "'{}' does not match {}pattern <key>=<value>", kv, hashmap_info)
},
CLIError::MissingCommandError => writeln!(f, "Please specify the main sub-command"),
CLIError::MissingMethodError(ref cmd) => writeln!(f, "Please specify the method to call on the '{}' command", cmd),
}
}
}
@@ -399,7 +457,7 @@ pub fn assure_config_dir_exists(dir: &str) -> Result<String, CLIError> {
pub fn application_secret_from_directory(dir: &str,
secret_basename: &str,
json_app_secret: &str)
json_console_secret: &str)
-> Result<ApplicationSecret, CLIError> {
let secret_path = Path::new(dir).join(secret_basename);
let secret_str = || secret_path.as_path().to_str().unwrap().to_string();
@@ -418,7 +476,10 @@ pub fn application_secret_from_directory(dir: &str,
err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) {
Err(cfe) => cfe,
Ok(mut f) => {
match f.write(json_app_secret.as_bytes()) {
// Assure we convert 'ugly' json string into pretty one
let console_secret: ConsoleApplicationSecret
= json::from_str(json_console_secret).unwrap();
match json::to_writer_pretty(&mut f, &console_secret) {
Err(io_err) => io_err,
Ok(_) => continue,
}
@@ -429,23 +490,24 @@ pub fn application_secret_from_directory(dir: &str,
return secret_io_error(err)
},
Ok(mut f) => {
let mut json_encoded_secret = String::new();
if let Err(io_err) = f.read_to_string(&mut json_encoded_secret) {
return secret_io_error(io_err)
}
match json::decode::<ConsoleApplicationSecret>(&json_encoded_secret) {
Err(json_decode_error) => return Err(CLIError::Configuration(
ConfigurationError::Secret(ApplicationSecretError::DecoderError(
(secret_str(), json_decode_error)
match json::de::from_reader::<_, ConsoleApplicationSecret>(f) {
Err(json::Error::IoError(err)) =>
return secret_io_error(err),
Err(json_err) =>
return Err(CLIError::Configuration(
ConfigurationError::Secret(
ApplicationSecretError::DecoderError(
(secret_str(), json_err)
)))),
Ok(console_secret) => match console_secret.installed {
Some(secret) => return Ok(secret),
None => return Err(
CLIError::Configuration(
ConfigurationError::Secret(
ApplicationSecretError::FormatError(secret_str())
)))
},
Ok(console_secret) =>
match console_secret.installed {
Some(secret) => return Ok(secret),
None => return Err(
CLIError::Configuration(
ConfigurationError::Secret(
ApplicationSecretError::FormatError(secret_str())
)))
},
}
}
}

View File

@@ -2,13 +2,11 @@
// This file was generated automatically from 'src/mako/cli/main.rs.mako'
// DO NOT EDIT !
#![feature(plugin, exit_status)]
#![plugin(docopt_macros)]
#![allow(unused_variables, unused_imports, dead_code, unused_mut)]
extern crate docopt;
extern crate clap;
extern crate yup_oauth2 as oauth2;
extern crate yup_hyper_mock as mock;
extern crate rustc_serialize;
extern crate serde;
extern crate hyper;
extern crate mime;
@@ -16,53 +14,37 @@ extern crate google_groupsmigration1 as api;
use std::env;
use std::io::{self, Write};
docopt!(Options derive Debug, "
Usage:
groupsmigration1 [options] archive insert <group-id> -u (simple|resumable) <file> <mime> [-p <v>...] [-o <out>]
groupsmigration1 --help
All documentation details can be found at
http://byron.github.io/google-apis-rs/google_groupsmigration1_cli/index.html
Configuration:
--scope <url>
Specify the authentication a method should be executed in. Each scope
requires the user to grant this application permission to use it.
If unset, it defaults to the shortest scope url for a particular method.
--config-dir <folder>
A directory into which we will store our persistent data. Defaults to
a user-writable directory that we will create during the first invocation.
[default: ~/.google-service-cli]
--debug
Output all server communication to standard error. `tx` and `rx` are placed
into the same stream.
--debug-auth
Output all communication related to authentication to standard error. `tx`
and `rx` are placed into the same stream.
");
use clap::{App, SubCommand, Arg};
mod cmn;
use cmn::{InvalidOptionsError, CLIError, JsonTokenStorage, arg_from_str, writer_from_opts, parse_kv_arg,
input_file_from_opts, input_mime_from_opts, FieldCursor, FieldError};
input_file_from_opts, input_mime_from_opts, FieldCursor, FieldError, CallType, UploadProtocol,
protocol_from_str};
use std::default::Default;
use std::str::FromStr;
use oauth2::{Authenticator, DefaultAuthenticatorDelegate};
use rustc_serialize::json;
use serde::json;
use clap::ArgMatches;
struct Engine {
opt: Options,
enum DoitError {
IoError(String, io::Error),
ApiError(api::Error),
}
struct Engine<'n, 'a> {
opt: ArgMatches<'n, 'a>,
hub: api::GroupsMigration<hyper::Client, Authenticator<DefaultAuthenticatorDelegate, JsonTokenStorage, hyper::Client>>,
}
impl Engine {
fn _archive_insert(&self, dry_run: bool, err: &mut InvalidOptionsError)
-> Option<api::Error> {
let mut call = self.hub.archive().insert(&self.opt.arg_group_id);
for parg in self.opt.arg_v.iter() {
impl<'n, 'a> Engine<'n, 'a> {
fn _archive_insert(&self, opt: &ArgMatches<'n, 'a>, dry_run: bool, err: &mut InvalidOptionsError)
-> Result<(), DoitError> {
let mut call = self.hub.archive().insert(opt.value_of("group-id").unwrap_or(""));
for parg in opt.values_of("v").unwrap_or(Vec::new()).iter() {
let (key, value) = parse_kv_arg(&*parg, err, false);
match key {
"alt"
@@ -83,65 +65,71 @@ impl Engine {
_ => err.issues.push(CLIError::UnknownParameter(key.to_string())),
}
}
let protocol =
if self.opt.cmd_simple {
"simple"
} else if self.opt.cmd_resumable {
"resumable"
} else {
unreachable!()
};
let mut input_file = input_file_from_opts(&self.opt.arg_file, err);
let mime_type = input_mime_from_opts(&self.opt.arg_mime, err);
let vals = opt.values_of("mode").unwrap();
let protocol = protocol_from_str(vals[0], ["simple", "resumable"].iter().map(|&v| v.to_string()).collect(), err);
let mut input_file = input_file_from_opts(vals[1], err);
let mime_type = input_mime_from_opts(opt.value_of("mime").unwrap_or("application/octet-stream"), err);
if dry_run {
None
Ok(())
} else {
assert!(err.issues.len() == 0);
if self.opt.flag_scope.len() > 0 {
call = call.add_scope(&self.opt.flag_scope);
for scope in self.opt.values_of("url").unwrap_or(Vec::new()).iter() {
call = call.add_scope(scope);
}
let mut ostream = writer_from_opts(self.opt.flag_o, &self.opt.arg_out);
let mut ostream = match writer_from_opts(opt.value_of("out")) {
Ok(mut f) => f,
Err(io_err) => return Err(DoitError::IoError(opt.value_of("out").unwrap_or("-").to_string(), io_err)),
};
match match protocol {
"simple" => call.upload(input_file.unwrap(), mime_type.unwrap()),
"resumable" => call.upload_resumable(input_file.unwrap(), mime_type.unwrap()),
_ => unreachable!(),
CallType::Upload(UploadProtocol::Simple) => call.upload(input_file.unwrap(), mime_type.unwrap()),
CallType::Upload(UploadProtocol::Resumable) => call.upload_resumable(input_file.unwrap(), mime_type.unwrap()),
CallType::Standard => unreachable!()
} {
Err(api_err) => Some(api_err),
Err(api_err) => Err(DoitError::ApiError(api_err)),
Ok((mut response, output_schema)) => {
serde::json::to_writer_pretty(&mut ostream, &output_schema).unwrap();
None
Ok(())
}
}
}
}
fn _doit(&self, dry_run: bool) -> (Option<api::Error>, Option<InvalidOptionsError>) {
fn _doit(&self, dry_run: bool) -> Result<Result<(), DoitError>, Option<InvalidOptionsError>> {
let mut err = InvalidOptionsError::new();
let mut call_result: Option<api::Error>;
let mut call_result: Result<(), DoitError> = Ok(());
let mut err_opt: Option<InvalidOptionsError> = None;
if self.opt.cmd_archive {
if self.opt.cmd_insert {
call_result = self._archive_insert(dry_run, &mut err);
} else {
unreachable!();
match self.opt.subcommand() {
("archive", Some(opt)) => {
match opt.subcommand() {
("insert", Some(opt)) => {
call_result = self._archive_insert(opt, dry_run, &mut err);
},
_ => {
err.issues.push(CLIError::MissingMethodError("archive".to_string()));
writeln!(io::stderr(), "{}\n", opt.usage()).ok();
}
}
},
_ => {
err.issues.push(CLIError::MissingCommandError);
writeln!(io::stderr(), "{}\n", self.opt.usage()).ok();
}
} else {
unreachable!();
}
if dry_run {
if err.issues.len() > 0 {
err_opt = Some(err);
}
Err(err_opt)
} else {
Ok(call_result)
}
(call_result, err_opt)
}
// Please note that this call will fail if any part of the opt can't be handled
fn new(opt: Options) -> Result<Engine, InvalidOptionsError> {
fn new(opt: ArgMatches<'a, 'n>) -> Result<Engine<'a, 'n>, InvalidOptionsError> {
let (config_dir, secret) = {
let config_dir = match cmn::assure_config_dir_exists(&opt.flag_config_dir) {
let config_dir = match cmn::assure_config_dir_exists(opt.value_of("folder").unwrap_or("~/.google-service-cli")) {
Err(e) => return Err(InvalidOptionsError::single(e, 3)),
Ok(p) => p,
};
@@ -154,7 +142,7 @@ impl Engine {
};
let auth = Authenticator::new( &secret, DefaultAuthenticatorDelegate,
if opt.flag_debug_auth {
if opt.is_present("debug-auth") {
hyper::Client::with_connector(mock::TeeConnector {
connector: hyper::net::HttpConnector(None)
})
@@ -167,7 +155,7 @@ impl Engine {
}, None);
let client =
if opt.flag_debug {
if opt.is_present("debug") {
hyper::Client::with_connector(mock::TeeConnector {
connector: hyper::net::HttpConnector(None)
})
@@ -180,34 +168,153 @@ impl Engine {
};
match engine._doit(true) {
(_, Some(err)) => Err(err),
_ => Ok(engine),
Err(Some(err)) => Err(err),
Err(None) => Ok(engine),
Ok(_) => unreachable!(),
}
}
// Execute the call with all the bells and whistles, informing the caller only if there was an error.
// The absense of one indicates success.
fn doit(&self) -> Option<api::Error> {
self._doit(false).0
fn doit(&self) -> Result<(), DoitError> {
match self._doit(false) {
Ok(res) => res,
Err(_) => unreachable!(),
}
}
}
fn main() {
let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit());
let debug = opts.flag_debug;
match Engine::new(opts) {
let upload_value_names = ["mode", "file"];
let arg_data = [
("archive", "methods: 'insert'", vec![
("insert", Some("Inserts a new mail into the archive of the Google group."),
vec![
(Some("group-id"),
None,
Some("The group ID"),
Some(true),
Some(false)),
(Some("mode"),
Some("u"),
Some("Specify the upload protocol (simple|resumable) and the file to upload"),
Some(true),
Some(true)),
(Some("v"),
Some("p"),
Some("Set various fields of the request structure"),
Some(false),
Some(true)),
(Some("out"),
Some("o"),
Some("Specify the file into which to write the programs output"),
Some(false),
Some(false)),
]),
]),
];
let mut app = App::new("groupsmigration1")
.author("Sebastian Thiel <byronimo@gmail.com>")
.version("0.2.0+20140416")
.about("Groups Migration Api.")
.after_help("All documentation details can be found at http://byron.github.io/google-apis-rs/google_groupsmigration1_cli")
.arg(Arg::with_name("url")
.long("scope")
.help("Specify the authentication a method should be executed in. Each scope requires the user to grant this application permission to use it.If unset, it defaults to the shortest scope url for a particular method.")
.multiple(true)
.takes_value(true))
.arg(Arg::with_name("folder")
.long("config-dir")
.help("A directory into which we will store our persistent data. Defaults to a user-writable directory that we will create during the first invocation.[default: ~/.google-service-cli")
.multiple(false)
.takes_value(true))
.arg(Arg::with_name("debug")
.long("debug")
.help("Output all server communication to standard error. `tx` and `rx` are placed into the same stream.")
.multiple(false)
.takes_value(false))
.arg(Arg::with_name("debug-auth")
.long("debug-auth")
.help("Output all communication related to authentication to standard error. `tx` and `rx` are placed into the same stream.")
.multiple(false)
.takes_value(false));
for &(main_command_name, ref about, ref subcommands) in arg_data.iter() {
let mut mcmd = SubCommand::new(main_command_name).about(about);
for &(sub_command_name, ref desc, ref args) in subcommands {
let mut scmd = SubCommand::new(sub_command_name);
if let &Some(desc) = desc {
scmd = scmd.about(desc);
}
for &(ref arg_name, ref flag, ref desc, ref required, ref multi) in args {
let arg_name_str =
match (arg_name, flag) {
(&Some(an), _ ) => an,
(_ , &Some(f)) => f,
_ => unreachable!(),
};
let mut arg = Arg::with_name(arg_name_str);
if let &Some(short_flag) = flag {
arg = arg.short(short_flag);
}
if let &Some(desc) = desc {
arg = arg.help(desc);
}
if arg_name.is_some() && flag.is_some() {
arg = arg.takes_value(true);
}
if let &Some(required) = required {
arg = arg.required(required);
}
if let &Some(multi) = multi {
arg = arg.multiple(multi);
}
if arg_name_str == "mode" {
arg = arg.number_of_values(2);
arg = arg.value_names(&upload_value_names);
scmd = scmd.arg(Arg::with_name("mime")
.short("m")
.requires("mode")
.required(false)
.help("The file's mime time, like 'application/octet-stream'")
.takes_value(true));
}
scmd = scmd.arg(arg);
}
mcmd = mcmd.subcommand(scmd);
}
app = app.subcommand(mcmd);
}
let matches = app.get_matches();
let debug = matches.is_present("debug");
match Engine::new(matches) {
Err(err) => {
writeln!(io::stderr(), "{}", err).ok();
env::set_exit_status(err.exit_code);
writeln!(io::stderr(), "{}", err).ok();
},
Ok(engine) => {
if let Some(err) = engine.doit() {
if debug {
writeln!(io::stderr(), "{:?}", err).ok();
} else {
writeln!(io::stderr(), "{}", err).ok();
}
if let Err(doit_err) = engine.doit() {
env::set_exit_status(1);
match doit_err {
DoitError::IoError(path, err) => {
writeln!(io::stderr(), "Failed to open output file '{}': {}", path, err).ok();
},
DoitError::ApiError(err) => {
if debug {
writeln!(io::stderr(), "{:?}", err).ok();
} else {
writeln!(io::stderr(), "{}", err).ok();
}
}
}
}
}
}

View File

@@ -4,7 +4,7 @@
[package]
name = "google-groupsmigration1"
version = "0.1.6+20140416"
version = "0.1.7+20140416"
authors = ["Sebastian Thiel <byronimo@gmail.com>"]
description = "A complete library to interact with Groups Migration (protocol v1)"
repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/groupsmigration1"

View File

@@ -5,7 +5,7 @@ DO NOT EDIT !
-->
The `google-groupsmigration1` library allows access to all features of the *Google Groups Migration* service.
This documentation was generated from *Groups Migration* crate version *0.1.6+20140416*, where *20140416* is the exact revision of the *groupsmigration:v1* schema built by the [mako](http://www.makotemplates.org/) code generator *v0.1.6*.
This documentation was generated from *Groups Migration* crate version *0.1.7+20140416*, where *20140416* is the exact revision of the *groupsmigration:v1* schema built by the [mako](http://www.makotemplates.org/) code generator *v0.1.7*.
Everything else about the *Groups Migration* *v1* API can be found at the
[official documentation site](https://developers.google.com/google-apps/groups-migration/).
@@ -162,7 +162,7 @@ These will always take a single argument, for which the following statements are
* [PODs][wiki-pod] are handed by copy
* strings are passed as `&str`
* [request values](http://byron.github.io/google-apis-rs/google_groupsmigration1/trait.RequestValue.html) are borrowed
* [request values](http://byron.github.io/google-apis-rs/google_groupsmigration1/trait.RequestValue.html) are moved
Arguments will always be copied or cloned into the builder, to make them independent of their original life times.

View File

@@ -43,7 +43,7 @@ pub trait RequestValue {}
/// This might be a bug within the google API schema.
pub trait UnusedType {}
/// Identifies types which are only used as part of other types, which
/// Identifies types which are only used as part of other types, which
/// usually are carrying the `Resource` trait.
pub trait Part {}
@@ -78,7 +78,7 @@ pub struct ErrorResponse {
pub struct ServerError {
errors: Vec<ServerMessage>,
code: u16,
message: String,
message: String,
}
#[derive(Deserialize, Serialize, Debug)]
@@ -120,7 +120,7 @@ impl hyper::net::NetworkStream for DummyNetworkStream {
/// A trait specifying functionality to help controlling any request performed by the API.
/// The trait has a conservative default implementation.
///
/// It contains methods to deal with all common issues, as well with the ones related to
/// It contains methods to deal with all common issues, as well with the ones related to
/// uploading media
pub trait Delegate {
@@ -128,12 +128,12 @@ pub trait Delegate {
/// information if he is interesting in knowing more context when further calls to it
/// are made.
/// The matching `finished()` call will always be made, no matter whether or not the API
/// request was successful. That way, the delegate may easily maintain a clean state
/// request was successful. That way, the delegate may easily maintain a clean state
/// between various API calls.
fn begin(&mut self, MethodInfo) {}
/// Called whenever there is an [HttpError](http://hyperium.github.io/hyper/hyper/error/enum.HttpError.html), usually if there are network problems.
///
///
/// If you choose to retry after a duration, the duration should be chosen using the
/// [exponential backoff algorithm](http://en.wikipedia.org/wiki/Exponential_backoff).
///
@@ -142,7 +142,7 @@ pub trait Delegate {
Retry::Abort
}
/// Called whenever there is the need for your applications API key after
/// Called whenever there is the need for your applications API key after
/// the official authenticator implementation didn't provide one, for some reason.
/// If this method returns None as well, the underlying operation will fail
fn api_key(&mut self) -> Option<String> {
@@ -171,16 +171,19 @@ pub trait Delegate {
}
/// Called after we have retrieved a new upload URL for a resumable upload to store it
/// in case we fail or cancel. That way, we can attempt to resume the upload later,
/// in case we fail or cancel. That way, we can attempt to resume the upload later,
/// see `upload_url()`.
fn store_upload_url(&mut self, url: &str) {
/// It will also be called with None after a successful upload, which allows the delegate
/// to forget the URL. That way, we will not attempt to resume an upload that has already
/// finished.
fn store_upload_url(&mut self, url: Option<&str>) {
let _ = url;
}
/// Called whenever a server response could not be decoded from json.
/// It's for informational purposes only, the caller will return with an error
/// accordingly.
///
///
/// # Arguments
///
/// * `json_encoded_value` - The json-encoded value which failed to decode.
@@ -191,7 +194,7 @@ pub trait Delegate {
}
/// Called whenever the http request returns with a non-success status code.
/// This can involve authentication issues, or anything else that very much
/// This can involve authentication issues, or anything else that very much
/// depends on the used API method.
/// The delegate should check the status, header and decoded json error to decide
/// whether to retry or not. In the latter case, the underlying call will fail.
@@ -202,7 +205,7 @@ pub trait Delegate {
Retry::Abort
}
/// Called prior to sending the main request of the given method. It can be used to time
/// Called prior to sending the main request of the given method. It can be used to time
/// the call or to print progress information.
/// It's also useful as you can be sure that a request will definitely be made.
fn pre_request(&mut self) { }
@@ -221,14 +224,14 @@ pub trait Delegate {
fn cancel_chunk_upload(&mut self, chunk: &ContentRange) -> bool {
let _ = chunk;
false
}
}
/// Called before the API request method returns, in every case. It can be used to clean up
/// internal state between calls to the API.
/// This call always has a matching call to `begin(...)`.
///
/// # Arguments
///
///
/// * `is_success` - a true value indicates the operation was successful. If false, you should
/// discard all values stored during `store_upload_url`.
fn finished(&mut self, is_success: bool) {
@@ -290,17 +293,17 @@ impl Display for Error {
writeln!(f, "The application's API key was not found in the configuration").ok();
writeln!(f, "It is used as there are no Scopes defined for this method.")
},
Error::BadRequest(ref err)
Error::BadRequest(ref err)
=> writeln!(f, "Bad Requst ({}): {}", err.error.code, err.error.message),
Error::MissingToken(ref err) =>
writeln!(f, "Token retrieval failed with error: {}", err),
Error::Cancelled =>
Error::Cancelled =>
writeln!(f, "Operation cancelled by delegate"),
Error::FieldClash(field) =>
writeln!(f, "The custom parameter '{}' is already provided natively by the CallBuilder.", field),
Error::JsonDecodeError(ref json_str, ref err)
Error::JsonDecodeError(ref json_str, ref err)
=> writeln!(f, "{}: {}", err, json_str),
Error::Failure(ref response) =>
Error::Failure(ref response) =>
writeln!(f, "Http status indicates failure: {:?}", response),
}
}
@@ -395,8 +398,8 @@ impl<'a> MultiPartReader<'a> {
impl<'a> Read for MultiPartReader<'a> {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
match (self.raw_parts.len(),
self.current_part.is_none(),
match (self.raw_parts.len(),
self.current_part.is_none(),
self.last_part_boundary.is_none()) {
(_, _, false) => {
let br = self.last_part_boundary.as_mut().unwrap().read(buf).unwrap_or(0);
@@ -409,7 +412,7 @@ impl<'a> Read for MultiPartReader<'a> {
(n, true, _) if n > 0 => {
let (headers, reader) = self.raw_parts.remove(0);
let mut c = Cursor::new(Vec::<u8>::new());
write!(&mut c, "{}--{}{}{}{}", LINE_ENDING, BOUNDARY, LINE_ENDING,
write!(&mut c, "{}--{}{}{}{}", LINE_ENDING, BOUNDARY, LINE_ENDING,
headers, LINE_ENDING).unwrap();
c.seek(SeekFrom::Start(0)).unwrap();
self.current_part = Some((c, reader));
@@ -423,12 +426,12 @@ impl<'a> Read for MultiPartReader<'a> {
let b = c.read(buf).unwrap_or(0);
(b, reader.read(&mut buf[b..]))
};
match rr {
Ok(bytes_read) => {
if hb < buf.len() && bytes_read == 0 {
if self.is_last_part() {
// before clearing the last part, we will add the boundary that
// before clearing the last part, we will add the boundary that
// will be written last
self.last_part_boundary = Some(Cursor::new(
format!("{}--{}--", LINE_ENDING, BOUNDARY).into_bytes()))
@@ -459,6 +462,16 @@ impl<'a> Read for MultiPartReader<'a> {
header!{
#[doc="The `X-Upload-Content-Type` header."]
(XUploadContentType, "X-Upload-Content-Type") => [Mime]
xupload_content_type {
test_header!(
test1,
vec![b"text/plain"],
Some(HeaderField(
vec![Mime(TopLevel::Text, SubLevel::Plain, Vec::new())]
)));
}
}
#[derive(Clone, PartialEq, Debug)]
@@ -656,7 +669,7 @@ impl<'a, A> ResumableUploadHelper<'a, A>
if !res.status.is_success() {
let mut json_err = String::new();
res.read_to_string(&mut json_err).unwrap();
if let Retry::After(d) = self.delegate.http_failure(&res,
if let Retry::After(d) = self.delegate.http_failure(&res,
serde::json::from_str(&json_err).ok(),
serde::json::from_str(&json_err).ok()) {
sleep_ms(d.num_milliseconds() as u32);
@@ -675,4 +688,4 @@ impl<'a, A> ResumableUploadHelper<'a, A>
}
}
}
}
}

View File

@@ -2,31 +2,31 @@
// 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.6+20140416*, where *20140416* is the exact revision of the *groupsmigration:v1* schema built by the [mako](http://www.makotemplates.org/) code generator *v0.1.6*.
//!
//! This documentation was generated from *Groups Migration* crate version *0.1.7+20140416*, where *20140416* is the exact revision of the *groupsmigration:v1* schema built by the [mako](http://www.makotemplates.org/) code generator *v0.1.7*.
//!
//! Everything else about the *Groups Migration* *v1* API can be found at the
//! [official documentation site](https://developers.google.com/google-apps/groups-migration/).
//! The original source code is [on github](https://github.com/Byron/google-apis-rs/tree/master/gen/groupsmigration1).
//! # Features
//!
//! Handle the following *Resources* with ease from the central [hub](struct.GroupsMigration.html) ...
//!
//!
//! Handle the following *Resources* with ease from the central [hub](struct.GroupsMigration.html) ...
//!
//! * archive
//! * [*insert*](struct.ArchiveInsertCall.html)
//!
//!
//!
//!
//! Upload supported by ...
//!
//!
//! * [*insert archive*](struct.ArchiveInsertCall.html)
//!
//!
//!
//!
//!
//!
//! Not what you are looking for ? Find all other Google APIs in their Rust [documentation index](../index.html).
//!
//!
//! # Structure of this Library
//!
//!
//! The API is structured into the following primary items:
//!
//!
//! * **[Hub](struct.GroupsMigration.html)**
//! * a central object to maintain state and allow accessing all *Activities*
//! * creates [*Method Builders*](trait.MethodsBuilder.html) which in turn
@@ -39,39 +39,39 @@
//! * never directly used in *Activities*
//! * **[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
//! let r = hub.resource().activity(...).doit()
//! ```
//!
//!
//! Or specifically ...
//!
//!
//! ```ignore
//! let r = hub.archive().insert(...).doit()
//! ```
//!
//! The `resource()` and `activity(...)` calls create [builders][builder-pattern]. The second one dealing with `Activities`
//! supports various methods to configure the impending operation (not shown here). It is made such that all required arguments have to be
//!
//! The `resource()` and `activity(...)` calls create [builders][builder-pattern]. The second one dealing with `Activities`
//! supports various methods to configure the impending operation (not shown here). It is made such that all required arguments have to be
//! specified right away (i.e. `(...)`), whereas all optional ones can be [build up][builder-pattern] as desired.
//! The `doit()` method performs the actual communication with the server and returns the respective result.
//!
//!
//! # Usage
//!
//!
//! ## Setting up your Project
//!
//!
//! To use this library, you would put the following lines into your `Cargo.toml` file:
//!
//!
//! ```toml
//! [dependencies]
//! google-groupsmigration1 = "*"
//! ```
//!
//!
//! ## A complete example
//!
//!
//! ```test_harness,no_run
//! extern crate hyper;
//! extern crate yup_oauth2 as oauth2;
@@ -82,13 +82,13 @@
//! use std::default::Default;
//! use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage};
//! use groupsmigration1::GroupsMigration;
//!
//! // Get an ApplicationSecret instance by some means. It contains the `client_id` and
//!
//! // Get an ApplicationSecret instance by some means. It contains the `client_id` and
//! // `client_secret`, among other things.
//! let secret: ApplicationSecret = Default::default();
//! // Instantiate the authenticator. It will choose a suitable authentication flow for you,
//! // Instantiate the authenticator. It will choose a suitable authentication flow for you,
//! // unless you replace `None` with the desired Flow.
//! // Provide your own `AuthenticatorDelegate` to adjust the way it operates and get feedback about
//! // Provide your own `AuthenticatorDelegate` to adjust the way it operates and get feedback about
//! // what's going on. You probably want to bring in your own `TokenStorage` to persist tokens and
//! // retrieve them from storage.
//! let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate,
@@ -100,7 +100,7 @@
//! // Values shown here are possibly random and not representative !
//! let result = hub.archive().insert("groupId")
//! .upload(fs::File::open("file.ext").unwrap(), "application/octet-stream".parse().unwrap());
//!
//!
//! match result {
//! Err(e) => match e {
//! // The Error enum provides details about what exactly happened.
@@ -120,62 +120,61 @@
//! # }
//! ```
//! ## Handling Errors
//!
//! All errors produced by the system are provided either as [Result](enum.Result.html) enumeration as return value of
//! the doit() methods, or handed as possibly intermediate results to either the
//!
//! All errors produced by the system are provided either as [Result](enum.Result.html) enumeration as return value of
//! the doit() methods, or handed as possibly intermediate results to either the
//! [Hub Delegate](trait.Delegate.html), or the [Authenticator Delegate](../yup-oauth2/trait.AuthenticatorDelegate.html).
//!
//! When delegates handle errors or intermediate values, they may have a chance to instruct the system to retry. This
//!
//! 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 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.
//! 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: `.param("alt", "media")`.
//!
//! Methods supporting uploads can do so using up to 2 different protocols:
//! *simple* and *resumable*. The distinctiveness of each is represented by customized
//!
//! Methods supporting uploads can do so using up to 2 different protocols:
//! *simple* and *resumable*. The distinctiveness of each is represented by customized
//! `doit(...)` methods, which are then named `upload(...)` and `upload_resumable(...)` respectively.
//!
//!
//! ## Customization and Callbacks
//!
//! You may alter the way an `doit()` method is called by providing a [delegate](trait.Delegate.html) to the
//! [Method Builder](trait.CallBuilder.html) before making the final `doit()` call.
//! Respective methods will be called to provide progress information, as well as determine whether the system should
//!
//! You may alter the way an `doit()` method is called by providing a [delegate](trait.Delegate.html) to the
//! [Method Builder](trait.CallBuilder.html) before making the final `doit()` call.
//! Respective methods will be called to provide progress information, as well as determine whether the system should
//! retry on failure.
//!
//!
//! The [delegate trait](trait.Delegate.html) is default-implemented, allowing you to customize it with minimal effort.
//!
//!
//! ## 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
//!
//! 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 identifiable by name, which will be sent to
//! 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
//!
//!
//! Using [method builders](trait.CallBuilder.html), you are able to prepare an action call by repeatedly calling it's methods.
//! These will always take a single argument, for which the following statements are true.
//!
//!
//! * [PODs][wiki-pod] are handed by copy
//! * strings are passed as `&str`
//! * [request values](trait.RequestValue.html) are borrowed
//!
//! * [request values](trait.RequestValue.html) are moved
//!
//! Arguments will always be copied or cloned into the builder, to make them independent of their original life times.
//!
//!
//! [wiki-pod]: http://en.wikipedia.org/wiki/Plain_old_data_structure
//! [builder-pattern]: http://en.wikipedia.org/wiki/Builder_pattern
//! [google-go-api]: https://github.com/google/google-api-go-client
//!
//!
#![feature(std_misc)]
//!
//!
// Unused attributes happen thanks to defined, but unused structures
// We don't warn about this, as depending on the API, some data structures or facilities are never used.
// Instead of pre-determining this, we just disable the lint. It's manually tuned to not have any
// Instead of pre-determining this, we just disable the lint. It's manually tuned to not have any
// unused imports in fully featured APIs. Same with unused_mut ... .
#![allow(unused_imports, unused_mut, dead_code)]
// Required for serde annotations
@@ -201,7 +200,10 @@ use std::io;
use std::fs;
use std::thread::sleep_ms;
pub use cmn::{MultiPartReader, ToParts, MethodInfo, Result, Error, CallBuilder, Hub, ReadSeek, Part, ResponseResult, RequestValue, NestedType, Delegate, DefaultDelegate, MethodsBuilder, Resource, ErrorResponse};
pub use cmn::{MultiPartReader, ToParts, MethodInfo, Result, Error,
CallBuilder, Hub, ReadSeek, Part, ResponseResult,
RequestValue, NestedType, Delegate, DefaultDelegate,
MethodsBuilder, Resource, ErrorResponse};
// ##############
@@ -305,7 +307,7 @@ impl<'a, C, A> GroupsMigration<C, A>
GroupsMigration {
client: RefCell::new(client),
auth: RefCell::new(authenticator),
_user_agent: "google-api-rust-client/0.1.6".to_string(),
_user_agent: "google-api-rust-client/0.1.7".to_string(),
}
}
@@ -314,7 +316,7 @@ impl<'a, C, A> GroupsMigration<C, A>
}
/// Set the user-agent header field to use in all requests to the server.
/// It defaults to `google-api-rust-client/0.1.6`.
/// It defaults to `google-api-rust-client/0.1.7`.
///
/// Returns the previously set user-agent.
pub fn user_agent(&mut self, agent_name: String) -> String {
@@ -391,7 +393,7 @@ pub struct ArchiveMethods<'a, C, A>
impl<'a, C, A> MethodsBuilder for ArchiveMethods<'a, C, A> {}
impl<'a, C, A> ArchiveMethods<'a, C, A> {
/// Create a builder to help you perform the following task:
///
/// Inserts a new mail into the archive of the Google group.
@@ -465,10 +467,16 @@ impl<'a, C, A> ArchiveInsertCall<'a, C, A> where C: BorrowMut<hyper::Client>, A:
/// Perform the operation you have build so far.
fn doit<RS>(mut self, mut reader: RS, reader_mime_type: mime::Mime, protocol: &'static str) -> Result<(hyper::client::Response, Groups)>
where RS: ReadSeek {
fn doit<RS>(mut self,
mut reader: RS,
reader_mime_type: mime::Mime,
protocol: &'static str)
-> Result<(hyper::client::Response, Groups)>
where RS: ReadSeek
{
use std::io::{Read, Seek};
use hyper::header::{ContentType, ContentLength, Authorization, UserAgent, Location};
use hyper::header::{ContentType, ContentLength, Authorization,
UserAgent, Location};
let mut dd = DefaultDelegate;
let mut dlg: &mut Delegate = match self._delegate {
Some(d) => d,
@@ -490,7 +498,7 @@ impl<'a, C, A> ArchiveInsertCall<'a, C, A> where C: BorrowMut<hyper::Client>, A:
params.push(("alt", "json".to_string()));
let (mut url, upload_type) =
let (mut url, upload_type) =
if protocol == "simple" {
("https://www.googleapis.com/upload/groups/v1/groups/{groupId}/archive".to_string(), "multipart")
} else if protocol == "resumable" {
@@ -527,7 +535,7 @@ impl<'a, C, A> ArchiveInsertCall<'a, C, A> where C: BorrowMut<hyper::Client>, A:
params.remove(index);
}
}
if params.len() > 0 {
url.push('?');
url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_ref()))));
@@ -568,7 +576,7 @@ impl<'a, C, A> ArchiveInsertCall<'a, C, A> where C: BorrowMut<hyper::Client>, A:
response
} else {
let mut client = &mut *self.hub.client.borrow_mut();
let mut req = client.borrow_mut().request(hyper::method::Method::Post, url.as_ref())
let mut req = client.borrow_mut().request(hyper::method::Method::Post, &url)
.header(UserAgent(self.hub._user_agent.clone()))
.header(auth_header.clone());
if protocol == "simple" {
@@ -626,7 +634,7 @@ impl<'a, C, A> ArchiveInsertCall<'a, C, A> where C: BorrowMut<hyper::Client>, A:
let upload_result = {
let url_str = &res.headers.get::<Location>().expect("Location header is part of protocol").0;
if upload_url_from_server {
dlg.store_upload_url(url_str);
dlg.store_upload_url(Some(url_str));
}
cmn::ResumableUploadHelper {
@@ -654,6 +662,7 @@ impl<'a, C, A> ArchiveInsertCall<'a, C, A> where C: BorrowMut<hyper::Client>, A:
Some(Ok(upload_result)) => {
res = upload_result;
if !res.status.is_success() {
dlg.store_upload_url(None);
dlg.finished(false);
return Err(Error::Failure(res))
}
@@ -685,8 +694,12 @@ impl<'a, C, A> ArchiveInsertCall<'a, C, A> where C: BorrowMut<hyper::Client>, A:
/// * *max size*: 16MB
/// * *multipart*: yes
/// * *valid mime types*: 'message/rfc822'
pub fn upload<RS>(self, stream: RS, mime_type: mime::Mime) -> Result<(hyper::client::Response, Groups)>
where RS: ReadSeek {
pub fn upload<RS>(self,
stream: RS,
mime_type: mime::Mime)
-> Result<(hyper::client::Response, Groups)>
where RS: ReadSeek
{
self.doit(stream, mime_type, "simple")
}
/// Upload media in a resumable fashion.
@@ -701,8 +714,12 @@ impl<'a, C, A> ArchiveInsertCall<'a, C, A> where C: BorrowMut<hyper::Client>, A:
/// * *max size*: 16MB
/// * *multipart*: yes
/// * *valid mime types*: 'message/rfc822'
pub fn upload_resumable<RS>(self, resumeable_stream: RS, mime_type: mime::Mime) -> Result<(hyper::client::Response, Groups)>
where RS: ReadSeek {
pub fn upload_resumable<RS>(self,
resumeable_stream: RS,
mime_type: mime::Mime)
-> Result<(hyper::client::Response, Groups)>
where RS: ReadSeek
{
self.doit(resumeable_stream, mime_type, "resumable")
}
@@ -744,7 +761,8 @@ impl<'a, C, A> ArchiveInsertCall<'a, C, A> where C: BorrowMut<hyper::Client>, A:
/// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
/// * *alt* (query-string) - Data format for the response.
pub fn param<T>(mut self, name: T, value: T) -> ArchiveInsertCall<'a, C, A>
where T: AsRef<str> {
where T: AsRef<str>
{
self._additional_params.insert(name.as_ref().to_string(), value.as_ref().to_string());
self
}
@@ -760,11 +778,10 @@ impl<'a, C, A> ArchiveInsertCall<'a, C, A> where C: BorrowMut<hyper::Client>, A:
/// Usually there is more than one suitable scope to authorize an operation, some of which may
/// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
/// sufficient, a read-write scope will do as well.
pub fn add_scope<T>(mut self, scope: T) -> ArchiveInsertCall<'a, C, A>
where T: AsRef<str> {
pub fn add_scope<T>(mut self, scope: T) -> ArchiveInsertCall<'a, C, A>
where T: AsRef<str>
{
self._scopes.insert(scope.as_ref().to_string(), ());
self
}
}

View File

@@ -21,7 +21,6 @@ hyper = "*"
mime = "*"
yup-oauth2 = "*"
clap = "*"
rustc-serialize = "*"
yup-hyper-mock = "*"
serde = ">= 0.3.0"
serde_macros = "*"

View File

@@ -18,76 +18,98 @@ Everything else about the *YouTube* API can be found at the
This documentation was generated from the *YouTube* API at revision *20150414*. The CLI is at version *0.2.0*.
```bash
youtube3 [options] activities insert -r <kv>... [-p <v>...] [-o <out>]
youtube3 [options] activities list <part> [-p <v>...] [-o <out>]
youtube3 [options] captions delete <id> [-p <v>...]
youtube3 [options] captions download <id> [-p <v>...] [-o <out>]
youtube3 [options] captions insert -r <kv>... -u (simple|resumable) <file> <mime> [-p <v>...] [-o <out>]
youtube3 [options] captions list <part> <video-id> [-p <v>...] [-o <out>]
youtube3 [options] captions update -r <kv>... -u (simple|resumable) <file> <mime> [-p <v>...] [-o <out>]
youtube3 [options] channel-banners insert -r <kv>... -u (simple|resumable) <file> <mime> [-p <v>...] [-o <out>]
youtube3 [options] channel-sections delete <id> [-p <v>...]
youtube3 [options] channel-sections insert -r <kv>... [-p <v>...] [-o <out>]
youtube3 [options] channel-sections list <part> [-p <v>...] [-o <out>]
youtube3 [options] channel-sections update -r <kv>... [-p <v>...] [-o <out>]
youtube3 [options] channels list <part> [-p <v>...] [-o <out>]
youtube3 [options] channels update -r <kv>... [-p <v>...] [-o <out>]
youtube3 [options] comment-threads insert -r <kv>... [-p <v>...] [-o <out>]
youtube3 [options] comment-threads list <part> [-p <v>...] [-o <out>]
youtube3 [options] comment-threads update -r <kv>... [-p <v>...] [-o <out>]
youtube3 [options] comments delete <id> [-p <v>...]
youtube3 [options] comments insert -r <kv>... [-p <v>...] [-o <out>]
youtube3 [options] comments list <part> [-p <v>...] [-o <out>]
youtube3 [options] comments mark-as-spam <id> [-p <v>...]
youtube3 [options] comments set-moderation-status <id> <moderation-status> [-p <v>...]
youtube3 [options] comments update -r <kv>... [-p <v>...] [-o <out>]
youtube3 [options] guide-categories list <part> [-p <v>...] [-o <out>]
youtube3 [options] i18n-languages list <part> [-p <v>...] [-o <out>]
youtube3 [options] i18n-regions list <part> [-p <v>...] [-o <out>]
youtube3 [options] live-broadcasts bind <id> <part> [-p <v>...] [-o <out>]
youtube3 [options] live-broadcasts control <id> <part> [-p <v>...] [-o <out>]
youtube3 [options] live-broadcasts delete <id> [-p <v>...]
youtube3 [options] live-broadcasts insert -r <kv>... [-p <v>...] [-o <out>]
youtube3 [options] live-broadcasts list <part> [-p <v>...] [-o <out>]
youtube3 [options] live-broadcasts transition <broadcast-status> <id> <part> [-p <v>...] [-o <out>]
youtube3 [options] live-broadcasts update -r <kv>... [-p <v>...] [-o <out>]
youtube3 [options] live-streams delete <id> [-p <v>...]
youtube3 [options] live-streams insert -r <kv>... [-p <v>...] [-o <out>]
youtube3 [options] live-streams list <part> [-p <v>...] [-o <out>]
youtube3 [options] live-streams update -r <kv>... [-p <v>...] [-o <out>]
youtube3 [options] playlist-items delete <id> [-p <v>...]
youtube3 [options] playlist-items insert -r <kv>... [-p <v>...] [-o <out>]
youtube3 [options] playlist-items list <part> [-p <v>...] [-o <out>]
youtube3 [options] playlist-items update -r <kv>... [-p <v>...] [-o <out>]
youtube3 [options] playlists delete <id> [-p <v>...]
youtube3 [options] playlists insert -r <kv>... [-p <v>...] [-o <out>]
youtube3 [options] playlists list <part> [-p <v>...] [-o <out>]
youtube3 [options] playlists update -r <kv>... [-p <v>...] [-o <out>]
youtube3 [options] search list <part> [-p <v>...] [-o <out>]
youtube3 [options] subscriptions delete <id> [-p <v>...]
youtube3 [options] subscriptions insert -r <kv>... [-p <v>...] [-o <out>]
youtube3 [options] subscriptions list <part> [-p <v>...] [-o <out>]
youtube3 [options] thumbnails set <video-id> -u (simple|resumable) <file> <mime> [-p <v>...] [-o <out>]
youtube3 [options] video-abuse-report-reasons list <part> [-p <v>...] [-o <out>]
youtube3 [options] video-categories list <part> [-p <v>...] [-o <out>]
youtube3 [options] videos delete <id> [-p <v>...]
youtube3 [options] videos get-rating <id> [-p <v>...] [-o <out>]
youtube3 [options] videos insert -r <kv>... -u (simple|resumable) <file> <mime> [-p <v>...] [-o <out>]
youtube3 [options] videos list <part> [-p <v>...] [-o <out>]
youtube3 [options] videos rate <id> <rating> [-p <v>...]
youtube3 [options] videos report-abuse -r <kv>... [-p <v>...]
youtube3 [options] videos update -r <kv>... [-p <v>...] [-o <out>]
youtube3 [options] watermarks set <channel-id> -r <kv>... -u (simple|resumable) <file> <mime> [-p <v>...]
youtube3 [options] watermarks unset <channel-id> [-p <v>...]
youtube3 [options]
activities
insert (-r <kv>)... [-p <v>]... [-o <out>]
list <part> [-p <v>]... [-o <out>]
captions
delete <id> [-p <v>]...
download <id> [-p <v>]... [-o <out>]
insert (-r <kv>)... (-u (simple|resumable) -f <file> [-m <mime>]) [-p <v>]... [-o <out>]
list <part> <video-id> [-p <v>]... [-o <out>]
update (-r <kv>)... (-u (simple|resumable) -f <file> [-m <mime>]) [-p <v>]... [-o <out>]
channel-banners
insert (-r <kv>)... (-u (simple|resumable) -f <file> [-m <mime>]) [-p <v>]... [-o <out>]
channel-sections
delete <id> [-p <v>]...
insert (-r <kv>)... [-p <v>]... [-o <out>]
list <part> [-p <v>]... [-o <out>]
update (-r <kv>)... [-p <v>]... [-o <out>]
channels
list <part> [-p <v>]... [-o <out>]
update (-r <kv>)... [-p <v>]... [-o <out>]
comment-threads
insert (-r <kv>)... [-p <v>]... [-o <out>]
list <part> [-p <v>]... [-o <out>]
update (-r <kv>)... [-p <v>]... [-o <out>]
comments
delete <id> [-p <v>]...
insert (-r <kv>)... [-p <v>]... [-o <out>]
list <part> [-p <v>]... [-o <out>]
mark-as-spam <id> [-p <v>]...
set-moderation-status <id> <moderation-status> [-p <v>]...
update (-r <kv>)... [-p <v>]... [-o <out>]
guide-categories
list <part> [-p <v>]... [-o <out>]
i18n-languages
list <part> [-p <v>]... [-o <out>]
i18n-regions
list <part> [-p <v>]... [-o <out>]
live-broadcasts
bind <id> <part> [-p <v>]... [-o <out>]
control <id> <part> [-p <v>]... [-o <out>]
delete <id> [-p <v>]...
insert (-r <kv>)... [-p <v>]... [-o <out>]
list <part> [-p <v>]... [-o <out>]
transition <broadcast-status> <id> <part> [-p <v>]... [-o <out>]
update (-r <kv>)... [-p <v>]... [-o <out>]
live-streams
delete <id> [-p <v>]...
insert (-r <kv>)... [-p <v>]... [-o <out>]
list <part> [-p <v>]... [-o <out>]
update (-r <kv>)... [-p <v>]... [-o <out>]
playlist-items
delete <id> [-p <v>]...
insert (-r <kv>)... [-p <v>]... [-o <out>]
list <part> [-p <v>]... [-o <out>]
update (-r <kv>)... [-p <v>]... [-o <out>]
playlists
delete <id> [-p <v>]...
insert (-r <kv>)... [-p <v>]... [-o <out>]
list <part> [-p <v>]... [-o <out>]
update (-r <kv>)... [-p <v>]... [-o <out>]
search
list <part> [-p <v>]... [-o <out>]
subscriptions
delete <id> [-p <v>]...
insert (-r <kv>)... [-p <v>]... [-o <out>]
list <part> [-p <v>]... [-o <out>]
thumbnails
set <video-id> (-u (simple|resumable) -f <file> [-m <mime>]) [-p <v>]... [-o <out>]
video-abuse-report-reasons
list <part> [-p <v>]... [-o <out>]
video-categories
list <part> [-p <v>]... [-o <out>]
videos
delete <id> [-p <v>]...
get-rating <id> [-p <v>]... [-o <out>]
insert (-r <kv>)... (-u (simple|resumable) -f <file> [-m <mime>]) [-p <v>]... [-o <out>]
list <part> [-p <v>]... [-o <out>]
rate <id> <rating> [-p <v>]...
report-abuse (-r <kv>)... [-p <v>]...
update (-r <kv>)... [-p <v>]... [-o <out>]
watermarks
set <channel-id> (-r <kv>)... (-u (simple|resumable) -f <file> [-m <mime>]) [-p <v>]...
unset <channel-id> [-p <v>]...
youtube3 --help
All documentation details can be found at
http://byron.github.io/google-apis-rs/google_youtube3_cli/index.html
http://byron.github.io/google-apis-rs/google_youtube3_cli
Configuration:
--scope <url>
[--scope <url>]...
Specify the authentication a method should be executed in. Each scope
requires the user to grant this application permission to use it.
requires the user to grant this application permission to use it.
If unset, it defaults to the shortest scope url for a particular method.
--config-dir <folder>
A directory into which we will store our persistent data. Defaults to

View File

@@ -1,8 +1,9 @@
// COPY OF 'src/rust/cli/cmn.rs'
// DO NOT EDIT
use oauth2::{ApplicationSecret, ConsoleApplicationSecret, TokenStorage, Token};
use rustc_serialize::json;
use serde::json;
use mime::Mime;
use clap::{App, SubCommand};
use std::fs;
use std::env;
@@ -17,6 +18,46 @@ use std::default::Default;
const FIELD_SEP: char = '.';
pub enum CallType {
Upload(UploadProtocol),
Standard,
}
pub enum UploadProtocol {
Simple,
Resumable,
}
impl AsRef<str> for UploadProtocol {
fn as_ref(&self) -> &str {
match *self {
UploadProtocol::Simple => "simple",
UploadProtocol::Resumable => "resumable"
}
}
}
impl AsRef<str> for CallType {
fn as_ref(&self) -> &str {
match *self {
CallType::Upload(ref proto) => proto.as_ref(),
CallType::Standard => "standard-request"
}
}
}
impl FromStr for UploadProtocol {
type Err = String;
fn from_str(s: &str) -> Result<UploadProtocol, String> {
match s {
"simple" => Ok(UploadProtocol::Simple),
"resumable" => Ok(UploadProtocol::Resumable),
_ => Err(format!("Protocol '{}' is unknown", s)),
}
}
}
#[derive(Clone, Default)]
pub struct FieldCursor(Vec<String>);
@@ -112,6 +153,17 @@ pub fn parse_kv_arg<'a>(kv: &'a str, err: &mut InvalidOptionsError, for_hashmap:
}
}
pub fn protocol_from_str(name: &str, valid_protocols: Vec<String>, err: &mut InvalidOptionsError) -> CallType {
CallType::Upload(
match UploadProtocol::from_str(name) {
Ok(up) => up,
Err(msg) => {
err.issues.push(CLIError::InvalidUploadProtocol(name.to_string(), valid_protocols));
UploadProtocol::Simple
}
})
}
pub fn input_file_from_opts(file_path: &str, err: &mut InvalidOptionsError) -> Option<fs::File> {
match fs::File::open(file_path) {
Ok(f) => Some(f),
@@ -132,13 +184,14 @@ pub fn input_mime_from_opts(mime: &str, err: &mut InvalidOptionsError) -> Option
}
}
// May panic if we can't open the file - this is anticipated, we can't currently communicate this
// kind of error: TODO: fix this architecture :)
pub fn writer_from_opts(flag: bool, arg: &str) -> Box<Write> {
if !flag || arg == "-" {
Box::new(stdout())
} else {
Box::new(fs::OpenOptions::new().create(true).write(true).open(arg).unwrap())
pub fn writer_from_opts(arg: Option<&str>) -> Result<Box<Write>, io::Error> {
let f = arg.unwrap_or("-");
match f {
"-" => Ok(Box::new(stdout())),
_ => match fs::OpenOptions::new().create(true).write(true).open(f) {
Ok(f) => Ok(Box::new(f)),
Err(io_err) => Err(io_err),
}
}
}
@@ -151,7 +204,7 @@ pub fn arg_from_str<T>(arg: &str, err: &mut InvalidOptionsError,
match FromStr::from_str(arg) {
Err(perr) => {
err.issues.push(
CLIError::ParseError((arg_name, arg_type, arg.to_string(), format!("{}", perr)))
CLIError::ParseError(arg_name, arg_type, arg.to_string(), format!("{}", perr))
);
Default::default()
},
@@ -171,49 +224,47 @@ impl JsonTokenStorage {
}
impl TokenStorage for JsonTokenStorage {
type Error = io::Error;
type Error = json::Error;
// NOTE: logging might be interesting, currently we swallow all errors
fn set(&mut self, scope_hash: u64, _: &Vec<&str>, token: Option<Token>) -> Option<io::Error> {
fn set(&mut self, scope_hash: u64, _: &Vec<&str>, token: Option<Token>) -> Result<(), json::Error> {
match token {
None => {
match fs::remove_file(self.path(scope_hash)) {
Err(err) =>
match err.kind() {
io::ErrorKind::NotFound => None,
_ => Some(err)
io::ErrorKind::NotFound => Ok(()),
_ => Err(json::Error::IoError(err))
},
Ok(_) => None
Ok(_) => Ok(()),
}
}
Some(token) => {
let json_token = json::encode(&token).unwrap();
match fs::OpenOptions::new().create(true).write(true).open(&self.path(scope_hash)) {
Ok(mut f) => {
match f.write(json_token.as_bytes()) {
Ok(_) => None,
Err(io_err) => Some(io_err),
match json::to_writer_pretty(&mut f, &token) {
Ok(_) => Ok(()),
Err(io_err) => Err(json::Error::IoError(io_err)),
}
},
Err(io_err) => Some(io_err)
Err(io_err) => Err(json::Error::IoError(io_err))
}
}
}
}
fn get(&self, scope_hash: u64, _: &Vec<&str>) -> Result<Option<Token>, io::Error> {
fn get(&self, scope_hash: u64, _: &Vec<&str>) -> Result<Option<Token>, json::Error> {
match fs::File::open(&self.path(scope_hash)) {
Ok(mut f) => {
let mut json_string = String::new();
match f.read_to_string(&mut json_string) {
Ok(_) => Ok(Some(json::decode::<Token>(&json_string).unwrap())),
Err(io_err) => Err(io_err),
match json::de::from_reader(f) {
Ok(token) => Ok(Some(token)),
Err(err) => Err(err),
}
},
Err(io_err) => {
match io_err.kind() {
io::ErrorKind::NotFound => Ok(None),
_ => Err(io_err)
_ => Err(json::Error::IoError(io_err))
}
}
}
@@ -223,7 +274,7 @@ impl TokenStorage for JsonTokenStorage {
#[derive(Debug)]
pub enum ApplicationSecretError {
DecoderError((String, json::DecoderError)),
DecoderError((String, json::Error)),
FormatError(String),
}
@@ -311,11 +362,14 @@ impl fmt::Display for FieldError {
#[derive(Debug)]
pub enum CLIError {
Configuration(ConfigurationError),
ParseError((&'static str, &'static str, String, String)),
ParseError(&'static str, &'static str, String, String),
UnknownParameter(String),
InvalidUploadProtocol(String, Vec<String>),
InvalidKeyValueSyntax(String, bool),
Input(InputError),
Field(FieldError),
MissingCommandError,
MissingMethodError(String),
}
impl fmt::Display for CLIError {
@@ -324,7 +378,9 @@ impl fmt::Display for CLIError {
CLIError::Configuration(ref err) => write!(f, "Configuration -> {}", err),
CLIError::Input(ref err) => write!(f, "Input -> {}", err),
CLIError::Field(ref err) => write!(f, "Field -> {}", err),
CLIError::ParseError((arg_name, type_name, ref value, ref err_desc))
CLIError::InvalidUploadProtocol(ref proto_name, ref valid_names)
=> writeln!(f, "'{}' is not a valid upload protocol. Choose from one of {}", proto_name, valid_names.connect(", ")),
CLIError::ParseError(arg_name, type_name, ref value, ref err_desc)
=> writeln!(f, "Failed to parse argument '{}' with value '{}' as {} with error: {}",
arg_name, value, type_name, err_desc),
CLIError::UnknownParameter(ref param_name)
@@ -333,6 +389,8 @@ impl fmt::Display for CLIError {
let hashmap_info = if is_hashmap { "hashmap " } else { "" };
writeln!(f, "'{}' does not match {}pattern <key>=<value>", kv, hashmap_info)
},
CLIError::MissingCommandError => writeln!(f, "Please specify the main sub-command"),
CLIError::MissingMethodError(ref cmd) => writeln!(f, "Please specify the method to call on the '{}' command", cmd),
}
}
}
@@ -399,7 +457,7 @@ pub fn assure_config_dir_exists(dir: &str) -> Result<String, CLIError> {
pub fn application_secret_from_directory(dir: &str,
secret_basename: &str,
json_app_secret: &str)
json_console_secret: &str)
-> Result<ApplicationSecret, CLIError> {
let secret_path = Path::new(dir).join(secret_basename);
let secret_str = || secret_path.as_path().to_str().unwrap().to_string();
@@ -418,7 +476,10 @@ pub fn application_secret_from_directory(dir: &str,
err = match fs::OpenOptions::new().create(true).write(true).open(&secret_path) {
Err(cfe) => cfe,
Ok(mut f) => {
match f.write(json_app_secret.as_bytes()) {
// Assure we convert 'ugly' json string into pretty one
let console_secret: ConsoleApplicationSecret
= json::from_str(json_console_secret).unwrap();
match json::to_writer_pretty(&mut f, &console_secret) {
Err(io_err) => io_err,
Ok(_) => continue,
}
@@ -429,23 +490,24 @@ pub fn application_secret_from_directory(dir: &str,
return secret_io_error(err)
},
Ok(mut f) => {
let mut json_encoded_secret = String::new();
if let Err(io_err) = f.read_to_string(&mut json_encoded_secret) {
return secret_io_error(io_err)
}
match json::decode::<ConsoleApplicationSecret>(&json_encoded_secret) {
Err(json_decode_error) => return Err(CLIError::Configuration(
ConfigurationError::Secret(ApplicationSecretError::DecoderError(
(secret_str(), json_decode_error)
match json::de::from_reader::<_, ConsoleApplicationSecret>(f) {
Err(json::Error::IoError(err)) =>
return secret_io_error(err),
Err(json_err) =>
return Err(CLIError::Configuration(
ConfigurationError::Secret(
ApplicationSecretError::DecoderError(
(secret_str(), json_err)
)))),
Ok(console_secret) => match console_secret.installed {
Some(secret) => return Ok(secret),
None => return Err(
CLIError::Configuration(
ConfigurationError::Secret(
ApplicationSecretError::FormatError(secret_str())
)))
},
Ok(console_secret) =>
match console_secret.installed {
Some(secret) => return Ok(secret),
None => return Err(
CLIError::Configuration(
ConfigurationError::Secret(
ApplicationSecretError::FormatError(secret_str())
)))
},
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -5,7 +5,7 @@ DO NOT EDIT !
-->
The `google-youtube3` library allows access to all features of the *Google YouTube* service.
This documentation was generated from *YouTube* crate version *0.1.6+20150414*, where *20150414* is the exact revision of the *youtube:v3* schema built by the [mako](http://www.makotemplates.org/) code generator *v0.1.6*.
This documentation was generated from *YouTube* crate version *0.1.7+20150414*, where *20150414* is the exact revision of the *youtube:v3* schema built by the [mako](http://www.makotemplates.org/) code generator *v0.1.7*.
Everything else about the *YouTube* *v3* API can be found at the
[official documentation site](https://developers.google.com/youtube/v3).

View File

@@ -4,7 +4,7 @@
[package]
name = "google-youtube3"
version = "0.1.6+20150414"
version = "0.1.7+20150414"
authors = ["Sebastian Thiel <byronimo@gmail.com>"]
description = "A complete library to interact with YouTube (protocol v3)"
repository = "https://github.com/Byron/google-apis-rs/tree/master/gen/youtube3"

View File

@@ -173,7 +173,10 @@ pub trait Delegate {
/// Called after we have retrieved a new upload URL for a resumable upload to store it
/// in case we fail or cancel. That way, we can attempt to resume the upload later,
/// see `upload_url()`.
fn store_upload_url(&mut self, url: &str) {
/// It will also be called with None after a successful upload, which allows the delegate
/// to forget the URL. That way, we will not attempt to resume an upload that has already
/// finished.
fn store_upload_url(&mut self, url: Option<&str>) {
let _ = url;
}
@@ -459,6 +462,16 @@ impl<'a> Read for MultiPartReader<'a> {
header!{
#[doc="The `X-Upload-Content-Type` header."]
(XUploadContentType, "X-Upload-Content-Type") => [Mime]
xupload_content_type {
test_header!(
test1,
vec![b"text/plain"],
Some(HeaderField(
vec![Mime(TopLevel::Text, SubLevel::Plain, Vec::new())]
)));
}
}
#[derive(Clone, PartialEq, Debug)]

View File

@@ -2,7 +2,7 @@
// This file was generated automatically from 'src/mako/api/lib.rs.mako'
// DO NOT EDIT !
//! This documentation was generated from *YouTube* crate version *0.1.6+20150414*, where *20150414* is the exact revision of the *youtube:v3* schema built by the [mako](http://www.makotemplates.org/) code generator *v0.1.6*.
//! This documentation was generated from *YouTube* crate version *0.1.7+20150414*, where *20150414* is the exact revision of the *youtube:v3* schema built by the [mako](http://www.makotemplates.org/) code generator *v0.1.7*.
//!
//! Everything else about the *YouTube* *v3* API can be found at the
//! [official documentation site](https://developers.google.com/youtube/v3).
@@ -240,7 +240,6 @@
//! [google-go-api]: https://github.com/google/google-api-go-client
//!
//!
#![feature(std_misc)]
// Unused attributes happen thanks to defined, but unused structures
// We don't warn about this, as depending on the API, some data structures or facilities are never used.
// Instead of pre-determining this, we just disable the lint. It's manually tuned to not have any
@@ -402,7 +401,7 @@ impl<'a, C, A> YouTube<C, A>
YouTube {
client: RefCell::new(client),
auth: RefCell::new(authenticator),
_user_agent: "google-api-rust-client/0.1.6".to_string(),
_user_agent: "google-api-rust-client/0.1.7".to_string(),
}
}
@@ -471,7 +470,7 @@ impl<'a, C, A> YouTube<C, A>
}
/// Set the user-agent header field to use in all requests to the server.
/// It defaults to `google-api-rust-client/0.1.6`.
/// It defaults to `google-api-rust-client/0.1.7`.
///
/// Returns the previously set user-agent.
pub fn user_agent(&mut self, agent_name: String) -> String {
@@ -7577,7 +7576,7 @@ impl<'a, C, A> ChannelBannerInsertCall<'a, C, A> where C: BorrowMut<hyper::Clien
let upload_result = {
let url_str = &res.headers.get::<Location>().expect("Location header is part of protocol").0;
if upload_url_from_server {
dlg.store_upload_url(url_str);
dlg.store_upload_url(Some(url_str));
}
cmn::ResumableUploadHelper {
@@ -7605,6 +7604,7 @@ impl<'a, C, A> ChannelBannerInsertCall<'a, C, A> where C: BorrowMut<hyper::Clien
Some(Ok(upload_result)) => {
res = upload_result;
if !res.status.is_success() {
dlg.store_upload_url(None);
dlg.finished(false);
return Err(Error::Failure(res))
}
@@ -10458,7 +10458,7 @@ impl<'a, C, A> ThumbnailSetCall<'a, C, A> where C: BorrowMut<hyper::Client>, A:
let upload_result = {
let url_str = &res.headers.get::<Location>().expect("Location header is part of protocol").0;
if upload_url_from_server {
dlg.store_upload_url(url_str);
dlg.store_upload_url(Some(url_str));
}
cmn::ResumableUploadHelper {
@@ -10486,6 +10486,7 @@ impl<'a, C, A> ThumbnailSetCall<'a, C, A> where C: BorrowMut<hyper::Client>, A:
Some(Ok(upload_result)) => {
res = upload_result;
if !res.status.is_success() {
dlg.store_upload_url(None);
dlg.finished(false);
return Err(Error::Failure(res))
}
@@ -12502,7 +12503,7 @@ impl<'a, C, A> VideoInsertCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: o
let upload_result = {
let url_str = &res.headers.get::<Location>().expect("Location header is part of protocol").0;
if upload_url_from_server {
dlg.store_upload_url(url_str);
dlg.store_upload_url(Some(url_str));
}
cmn::ResumableUploadHelper {
@@ -12530,6 +12531,7 @@ impl<'a, C, A> VideoInsertCall<'a, C, A> where C: BorrowMut<hyper::Client>, A: o
Some(Ok(upload_result)) => {
res = upload_result;
if !res.status.is_success() {
dlg.store_upload_url(None);
dlg.finished(false);
return Err(Error::Failure(res))
}
@@ -20182,7 +20184,7 @@ impl<'a, C, A> WatermarkSetCall<'a, C, A> where C: BorrowMut<hyper::Client>, A:
let upload_result = {
let url_str = &res.headers.get::<Location>().expect("Location header is part of protocol").0;
if upload_url_from_server {
dlg.store_upload_url(url_str);
dlg.store_upload_url(Some(url_str));
}
cmn::ResumableUploadHelper {
@@ -20210,6 +20212,7 @@ impl<'a, C, A> WatermarkSetCall<'a, C, A> where C: BorrowMut<hyper::Client>, A:
Some(Ok(upload_result)) => {
res = upload_result;
if !res.status.is_success() {
dlg.store_upload_url(None);
dlg.finished(false);
return Err(Error::Failure(res))
}
@@ -23087,7 +23090,7 @@ impl<'a, C, A> CaptionInsertCall<'a, C, A> where C: BorrowMut<hyper::Client>, A:
let upload_result = {
let url_str = &res.headers.get::<Location>().expect("Location header is part of protocol").0;
if upload_url_from_server {
dlg.store_upload_url(url_str);
dlg.store_upload_url(Some(url_str));
}
cmn::ResumableUploadHelper {
@@ -23115,6 +23118,7 @@ impl<'a, C, A> CaptionInsertCall<'a, C, A> where C: BorrowMut<hyper::Client>, A:
Some(Ok(upload_result)) => {
res = upload_result;
if !res.status.is_success() {
dlg.store_upload_url(None);
dlg.finished(false);
return Err(Error::Failure(res))
}
@@ -24044,7 +24048,7 @@ impl<'a, C, A> CaptionUpdateCall<'a, C, A> where C: BorrowMut<hyper::Client>, A:
let upload_result = {
let url_str = &res.headers.get::<Location>().expect("Location header is part of protocol").0;
if upload_url_from_server {
dlg.store_upload_url(url_str);
dlg.store_upload_url(Some(url_str));
}
cmn::ResumableUploadHelper {
@@ -24072,6 +24076,7 @@ impl<'a, C, A> CaptionUpdateCall<'a, C, A> where C: BorrowMut<hyper::Client>, A:
Some(Ok(upload_result)) => {
res = upload_result;
if !res.status.is_success() {
dlg.store_upload_url(None);
dlg.finished(false);
return Err(Error::Failure(res))
}