diff --git a/gen/groupsmigration1/Cargo.toml b/gen/groupsmigration1/Cargo.toml new file mode 100644 index 00000000000..97147461388 --- /dev/null +++ b/gen/groupsmigration1/Cargo.toml @@ -0,0 +1,22 @@ +# DO NOT EDIT ! +# This file was generated automatically from 'src/mako/Cargo.toml.mako' +# DO NOT EDIT ! +[package] + +name = "google-groupsmigration1" +version = "0.0.1+20140416" +authors = ["Sebastian Thiel "] +description = "A complete library to interact with Groups Migration (protocol v1)" +repository = "https://github.com/Byron/google-apis-rs/gen/groupsmigration1/.timestamp" +homepage = "https://developers.google.com/google-apps/groups-migration/" +documentation = "http://byron.github.io/google-apis-rs/google-groupsmigration1" +license = "MIT" +keywords = ["groupsmigration", "google", "protocol", "web", "api"] + +[dependencies] +hyper = "*" +mime = "*" +url = "*" +serde = "*" +serde_macros = "*" +yup-oauth2 = "*" diff --git a/gen/groupsmigration1/LICENSE.md b/gen/groupsmigration1/LICENSE.md new file mode 100644 index 00000000000..ae22e6ec52f --- /dev/null +++ b/gen/groupsmigration1/LICENSE.md @@ -0,0 +1,30 @@ + +The MIT License (MIT) +===================== + +Copyright © `2015` `Sebastian Thiel` + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the “Software”), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/gen/groupsmigration1/README.md b/gen/groupsmigration1/README.md new file mode 100644 index 00000000000..96a2d278190 --- /dev/null +++ b/gen/groupsmigration1/README.md @@ -0,0 +1,165 @@ + +The `groupsmigration1` library allows access to all features of *Groups Migration*. + +# Features + +It seems there is nothing you can do here ... . + +* archive + * [*insert*](http://byron.github.io/google-apis-rs/google-groupsmigration1/struct.ArchiveInsertCall.html) + + +Upload supported by ... + +* [*insert archive*](http://byron.github.io/google-apis-rs/google-groupsmigration1/struct.ArchiveInsertCall.html) + + +Everything else about the *Groups Migration* *v1* API can be found at the +[official documentation site](https://developers.google.com/google-apps/groups-migration/). + +# Structure of this Library + +The API is structured into the following primary items: + +* **[Hub](http://byron.github.io/google-apis-rs/google-groupsmigration1/struct.GroupsMigration.html)** + * a central object to maintain state and allow accessing all *Activities* +* **[Resources](http://byron.github.io/google-apis-rs/google-groupsmigration1/trait.Resource.html)** + * primary types that you can apply *Activities* to + * a collection of properties and *Parts* + * **[Parts](http://byron.github.io/google-apis-rs/google-groupsmigration1/trait.Part.html)** + * a collection of properties + * never directly used in *Activities* +* **[Activities](http://byron.github.io/google-apis-rs/google-groupsmigration1/trait.CallBuilder.html)** + * operations to apply to *Resources* + +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 +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 + +```Rust +extern crate hyper; +extern crate "yup-oauth2" as oauth2; +extern crate "google-groupsmigration1" as groupsmigration1; +use groupsmigration1::Result; +use std::fs; +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 +// `client_secret`, among other things. +let secret: ApplicationSecret = Default::default(); +// 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 +// 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, + hyper::Client::new(), + ::default(), None); +let mut hub = GroupsMigration::new(hyper::Client::new(), auth); +// You can configure optional parameters by calling the respective setters at will, and +// execute the final call using `upload(...)`. +// 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 { + Result::HttpError(err) => println!("HTTPERROR: {:?}", err), + Result::MissingAPIKey => println!("Auth: Missing API Key - used if there are no scopes"), + Result::MissingToken => println!("OAuth2: Missing Token"), + Result::UploadSizeLimitExceeded(size, max_size) => println!("Upload size too big: {} of {}", size, max_size), + Result::Failure(_) => println!("General Failure (hyper::client::Response doesn't print)"), + Result::FieldClash(clashed_field) => println!("You added custom parameter which is part of builder: {:?}", clashed_field), + Result::JsonDecodeError(err) => println!("Couldn't understand server reply - maybe API needs update: {:?}", err), + Result::Success(_) => println!("Success (value doesn't print)"), +} + +``` +## Handling Errors + +All errors produced by the system are provided either as [Result](http://byron.github.io/google-apis-rs/google-groupsmigration1/enum.Result.html) enumeration as return value of +the doit() methods, or handed as possibly intermediate results to either the +[Hub Delegate](http://byron.github.io/google-apis-rs/google-groupsmigration1/trait.Delegate.html), or the [Authenticator Delegate](http://byron.github.io/google-apis-rs/google-groupsmigration1/../yup-oauth2/trait.AuthenticatorDelegate.html). + +When delegates handle errors or intermediate values, they may have a chance to instruct the system to retry. This +makes the system potentially resilient to all kinds of errors. + +## Uploads and Downlods +If a method supports downloads, the response body, which is part of the [Result](http://byron.github.io/google-apis-rs/google-groupsmigration1/enum.Result.html), should be +read by you to obtain the media. +If such a method also supports a [Response Result](http://byron.github.io/google-apis-rs/google-groupsmigration1/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 +`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](http://byron.github.io/google-apis-rs/google-groupsmigration1/trait.Delegate.html) to the +[Method Builder](http://byron.github.io/google-apis-rs/google-groupsmigration1/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](http://byron.github.io/google-apis-rs/google-groupsmigration1/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](http://byron.github.io/google-apis-rs/google-groupsmigration1/trait.RequestValue.html) and +[decodable](http://byron.github.io/google-apis-rs/google-groupsmigration1/trait.ResponseResult.html) via json. Optionals are used to indicate that partial requests are responses are valid. +Most optionals are are considered [Parts](http://byron.github.io/google-apis-rs/google-groupsmigration1/trait.Part.html) which are identifyable 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](http://byron.github.io/google-apis-rs/google-groupsmigration1/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](http://byron.github.io/google-apis-rs/google-groupsmigration1/trait.RequestValue.html) are borrowed + +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 + +# License +The **groupsmigration1** library was generated by Sebastian Thiel, and is placed +under the *MIT* license. +You can read the full text at the repository's [license file][repo-license]. + +[repo-license]: https://github.com/Byron/google-apis-rs/LICENSE.md diff --git a/gen/groupsmigration1/src/cmn.rs b/gen/groupsmigration1/src/cmn.rs new file mode 100644 index 00000000000..13ddd954e5d --- /dev/null +++ b/gen/groupsmigration1/src/cmn.rs @@ -0,0 +1,396 @@ +// COPY OF 'src/rust/cmn.rs' +// DO NOT EDIT +use std::marker::MarkerTrait; +use std::io::{self, Read, Seek, Cursor, Write, SeekFrom}; +use std; + +use mime::{Mime, TopLevel, SubLevel, Attr, Value}; +use oauth2; +use hyper; +use hyper::header::{ContentType, ContentLength, Headers, UserAgent, Authorization}; +use hyper::http::LINE_ENDING; +use hyper::method::Method; + +use serde; + +/// Identifies the Hub. There is only one per library, this trait is supposed +/// to make intended use more explicit. +/// The hub allows to access all resource methods more easily. +pub trait Hub: MarkerTrait {} + +/// Identifies types for building methods of a particular resource type +pub trait ResourceMethodsBuilder: MarkerTrait {} + +/// Identifies types which represent builders for a particular resource method +pub trait CallBuilder: MarkerTrait {} + +/// Identifies types which can be inserted and deleted. +/// Types with this trait are most commonly used by clients of this API. +pub trait Resource: MarkerTrait {} + +/// Identifies types which are used in API responses. +pub trait ResponseResult: MarkerTrait {} + +/// Identifies types which are used in API requests. +pub trait RequestValue: MarkerTrait {} + +/// Identifies types which are not actually used by the API +/// This might be a bug within the google API schema. +pub trait UnusedType: MarkerTrait {} + +/// Identifies types which are only used as part of other types, which +/// usually are carrying the `Resource` trait. +pub trait Part: MarkerTrait {} + +/// Identifies types which are only used by other types internally. +/// They have no special meaning, this trait just marks them for completeness. +pub trait NestedType: MarkerTrait {} + +/// A utility to specify reader types which provide seeking capabilities too +pub trait ReadSeek: Seek + Read {} +impl ReadSeek for T {} + +/// A trait for all types that can convert themselves into a *parts* string +pub trait ToParts { + fn to_parts(&self) -> String; +} + + +/// A utility type which can decode a server response that indicates error +#[derive(Deserialize)] +pub struct JsonServerError { + pub error: String, + pub error_description: Option +} + +#[derive(Copy, Clone)] +pub struct DummyNetworkStream; + +impl Read for DummyNetworkStream { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + Ok(0) + } +} + +impl Write for DummyNetworkStream { + fn write(&mut self, msg: &[u8]) -> io::Result { + Ok(0) + } + + fn flush(&mut self) -> io::Result<()> { + Ok(()) + } +} + +impl hyper::net::NetworkStream for DummyNetworkStream { + fn peer_addr(&mut self) -> io::Result { + Ok("127.0.0.1:1337".parse().unwrap()) + } +} + + +/// 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 +/// uploading media +pub trait Delegate { + + /// Called at the beginning of any API request. The delegate should store the method + /// 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 sucessfull. That way, the delgate 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. + /// + /// Return retry information. + fn http_error(&mut self, &hyper::HttpError) -> oauth2::Retry { + oauth2::Retry::Abort + } + + /// 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 { + None + } + + /// Called whenever the Authenticator didn't yield a token. The delegate + /// may attempt to provide one, or just take is a general information about the + /// pending impending failure + fn token(&mut self) -> Option { + None + } + + /// Called during resumable uploads to provide a URL for the impending upload. + /// It was saved after a previous call to `store_upload_url(...)`, and if not None, + /// will be used instead of asking the server for a new upload URL. + /// This is useful in case a previous resumable upload was aborted/cancelled, but should now + /// be resumed. + /// The returned URL will be used exactly once - if it fails again and the delegate allows + /// to retry, we will ask the server for a new upload URL. + fn upload_url(&mut self) -> Option { + None + } + + /// 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) { + 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. + /// `json_decode_error` - The decoder error + fn response_json_decode_error(&mut self, json_encoded_value: &str, json_decode_error: &serde::json::Error) { + let _ = json_encoded_value; + let _ = json_decode_error; + } + + /// Called whenever the http request returns with a non-success status code. + /// 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. + fn http_failure(&mut self, _: &hyper::client::Response, JsonServerError) -> oauth2::Retry { + oauth2::Retry::Abort + } + + /// 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) { } + + + /// 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) { + let _ = is_success; + } +} + +/// A delegate with a conservative default implementation, which is used if no other delegate is +/// set. +#[derive(Default)] +pub struct DefaultDelegate; + +impl Delegate for DefaultDelegate {} + + +/// A universal result type used as return for all action method results. +pub enum Result { + /// The http connection failed + HttpError(hyper::HttpError), + + /// An attempt was made to upload a resource with size stored in field `.0` + /// even though the maximum upload size is what is stored in field `.1`. + UploadSizeLimitExceeded(u64, u64), + + /// We needed an API key for authentication, but didn't obtain one. + /// Neither through the authenticator, nor through the Delegate. + MissingAPIKey, + + /// We required a Token, but didn't get one from the Authenticator + MissingToken, + + /// An additional, free form field clashed with one of the built-in optional ones + FieldClash(&'static str), + + /// Shows that we failed to decode the server response. + /// This can happen if the protocol changes in conjunction with strict json decoding. + JsonDecodeError(serde::json::Error), + + /// Indicates an HTTP repsonse with a non-success status code + Failure(hyper::client::Response), + + /// It worked ! + Success(T), +} + +/// Contains information about an API request. +pub struct MethodInfo { + pub id: &'static str, + pub http_method: Method, +} + +const BOUNDARY: &'static str = "MDuXWGyeE33QFXGchb2VFWc4Z7945d"; + +/// Provides a `Read` interface that converts multiple parts into the protocol +/// identified by [RFC2387](https://tools.ietf.org/html/rfc2387). +/// **Note**: This implementation is just as rich as it needs to be to perform uploads +/// to google APIs, and might not be a fully-featured implementation. +#[derive(Default)] +pub struct MultiPartReader<'a> { + raw_parts: Vec<(Headers, &'a mut Read)>, + current_part: Option<(Cursor>, &'a mut Read)>, + last_part_boundary: Option>>, +} + +impl<'a> MultiPartReader<'a> { + + /// Reserve memory for exactly the given amount of parts + pub fn reserve_exact(&mut self, cap: usize) { + self.raw_parts.reserve_exact(cap); + } + + /// Add a new part to the queue of parts to be read on the first `read` call. + /// + /// # Arguments + /// `headers` - identifying the body of the part. It's similar to the header + /// in an ordinary single-part call, and should thus contain the + /// same information. + /// `reader` - a reader providing the part's body + /// `size` - the amount of bytes provided by the reader. It will be put onto the header as + /// content-size. + /// `mime` - It will be put onto the content type + /// # Panics + /// + /// If this method is called after the first `read` call, it will panic + pub fn add_part(&mut self, reader: &'a mut Read, size: u64, mime_type: Mime) -> &mut MultiPartReader<'a> { + let mut headers = Headers::new(); + headers.set(ContentType(mime_type)); + headers.set(ContentLength(size)); + self.raw_parts.push((headers, reader)); + self + } + + /// Returns the mime-type representing our multi-part message. + /// Use it with the ContentType header. + pub fn mime_type(&self) -> Mime { + Mime( + TopLevel::Multipart, + SubLevel::Ext("Related".to_string()), + vec![(Attr::Ext("boundary".to_string()), Value::Ext(BOUNDARY.to_string()))], + ) + } + + /// Returns true if we are totally used + fn is_depleted(&self) -> bool { + self.raw_parts.len() == 0 && self.current_part.is_none() && self.last_part_boundary.is_none() + } + + /// Returns true if we are handling our last part + fn is_last_part(&self) -> bool { + self.raw_parts.len() == 0 && self.current_part.is_some() + } +} + +impl<'a> Read for MultiPartReader<'a> { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + 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); + if br < buf.len() { + self.last_part_boundary = None; + } + return Ok(br) + }, + (0, true, true) => return Ok(0), + (n, true, _) if n > 0 => { + let (headers, reader) = self.raw_parts.remove(0); + let mut c = Cursor::new(Vec::::new()); + write!(&mut c, "{}--{}{}{}{}", LINE_ENDING, BOUNDARY, LINE_ENDING, + headers, LINE_ENDING).unwrap(); + c.seek(SeekFrom::Start(0)).unwrap(); + self.current_part = Some((c, reader)); + } + _ => {}, + } + + // read headers as long as possible + let (hb, rr) = { + let &mut (ref mut c, ref mut reader) = self.current_part.as_mut().unwrap(); + 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 + // will be written last + self.last_part_boundary = Some(Cursor::new( + format!("{}--{}", LINE_ENDING, BOUNDARY).into_bytes())) + } + // We are depleted - this can trigger the next part to come in + self.current_part = None; + } + let mut total_bytes_read = hb + bytes_read; + while total_bytes_read < buf.len() && !self.is_depleted() { + match self.read(&mut buf[total_bytes_read ..]) { + Ok(br) => total_bytes_read += br, + Err(err) => return Err(err), + } + } + Ok(total_bytes_read) + } + Err(err) => { + // fail permanently + self.current_part = None; + self.last_part_boundary = None; + self.raw_parts.clear(); + Err(err) + } + } + } +} + + +/// The `X-Upload-Content-Type` header. +#[derive(Clone, PartialEq, Debug)] +pub struct XUploadContentType(pub Mime); + +impl_header!(XUploadContentType, + "X-Upload-Content-Type", + Mime); + +/// A utility type to perform a resumable upload from start to end. +pub struct ResumableUploadHelper<'a, NC: 'a, A: 'a> { + pub client: &'a mut hyper::client::Client, + pub delegate: &'a mut Delegate, + pub auth: &'a mut A, + pub user_agent: &'a str, + pub auth_token: String, + pub url: &'a str, + pub reader: &'a mut ReadSeek, + pub media_type: Mime, + pub content_size: u64 +} + +impl<'a, NC, A> ResumableUploadHelper<'a, NC, A> + where NC: hyper::net::NetworkConnector, + A: oauth2::GetToken { + + fn query_transfer_status(&'a mut self) -> (u64, hyper::HttpResult) { + self.client.post(self.url) + .header(UserAgent(self.user_agent.to_string())) + .header(Authorization("Bearer ".to_string() + &self.auth_token)); + (0, Err(hyper::error::HttpError::HttpStatusError)) + } + + pub fn upload(&'a mut self) -> hyper::HttpResult { + let (start, result) = self.query_transfer_status(); + if let Err(_) = result { + return result + } + Err(hyper::error::HttpError::HttpStatusError) + } +} \ No newline at end of file diff --git a/gen/groupsmigration1/src/lib.rs b/gen/groupsmigration1/src/lib.rs new file mode 100644 index 00000000000..df8365a4bf4 --- /dev/null +++ b/gen/groupsmigration1/src/lib.rs @@ -0,0 +1,731 @@ +// DO NOT EDIT ! +// This file was generated automatically from 'src/mako/lib.rs.mako' +// DO NOT EDIT ! + +//! This documentation was generated from *Groups Migration* crate version *0.0.1+20140416*. +//! The original source code can be found [on github](https://github.com/Byron/google-apis-rs/tree/master/gen/groupsmigration1). +//! # Features +//! +//! It seems there is nothing you can do here ... . +//! +//! * archive +//! * [*insert*](struct.ArchiveInsertCall.html) +//! +//! +//! Upload supported by ... +//! +//! * [*insert archive*](struct.ArchiveInsertCall.html) +//! +//! +//! Everything else about the *Groups Migration* *v1* API can be found at the +//! [official documentation site](https://developers.google.com/google-apps/groups-migration/). +//! +//! 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* +//! * **[Resources](trait.Resource.html)** +//! * primary types that you can apply *Activities* to +//! * a collection of properties and *Parts* +//! * **[Parts](trait.Part.html)** +//! * a collection of properties +//! * never directly used in *Activities* +//! * **[Activities](trait.CallBuilder.html)** +//! * operations to apply to *Resources* +//! +//! 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 +//! 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; +//! extern crate "google-groupsmigration1" as groupsmigration1; +//! use groupsmigration1::Result; +//! use std::fs; +//! # #[test] fn egal() { +//! 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 +//! // `client_secret`, among other things. +//! let secret: ApplicationSecret = Default::default(); +//! // 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 +//! // 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, +//! hyper::Client::new(), +//! ::default(), None); +//! let mut hub = GroupsMigration::new(hyper::Client::new(), auth); +//! // You can configure optional parameters by calling the respective setters at will, and +//! // execute the final call using `upload(...)`. +//! // 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 { +//! Result::HttpError(err) => println!("HTTPERROR: {:?}", err), +//! Result::MissingAPIKey => println!("Auth: Missing API Key - used if there are no scopes"), +//! Result::MissingToken => println!("OAuth2: Missing Token"), +//! Result::UploadSizeLimitExceeded(size, max_size) => println!("Upload size too big: {} of {}", size, max_size), +//! Result::Failure(_) => println!("General Failure (hyper::client::Response doesn't print)"), +//! Result::FieldClash(clashed_field) => println!("You added custom parameter which is part of builder: {:?}", clashed_field), +//! Result::JsonDecodeError(err) => println!("Couldn't understand server reply - maybe API needs update: {:?}", err), +//! Result::Success(_) => println!("Success (value doesn't print)"), +//! } +//! # } +//! ``` +//! ## 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 +//! [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 +//! makes the system potentially resilient to all kinds of errors. +//! +//! ## Uploads and Downlods +//! 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 +//! `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 +//! 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 are valid. +//! Most optionals are are considered [Parts](trait.Part.html) which are identifyable 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 +//! +//! 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(core,io,thread_sleep)] +// 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 +// unused imports in fully featured APIs. Same with unused_mut ... . +#![allow(unused_imports, unused_mut)] +// Required for serde annotations +#![feature(custom_derive, custom_attribute, plugin)] +#![plugin(serde_macros)] + +#[macro_use] +extern crate hyper; +extern crate serde; +extern crate "yup-oauth2" as oauth2; +extern crate mime; +extern crate url; + +mod cmn; + +use std::collections::HashMap; +use std::cell::RefCell; +use std::borrow::BorrowMut; +use std::default::Default; +use std::collections::BTreeMap; +use std::marker::PhantomData; +use serde::json; +use std::io; +use std::fs; +use std::thread::sleep; + +pub use cmn::{MultiPartReader, ToParts, MethodInfo, Result, CallBuilder, Hub, ReadSeek, Part, ResponseResult, RequestValue, NestedType, Delegate, DefaultDelegate, ResourceMethodsBuilder, Resource}; + + +// ############## +// UTILITIES ### +// ############ + +/// Identifies the an OAuth2 authorization scope. +/// A scope is needed when requesting an +/// [authorization token](https://developers.google.com/youtube/v3/guides/authentication). +#[derive(PartialEq, Eq, Hash)] +pub enum Scope { + /// Manage messages in groups on your domain + AppGroupMigration, +} + +impl Str for Scope { + fn as_slice(&self) -> &str { + match *self { + Scope::AppGroupMigration => "https://www.googleapis.com/auth/apps.groups.migration", + } + } +} + +impl Default for Scope { + fn default() -> Scope { + Scope::AppGroupMigration + } +} + + + +// ######## +// HUB ### +// ###### + +/// Central instance to access all GroupsMigration related resource activities +/// +/// # Examples +/// +/// Instantiate a new hub +/// +/// ```test_harness,no_run +/// extern crate hyper; +/// extern crate "yup-oauth2" as oauth2; +/// extern crate "google-groupsmigration1" as groupsmigration1; +/// use groupsmigration1::Result; +/// use std::fs; +/// # #[test] fn egal() { +/// 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 +/// // `client_secret`, among other things. +/// let secret: ApplicationSecret = Default::default(); +/// // 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 +/// // 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, +/// hyper::Client::new(), +/// ::default(), None); +/// let mut hub = GroupsMigration::new(hyper::Client::new(), auth); +/// // You can configure optional parameters by calling the respective setters at will, and +/// // execute the final call using `upload(...)`. +/// // 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 { +/// Result::HttpError(err) => println!("HTTPERROR: {:?}", err), +/// Result::MissingAPIKey => println!("Auth: Missing API Key - used if there are no scopes"), +/// Result::MissingToken => println!("OAuth2: Missing Token"), +/// Result::UploadSizeLimitExceeded(size, max_size) => println!("Upload size too big: {} of {}", size, max_size), +/// Result::Failure(_) => println!("General Failure (hyper::client::Response doesn't print)"), +/// Result::FieldClash(clashed_field) => println!("You added custom parameter which is part of builder: {:?}", clashed_field), +/// Result::JsonDecodeError(err) => println!("Couldn't understand server reply - maybe API needs update: {:?}", err), +/// Result::Success(_) => println!("Success (value doesn't print)"), +/// } +/// # } +/// ``` +pub struct GroupsMigration { + client: RefCell, + auth: RefCell, + _user_agent: String, + + _m: PhantomData +} + +impl<'a, C, NC, A> Hub for GroupsMigration {} + +impl<'a, C, NC, A> GroupsMigration + where NC: hyper::net::NetworkConnector, C: BorrowMut>, A: oauth2::GetToken { + + pub fn new(client: C, authenticator: A) -> GroupsMigration { + GroupsMigration { + client: RefCell::new(client), + auth: RefCell::new(authenticator), + _user_agent: "google-api-rust-client/0.0.1".to_string(), + _m: PhantomData + } + } + + pub fn archive(&'a self) -> ArchiveMethods<'a, C, NC, A> { + ArchiveMethods { hub: &self } + } + + /// Set the user-agent header field to use in all requests to the server. + /// It defaults to `google-api-rust-client/0.0.1`. + /// + /// Returns the previously set user-agent. + pub fn user_agent(&mut self, agent_name: String) -> String { + let prev = self._user_agent.clone(); + self._user_agent = agent_name; + prev + } +} + + +// ############ +// SCHEMAS ### +// ########## +/// JSON response template for groups migration API. +/// +/// # Activities +/// +/// This type is used in activities, which are methods you may call on this type or where this type is involved in. +/// The list links the activity name, along with information about where it is used (one of *request* and *response*). +/// +/// * [insert archive](struct.ArchiveInsertCall.html) (response) +/// +#[derive(Default, Clone, Debug, Deserialize)] +pub struct Groups { + /// The kind of insert resource this is. + pub kind: String, + /// The status of the insert request. + #[serde(alias="responseCode")] + pub response_code: String, +} + +impl ResponseResult for Groups {} + + + +// ################### +// MethodBuilders ### +// ################# + +/// A builder providing access to all methods supported on *archive* resources. +/// It is not used directly, but through the `GroupsMigration` hub. +/// +/// # Example +/// +/// Instantiate a resource builder +/// +/// ```test_harness,no_run +/// extern crate hyper; +/// extern crate "yup-oauth2" as oauth2; +/// extern crate "google-groupsmigration1" as groupsmigration1; +/// +/// # #[test] fn egal() { +/// use std::default::Default; +/// use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage}; +/// use groupsmigration1::GroupsMigration; +/// +/// let secret: ApplicationSecret = Default::default(); +/// let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, +/// hyper::Client::new(), +/// ::default(), None); +/// let mut hub = GroupsMigration::new(hyper::Client::new(), auth); +/// // Usually you wouldn't bind this to a variable, but keep calling *CallBuilders* +/// // like `insert(...)` +/// // to build up your call. +/// let rb = hub.archive(); +/// # } +/// ``` +pub struct ArchiveMethods<'a, C, NC, A> + where C: 'a, NC: 'a, A: 'a { + + hub: &'a GroupsMigration, +} + +impl<'a, C, NC, A> ResourceMethodsBuilder for ArchiveMethods<'a, C, NC, A> {} + +impl<'a, C, NC, A> ArchiveMethods<'a, C, NC, A> { + + /// Create a builder to help you perform the following task: + /// + /// Inserts a new mail into the archive of the Google group. + pub fn insert(&self, group_id: &str) -> ArchiveInsertCall<'a, C, NC, A> { + ArchiveInsertCall { + hub: self.hub, + _group_id: group_id.to_string(), + _delegate: Default::default(), + _scopes: Default::default(), + _additional_params: Default::default(), + } + } +} + + + + + +// ################### +// CallBuilders ### +// ################# + +/// Inserts a new mail into the archive of the Google group. +/// +/// A builder for the *insert* method supported by a *archive* resource. +/// It is not used directly, but through a `ArchiveMethods`. +/// +/// # Example +/// +/// Instantiate a resource method builder +/// +/// ```test_harness,no_run +/// # extern crate hyper; +/// # extern crate "yup-oauth2" as oauth2; +/// # extern crate "google-groupsmigration1" as groupsmigration1; +/// use std::fs; +/// # #[test] fn egal() { +/// # use std::default::Default; +/// # use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage}; +/// # use groupsmigration1::GroupsMigration; +/// +/// # let secret: ApplicationSecret = Default::default(); +/// # let auth = Authenticator::new(&secret, DefaultAuthenticatorDelegate, +/// # hyper::Client::new(), +/// # ::default(), None); +/// # let mut hub = GroupsMigration::new(hyper::Client::new(), auth); +/// // You can configure optional parameters by calling the respective setters at will, and +/// // execute the final call using `upload(...)`. +/// // 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()); +/// # } +/// ``` +pub struct ArchiveInsertCall<'a, C, NC, A> + where C: 'a, NC: 'a, A: 'a { + + hub: &'a GroupsMigration, + _group_id: String, + _delegate: Option<&'a mut Delegate>, + _additional_params: HashMap, + _scopes: BTreeMap +} + +impl<'a, C, NC, A> CallBuilder for ArchiveInsertCall<'a, C, NC, A> {} + +impl<'a, C, NC, A> ArchiveInsertCall<'a, C, NC, A> where NC: hyper::net::NetworkConnector, C: BorrowMut>, A: oauth2::GetToken { + + + /// Perform the operation you have build so far. + fn doit(mut self, mut reader: RS, reader_mime_type: mime::Mime, protocol: &'static str) -> Result<(hyper::client::Response, Groups)> + where RS: ReadSeek { + use hyper::client::IntoBody; + use std::io::{Read, Seek}; + use hyper::header::{ContentType, ContentLength, Authorization, UserAgent, Location}; + let mut dd = DefaultDelegate; + let mut dlg: &mut Delegate = match self._delegate { + Some(d) => d, + None => &mut dd + }; + dlg.begin(MethodInfo { id: "groupsmigration.archive.insert", + http_method: hyper::method::Method::Post }); + let mut params: Vec<(&str, String)> = Vec::with_capacity((3 + self._additional_params.len())); + params.push(("groupId", self._group_id.to_string())); + for &field in ["alt", "groupId"].iter() { + if self._additional_params.contains_key(field) { + dlg.finished(false); + return Result::FieldClash(field); + } + } + for (name, value) in self._additional_params.iter() { + params.push((&name, value.clone())); + } + + params.push(("alt", "json".to_string())); + + let mut url = if protocol == "simple" { + "https://www.googleapis.com/upload/groups/v1/groups/{groupId}/archive".to_string() + } else if protocol == "resumable" { + "https://www.googleapis.com/resumable/upload/groups/v1/groups/{groupId}/archive".to_string() + } else { + unreachable!() + }; + params.push(("uploadType", protocol.to_string())); + if self._scopes.len() == 0 { + self._scopes.insert(Scope::AppGroupMigration.as_slice().to_string(), ()); + } + + for &(find_this, param_name) in [("{groupId}", "groupId")].iter() { + let mut replace_with: Option<&str> = None; + for &(name, ref value) in params.iter() { + if name == param_name { + replace_with = Some(value); + break; + } + } + url = url.replace(find_this, replace_with.expect("to find substitution value in params")); + } + { + let mut indices_for_removal: Vec = Vec::with_capacity(1); + for param_name in ["groupId"].iter() { + for (index, &(ref name, _)) in params.iter().rev().enumerate() { + if name == param_name { + indices_for_removal.push(params.len() - index - 1); + break; + } + } + } + for &index in indices_for_removal.iter() { + 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_slice())))); + } + + + let mut should_ask_dlg_for_url = false; + let mut upload_url_from_server = true; + let mut upload_url: Option = None; + + loop { + let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys()); + if token.is_none() { + token = dlg.token(); + } + if token.is_none() { + dlg.finished(false); + return Result::MissingToken + } + let auth_header = Authorization("Bearer ".to_string() + &token.unwrap().access_token); + let mut req_result = { + if should_ask_dlg_for_url && (upload_url = dlg.upload_url()) == () && upload_url.is_some() { + should_ask_dlg_for_url = false; + upload_url_from_server = false; + let mut response = hyper::client::Response::new(Box::new(cmn::DummyNetworkStream)); + match response { + Ok(ref mut res) => { + res.status = hyper::status::StatusCode::Ok; + res.headers.set(Location(upload_url.as_ref().unwrap().clone())) + } + _ => unreachable!(), + } + response + } else { + let mut client = &mut *self.hub.client.borrow_mut(); + let mut req = client.borrow_mut().request(hyper::method::Method::Post, url.as_slice()) + .header(UserAgent(self.hub._user_agent.clone())) + .header(auth_header.clone()); + if protocol == "simple" { + let size = reader.seek(io::SeekFrom::End(0)).unwrap(); + reader.seek(io::SeekFrom::Start(0)).unwrap(); + if size > 0 { + return Result::UploadSizeLimitExceeded(size, 0) + } + req = req.header(ContentType(reader_mime_type.clone())) + .header(ContentLength(size)) + .body(reader.into_body()); + } + upload_url_from_server = true; + if protocol == "resumable" { + req = req.header(cmn::XUploadContentType(reader_mime_type.clone())); + } + + dlg.pre_request(); + req.send() + + } + }; + + match req_result { + Err(err) => { + if let oauth2::Retry::After(d) = dlg.http_error(&err) { + sleep(d); + continue; + } + dlg.finished(false); + return Result::HttpError(err) + } + Ok(mut res) => { + if !res.status.is_success() { + let mut json_err = String::new(); + res.read_to_string(&mut json_err).unwrap(); + let error_info: cmn::JsonServerError = json::from_str(&json_err).unwrap(); + if let oauth2::Retry::After(d) = dlg.http_failure(&res, error_info) { + sleep(d); + continue; + } + dlg.finished(false); + return Result::Failure(res) + } + if protocol == "resumable" { + let size = reader.seek(io::SeekFrom::End(0)).unwrap(); + reader.seek(io::SeekFrom::Start(0)).unwrap(); + if size > 0 { + return Result::UploadSizeLimitExceeded(size, 0) + } + let mut client = &mut *self.hub.client.borrow_mut(); + let upload_result = { + let url = &res.headers.get::().expect("Location header is part of protocol").0; + if upload_url_from_server { + dlg.store_upload_url(url); + } + + cmn::ResumableUploadHelper { + client: &mut client.borrow_mut(), + delegate: dlg, + auth: &mut *self.hub.auth.borrow_mut(), + user_agent: &self.hub._user_agent, + auth_token: auth_header.0.clone(), + url: url, + reader: &mut reader, + media_type: reader_mime_type.clone(), + content_size: size + }.upload() + }; + match upload_result { + Err(err) => { + dlg.finished(false); + return Result::HttpError(err) + } + Ok(upload_result) => res = upload_result, + } + } + let result_value = { + let mut json_response = String::new(); + res.read_to_string(&mut json_response).unwrap(); + match json::from_str(&json_response) { + Ok(decoded) => (res, decoded), + Err(err) => { + dlg.response_json_decode_error(&json_response, &err); + return Result::JsonDecodeError(err); + } + } + }; + + dlg.finished(true); + return Result::Success(result_value) + } + } + } + } + + /// Upload media all at once. + /// If the upload fails for whichever reason, all progress is lost. + /// + /// * *max size*: 16MB + /// * *multipart*: yes + /// * *valid mime types*: 'message/rfc822' + pub fn upload(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 resumeable fashion. + /// Even if the upload fails or is interrupted, it can be resumed for a + /// certain amount of time as the server maintains state temporarily. + /// + /// TODO: Write more about how delegation works in this particular case. + /// + /// * *max size*: 16MB + /// * *multipart*: yes + /// * *valid mime types*: 'message/rfc822' + pub fn upload_resumable(self, resumeable_stream: RS, mime_type: mime::Mime) -> Result<(hyper::client::Response, Groups)> + where RS: ReadSeek { + self.doit(resumeable_stream, mime_type, "resumable") + } + + /// Sets the *group id* path property to the given value. + /// + /// Even though the property as already been set when instantiating this call, + /// we provide this method for API completeness. + /// + /// The group ID + pub fn group_id(mut self, new_value: &str) -> ArchiveInsertCall<'a, C, NC, A> { + self._group_id = new_value.to_string(); + self + } + /// Sets the *delegate* property to the given value. + /// + /// + /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong + /// while executing the actual API request. + /// + /// It should be used to handle progress information, and to implement a certain level of resilience. + pub fn delegate(mut self, new_value: &'a mut Delegate) -> ArchiveInsertCall<'a, C, NC, A> { + self._delegate = Some(new_value); + self + } + + /// Set any additional parameter of the query string used in the request. + /// It should be used to set parameters which are not yet available through their own + /// setters. + /// + /// Please note that this method must not be used to set any of the known paramters + /// which have their own setter method. If done anyway, the request will fail. + /// + /// # Additional Parameters + /// + /// * *quotaUser* (query-string) - Available to use for quota purposes for server-side applications. Can be any arbitrary string assigned to a user, but should not exceed 40 characters. Overrides userIp if both are provided. + /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user. + /// * *key* (query-string) - API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token. + /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks. + /// * *userIp* (query-string) - IP address of the site where the request originates. Use this if you want to enforce per-user limits. + /// * *fields* (query-string) - Selector specifying which fields to include in a partial response. + /// * *alt* (query-string) - Data format for the response. + pub fn param(mut self, name: T, value: T) -> ArchiveInsertCall<'a, C, NC, A> + where T: Str { + self._additional_params.insert(name.as_slice().to_string(), value.as_slice().to_string()); + self + } + + /// Identifies the authorization scope for the method you are building. + /// + /// Use this method to actively specify which scope should be used, instead of relying on the + /// automated algorithm which simply prefers read-only scopes over those who are not. + /// + /// The `scope` will be added to a set of scopes. This is important as one can maintain access + /// tokens for more than one scope. + /// + /// 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(mut self, scope: T) -> ArchiveInsertCall<'a, C, NC, A> + where T: Str { + self._scopes.insert(scope.as_slice().to_string(), ()); + self + } +} + + diff --git a/gen/youtube3/README.md b/gen/youtube3/README.md index 4754d7d948b..cacefccb50b 100644 --- a/gen/youtube3/README.md +++ b/gen/youtube3/README.md @@ -66,13 +66,13 @@ The API is structured into the following primary items: * **[Hub](http://byron.github.io/google-apis-rs/google-youtube3/struct.YouTube.html)** * a central object to maintain state and allow accessing all *Activities* -* **[Resources](http://byron.github.io/google-apis-rs/google-youtube3/cmn/trait.Resource.html)** +* **[Resources](http://byron.github.io/google-apis-rs/google-youtube3/trait.Resource.html)** * primary types that you can apply *Activities* to * a collection of properties and *Parts* - * **[Parts](http://byron.github.io/google-apis-rs/google-youtube3/cmn/trait.Part.html)** + * **[Parts](http://byron.github.io/google-apis-rs/google-youtube3/trait.Part.html)** * a collection of properties * never directly used in *Activities* -* **[Activities](http://byron.github.io/google-apis-rs/google-youtube3/cmn/trait.CallBuilder.html)** +* **[Activities](http://byron.github.io/google-apis-rs/google-youtube3/trait.CallBuilder.html)** * operations to apply to *Resources* Generally speaking, you can invoke *Activities* like this: @@ -106,7 +106,7 @@ To use this library, you would put the following lines into your `Cargo.toml` fi ```toml [dependencies] -google-youtube3 = "0.0.1" +google-youtube3 = "*" ``` ## A complete example @@ -114,7 +114,6 @@ google-youtube3 = "0.0.1" ```Rust extern crate hyper; extern crate "yup-oauth2" as oauth2; -extern crate serde; extern crate "google-youtube3" as youtube3; use youtube3::Result; use std::default::Default; @@ -148,28 +147,29 @@ let result = hub.live_broadcasts().list("part") match result { Result::HttpError(err) => println!("HTTPERROR: {:?}", err), - Result::MissingAPIKey => println!("Missing API Key"), - Result::MissingToken => println!("Missing Token"), - Result::Failure(_) => println!("General Failure (Response doesn't print)"), - Result::FieldClash(clashed_field) => println!("FIELD CLASH: {:?}", clashed_field), - Result::JsonDecodeError(err) => println!("Json failed to decode: {:?}", err), + Result::MissingAPIKey => println!("Auth: Missing API Key - used if there are no scopes"), + Result::MissingToken => println!("OAuth2: Missing Token"), + Result::UploadSizeLimitExceeded(size, max_size) => println!("Upload size too big: {} of {}", size, max_size), + Result::Failure(_) => println!("General Failure (hyper::client::Response doesn't print)"), + Result::FieldClash(clashed_field) => println!("You added custom parameter which is part of builder: {:?}", clashed_field), + Result::JsonDecodeError(err) => println!("Couldn't understand server reply - maybe API needs update: {:?}", err), Result::Success(_) => println!("Success (value doesn't print)"), } ``` ## Handling Errors -All errors produced by the system are provided either as [Result](http://byron.github.io/google-apis-rs/google-youtube3/cmn/enum.Result.html) enumeration as return value of +All errors produced by the system are provided either as [Result](http://byron.github.io/google-apis-rs/google-youtube3/enum.Result.html) enumeration as return value of the doit() methods, or handed as possibly intermediate results to either the -[Hub Delegate](http://byron.github.io/google-apis-rs/google-youtube3/cmn/trait.Delegate.html), or the [Authenticator Delegate](http://byron.github.io/google-apis-rs/google-youtube3/../yup-oauth2/trait.AuthenticatorDelegate.html). +[Hub Delegate](http://byron.github.io/google-apis-rs/google-youtube3/trait.Delegate.html), or the [Authenticator Delegate](http://byron.github.io/google-apis-rs/google-youtube3/../yup-oauth2/trait.AuthenticatorDelegate.html). 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. -## About Uploads and Downlods -If a method supports downloads, the response body, which is part of the [Result](http://byron.github.io/google-apis-rs/google-youtube3/cmn/enum.Result.html), should be +## Uploads and Downlods +If a method supports downloads, the response body, which is part of the [Result](http://byron.github.io/google-apis-rs/google-youtube3/enum.Result.html), should be read by you to obtain the media. -If such a method also supports a [Response Result](http://byron.github.io/google-apis-rs/google-youtube3/cmn/trait.ResponseResult.html), it will return that by default. +If such a method also supports a [Response Result](http://byron.github.io/google-apis-rs/google-youtube3/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")`. @@ -177,30 +177,30 @@ 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. -## About Customization/Callbacks +## Customization and Callbacks -You may alter the way an `doit()` method is called by providing a [delegate](http://byron.github.io/google-apis-rs/google-youtube3/cmn/trait.Delegate.html) to the -[Method Builder](http://byron.github.io/google-apis-rs/google-youtube3/cmn/trait.CallBuilder.html) before making the final `doit()` call. +You may alter the way an `doit()` method is called by providing a [delegate](http://byron.github.io/google-apis-rs/google-youtube3/trait.Delegate.html) to the +[Method Builder](http://byron.github.io/google-apis-rs/google-youtube3/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](http://byron.github.io/google-apis-rs/google-youtube3/cmn/trait.Delegate.html) is default-implemented, allowing you to customize it with minimal effort. +The [delegate trait](http://byron.github.io/google-apis-rs/google-youtube3/trait.Delegate.html) is default-implemented, allowing you to customize it with minimal effort. -## About Parts +## Optional Parts in Server-Requests -All structures provided by this library are made to be [enocodable](http://byron.github.io/google-apis-rs/google-youtube3/cmn/trait.RequestValue.html) and -[decodable](http://byron.github.io/google-apis-rs/google-youtube3/cmn/trait.ResponseResult.html) via json. Optionals are used to indicate that partial requests are responses are valid. -Most optionals are are considered [Parts](http://byron.github.io/google-apis-rs/google-youtube3/cmn/trait.Part.html) which are identifyable by name, which will be sent to +All structures provided by this library are made to be [enocodable](http://byron.github.io/google-apis-rs/google-youtube3/trait.RequestValue.html) and +[decodable](http://byron.github.io/google-apis-rs/google-youtube3/trait.ResponseResult.html) via json. Optionals are used to indicate that partial requests are responses are valid. +Most optionals are are considered [Parts](http://byron.github.io/google-apis-rs/google-youtube3/trait.Part.html) which are identifyable 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. -## About Builder Arguments +## Builder Arguments -Using [method builders](http://byron.github.io/google-apis-rs/google-youtube3/cmn/trait.CallBuilder.html), you are able to prepare an action call by repeatedly calling it's methods. +Using [method builders](http://byron.github.io/google-apis-rs/google-youtube3/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](http://byron.github.io/google-apis-rs/google-youtube3/cmn/trait.RequestValue.html) are borrowed +* [request values](http://byron.github.io/google-apis-rs/google-youtube3/trait.RequestValue.html) are borrowed Arguments will always be copied or cloned into the builder, to make them independent of their original life times. diff --git a/gen/youtube3/cargo.toml b/gen/youtube3/cargo.toml index 55e93a05485..555711b9635 100644 --- a/gen/youtube3/cargo.toml +++ b/gen/youtube3/cargo.toml @@ -4,12 +4,12 @@ [package] name = "google-youtube3" -version = "0.0.1" +version = "0.0.1+20150309" authors = ["Sebastian Thiel "] description = "A complete library to interact with YouTube (protocol v3)" repository = "https://github.com/Byron/google-apis-rs/gen/youtube3/.timestamp" homepage = "https://developers.google.com/youtube/v3" -documentation = "http://byron.github.io/google-apis-rs" +documentation = "http://byron.github.io/google-apis-rs/google-youtube3" license = "MIT" keywords = ["youtube", "google", "protocol", "web", "api"] diff --git a/gen/youtube3/src/cmn.rs b/gen/youtube3/src/cmn.rs index 2ed9d3cfd8c..13ddd954e5d 100644 --- a/gen/youtube3/src/cmn.rs +++ b/gen/youtube3/src/cmn.rs @@ -7,7 +7,7 @@ use std; use mime::{Mime, TopLevel, SubLevel, Attr, Value}; use oauth2; use hyper; -use hyper::header::{ContentType, ContentLength, Headers}; +use hyper::header::{ContentType, ContentLength, Headers, UserAgent, Authorization}; use hyper::http::LINE_ENDING; use hyper::method::Method; @@ -177,7 +177,8 @@ pub trait Delegate { /// /// # Arguments /// - /// `is_success` - a true value indicates the operation was successful + /// `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) { let _ = is_success; } @@ -196,6 +197,10 @@ pub enum Result { /// The http connection failed HttpError(hyper::HttpError), + /// An attempt was made to upload a resource with size stored in field `.0` + /// even though the maximum upload size is what is stored in field `.1`. + UploadSizeLimitExceeded(u64, u64), + /// We needed an API key for authentication, but didn't obtain one. /// Neither through the authenticator, nor through the Delegate. MissingAPIKey, @@ -362,6 +367,8 @@ pub struct ResumableUploadHelper<'a, NC: 'a, A: 'a> { pub client: &'a mut hyper::client::Client, pub delegate: &'a mut Delegate, pub auth: &'a mut A, + pub user_agent: &'a str, + pub auth_token: String, pub url: &'a str, pub reader: &'a mut ReadSeek, pub media_type: Mime, @@ -371,7 +378,19 @@ pub struct ResumableUploadHelper<'a, NC: 'a, A: 'a> { impl<'a, NC, A> ResumableUploadHelper<'a, NC, A> where NC: hyper::net::NetworkConnector, A: oauth2::GetToken { + + fn query_transfer_status(&'a mut self) -> (u64, hyper::HttpResult) { + self.client.post(self.url) + .header(UserAgent(self.user_agent.to_string())) + .header(Authorization("Bearer ".to_string() + &self.auth_token)); + (0, Err(hyper::error::HttpError::HttpStatusError)) + } + pub fn upload(&'a mut self) -> hyper::HttpResult { + let (start, result) = self.query_transfer_status(); + if let Err(_) = result { + return result + } Err(hyper::error::HttpError::HttpStatusError) } } \ No newline at end of file diff --git a/gen/youtube3/src/lib.rs b/gen/youtube3/src/lib.rs index 7305be7be3f..ecb81317ae7 100644 --- a/gen/youtube3/src/lib.rs +++ b/gen/youtube3/src/lib.rs @@ -2,7 +2,7 @@ // This file was generated automatically from 'src/mako/lib.rs.mako' // DO NOT EDIT ! -//! This documentation was generated from *YouTube* crate version *0.0.1*. +//! This documentation was generated from *YouTube* crate version *0.0.1+20150309*. //! The original source code can be found [on github](https://github.com/Byron/google-apis-rs/tree/master/gen/youtube3). //! # Features //! @@ -67,13 +67,13 @@ //! //! * **[Hub](struct.YouTube.html)** //! * a central object to maintain state and allow accessing all *Activities* -//! * **[Resources](cmn/trait.Resource.html)** +//! * **[Resources](trait.Resource.html)** //! * primary types that you can apply *Activities* to //! * a collection of properties and *Parts* -//! * **[Parts](cmn/trait.Part.html)** +//! * **[Parts](trait.Part.html)** //! * a collection of properties //! * never directly used in *Activities* -//! * **[Activities](cmn/trait.CallBuilder.html)** +//! * **[Activities](trait.CallBuilder.html)** //! * operations to apply to *Resources* //! //! Generally speaking, you can invoke *Activities* like this: @@ -107,7 +107,7 @@ //! //! ```toml //! [dependencies] -//! google-youtube3 = "0.0.1" +//! google-youtube3 = "*" //! ``` //! //! ## A complete example @@ -115,7 +115,6 @@ //! ```test_harness,no_run //! extern crate hyper; //! extern crate "yup-oauth2" as oauth2; -//! extern crate serde; //! extern crate "google-youtube3" as youtube3; //! use youtube3::Result; //! # #[test] fn egal() { @@ -150,28 +149,29 @@ //! //! match result { //! Result::HttpError(err) => println!("HTTPERROR: {:?}", err), -//! Result::MissingAPIKey => println!("Missing API Key"), -//! Result::MissingToken => println!("Missing Token"), -//! Result::Failure(_) => println!("General Failure (Response doesn't print)"), -//! Result::FieldClash(clashed_field) => println!("FIELD CLASH: {:?}", clashed_field), -//! Result::JsonDecodeError(err) => println!("Json failed to decode: {:?}", err), +//! Result::MissingAPIKey => println!("Auth: Missing API Key - used if there are no scopes"), +//! Result::MissingToken => println!("OAuth2: Missing Token"), +//! Result::UploadSizeLimitExceeded(size, max_size) => println!("Upload size too big: {} of {}", size, max_size), +//! Result::Failure(_) => println!("General Failure (hyper::client::Response doesn't print)"), +//! Result::FieldClash(clashed_field) => println!("You added custom parameter which is part of builder: {:?}", clashed_field), +//! Result::JsonDecodeError(err) => println!("Couldn't understand server reply - maybe API needs update: {:?}", err), //! Result::Success(_) => println!("Success (value doesn't print)"), //! } //! # } //! ``` //! ## Handling Errors //! -//! All errors produced by the system are provided either as [Result](cmn/enum.Result.html) enumeration as return value of +//! 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](cmn/trait.Delegate.html), or the [Authenticator Delegate](../yup-oauth2/trait.AuthenticatorDelegate.html). +//! [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 //! makes the system potentially resilient to all kinds of errors. //! -//! ## About Uploads and Downlods -//! If a method supports downloads, the response body, which is part of the [Result](cmn/enum.Result.html), should be +//! ## Uploads and Downlods +//! 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](cmn/trait.ResponseResult.html), it will return that by default. +//! 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")`. //! @@ -179,30 +179,30 @@ //! *simple* and *resumable*. The distinctiveness of each is represented by customized //! `doit(...)` methods, which are then named `upload(...)` and `upload_resumable(...)` respectively. //! -//! ## About Customization/Callbacks +//! ## Customization and Callbacks //! -//! You may alter the way an `doit()` method is called by providing a [delegate](cmn/trait.Delegate.html) to the -//! [Method Builder](cmn/trait.CallBuilder.html) before making the final `doit()` call. +//! 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](cmn/trait.Delegate.html) is default-implemented, allowing you to customize it with minimal effort. +//! The [delegate trait](trait.Delegate.html) is default-implemented, allowing you to customize it with minimal effort. //! -//! ## About Parts +//! ## Optional Parts in Server-Requests //! -//! All structures provided by this library are made to be [enocodable](cmn/trait.RequestValue.html) and -//! [decodable](cmn/trait.ResponseResult.html) via json. Optionals are used to indicate that partial requests are responses are valid. -//! Most optionals are are considered [Parts](cmn/trait.Part.html) which are identifyable by name, which will be sent to +//! All structures provided by this library are made to be [enocodable](trait.RequestValue.html) and +//! [decodable](trait.ResponseResult.html) via json. Optionals are used to indicate that partial requests are responses are valid. +//! Most optionals are are considered [Parts](trait.Part.html) which are identifyable by name, which will be sent to //! the server to indicate either the set parts of the request or the desired parts in the response. //! -//! ## About Builder Arguments +//! ## Builder Arguments //! -//! Using [method builders](cmn/trait.CallBuilder.html), you are able to prepare an action call by repeatedly calling it's methods. +//! 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](cmn/trait.RequestValue.html) are borrowed +//! * [request values](trait.RequestValue.html) are borrowed //! //! Arguments will always be copied or cloned into the builder, to make them independent of their original life times. //! @@ -241,7 +241,7 @@ use std::io; use std::fs; use std::thread::sleep; -pub use cmn::{MultiPartReader, ToParts, MethodInfo, Result, CallBuilder, Hub, ReadSeek, Part, ResponseResult, RequestValue, NestedType, Delegate, DefaultDelegate}; +pub use cmn::{MultiPartReader, ToParts, MethodInfo, Result, CallBuilder, Hub, ReadSeek, Part, ResponseResult, RequestValue, NestedType, Delegate, DefaultDelegate, ResourceMethodsBuilder, Resource}; // ############## @@ -306,7 +306,6 @@ impl Default for Scope { /// ```test_harness,no_run /// extern crate hyper; /// extern crate "yup-oauth2" as oauth2; -/// extern crate serde; /// extern crate "google-youtube3" as youtube3; /// use youtube3::Result; /// # #[test] fn egal() { @@ -341,11 +340,12 @@ impl Default for Scope { /// /// match result { /// Result::HttpError(err) => println!("HTTPERROR: {:?}", err), -/// Result::MissingAPIKey => println!("Missing API Key"), -/// Result::MissingToken => println!("Missing Token"), -/// Result::Failure(_) => println!("General Failure (Response doesn't print)"), -/// Result::FieldClash(clashed_field) => println!("FIELD CLASH: {:?}", clashed_field), -/// Result::JsonDecodeError(err) => println!("Json failed to decode: {:?}", err), +/// Result::MissingAPIKey => println!("Auth: Missing API Key - used if there are no scopes"), +/// Result::MissingToken => println!("OAuth2: Missing Token"), +/// Result::UploadSizeLimitExceeded(size, max_size) => println!("Upload size too big: {} of {}", size, max_size), +/// Result::Failure(_) => println!("General Failure (hyper::client::Response doesn't print)"), +/// Result::FieldClash(clashed_field) => println!("You added custom parameter which is part of builder: {:?}", clashed_field), +/// Result::JsonDecodeError(err) => println!("Couldn't understand server reply - maybe API needs update: {:?}", err), /// Result::Success(_) => println!("Success (value doesn't print)"), /// } /// # } @@ -728,8 +728,8 @@ pub struct LiveStream { } impl RequestValue for LiveStream {} +impl Resource for LiveStream {} impl ResponseResult for LiveStream {} -impl cmn::Resource for LiveStream {} impl ToParts for LiveStream { /// Return a comma separated list of members that are currently set, i.e. for which `self.member.is_some()`. @@ -1265,8 +1265,8 @@ pub struct PlaylistItem { } impl RequestValue for PlaylistItem {} +impl Resource for PlaylistItem {} impl ResponseResult for PlaylistItem {} -impl cmn::Resource for PlaylistItem {} impl ToParts for PlaylistItem { /// Return a comma separated list of members that are currently set, i.e. for which `self.member.is_some()`. @@ -1416,7 +1416,7 @@ pub struct I18nRegion { pub id: Option, } -impl cmn::Resource for I18nRegion {} +impl Resource for I18nRegion {} impl ToParts for I18nRegion { /// Return a comma separated list of members that are currently set, i.e. for which `self.member.is_some()`. @@ -1794,8 +1794,8 @@ pub struct Video { } impl RequestValue for Video {} +impl Resource for Video {} impl ResponseResult for Video {} -impl cmn::Resource for Video {} impl ToParts for Video { /// Return a comma separated list of members that are currently set, i.e. for which `self.member.is_some()`. @@ -2034,8 +2034,8 @@ pub struct Subscription { } impl RequestValue for Subscription {} +impl Resource for Subscription {} impl ResponseResult for Subscription {} -impl cmn::Resource for Subscription {} impl ToParts for Subscription { /// Return a comma separated list of members that are currently set, i.e. for which `self.member.is_some()`. @@ -2149,8 +2149,8 @@ pub struct Playlist { } impl RequestValue for Playlist {} +impl Resource for Playlist {} impl ResponseResult for Playlist {} -impl cmn::Resource for Playlist {} impl ToParts for Playlist { /// Return a comma separated list of members that are currently set, i.e. for which `self.member.is_some()`. @@ -2494,8 +2494,8 @@ pub struct LiveBroadcast { } impl RequestValue for LiveBroadcast {} +impl Resource for LiveBroadcast {} impl ResponseResult for LiveBroadcast {} -impl cmn::Resource for LiveBroadcast {} impl ToParts for LiveBroadcast { /// Return a comma separated list of members that are currently set, i.e. for which `self.member.is_some()`. @@ -2565,7 +2565,7 @@ pub struct Thumbnail { pub height: Option, } -impl cmn::Resource for Thumbnail {} +impl Resource for Thumbnail {} /// A channel resource contains information about a YouTube channel. @@ -2618,8 +2618,8 @@ pub struct Channel { } impl RequestValue for Channel {} +impl Resource for Channel {} impl ResponseResult for Channel {} -impl cmn::Resource for Channel {} impl ToParts for Channel { /// Return a comma separated list of members that are currently set, i.e. for which `self.member.is_some()`. @@ -3096,8 +3096,8 @@ pub struct ChannelSection { } impl RequestValue for ChannelSection {} +impl Resource for ChannelSection {} impl ResponseResult for ChannelSection {} -impl cmn::Resource for ChannelSection {} impl ToParts for ChannelSection { /// Return a comma separated list of members that are currently set, i.e. for which `self.member.is_some()`. @@ -3668,7 +3668,7 @@ pub struct I18nLanguage { pub id: Option, } -impl cmn::Resource for I18nLanguage {} +impl Resource for I18nLanguage {} impl ToParts for I18nLanguage { /// Return a comma separated list of members that are currently set, i.e. for which `self.member.is_some()`. @@ -4030,7 +4030,6 @@ impl Part for ChannelContentDetailsRelatedPlaylists {} /// ```test_harness,no_run /// extern crate hyper; /// extern crate "yup-oauth2" as oauth2; -/// extern crate serde; /// extern crate "google-youtube3" as youtube3; /// /// # #[test] fn egal() { @@ -4055,7 +4054,7 @@ pub struct I18nLanguageMethods<'a, C, NC, A> hub: &'a YouTube, } -impl<'a, C, NC, A> cmn::ResourceMethodsBuilder for I18nLanguageMethods<'a, C, NC, A> {} +impl<'a, C, NC, A> ResourceMethodsBuilder for I18nLanguageMethods<'a, C, NC, A> {} impl<'a, C, NC, A> I18nLanguageMethods<'a, C, NC, A> { @@ -4086,7 +4085,6 @@ impl<'a, C, NC, A> I18nLanguageMethods<'a, C, NC, A> { /// ```test_harness,no_run /// extern crate hyper; /// extern crate "yup-oauth2" as oauth2; -/// extern crate serde; /// extern crate "google-youtube3" as youtube3; /// /// # #[test] fn egal() { @@ -4111,7 +4109,7 @@ pub struct ChannelBannerMethods<'a, C, NC, A> hub: &'a YouTube, } -impl<'a, C, NC, A> cmn::ResourceMethodsBuilder for ChannelBannerMethods<'a, C, NC, A> {} +impl<'a, C, NC, A> ResourceMethodsBuilder for ChannelBannerMethods<'a, C, NC, A> {} impl<'a, C, NC, A> ChannelBannerMethods<'a, C, NC, A> { @@ -4146,7 +4144,6 @@ impl<'a, C, NC, A> ChannelBannerMethods<'a, C, NC, A> { /// ```test_harness,no_run /// extern crate hyper; /// extern crate "yup-oauth2" as oauth2; -/// extern crate serde; /// extern crate "google-youtube3" as youtube3; /// /// # #[test] fn egal() { @@ -4171,7 +4168,7 @@ pub struct ChannelSectionMethods<'a, C, NC, A> hub: &'a YouTube, } -impl<'a, C, NC, A> cmn::ResourceMethodsBuilder for ChannelSectionMethods<'a, C, NC, A> {} +impl<'a, C, NC, A> ResourceMethodsBuilder for ChannelSectionMethods<'a, C, NC, A> {} impl<'a, C, NC, A> ChannelSectionMethods<'a, C, NC, A> { @@ -4250,7 +4247,6 @@ impl<'a, C, NC, A> ChannelSectionMethods<'a, C, NC, A> { /// ```test_harness,no_run /// extern crate hyper; /// extern crate "yup-oauth2" as oauth2; -/// extern crate serde; /// extern crate "google-youtube3" as youtube3; /// /// # #[test] fn egal() { @@ -4275,7 +4271,7 @@ pub struct GuideCategoryMethods<'a, C, NC, A> hub: &'a YouTube, } -impl<'a, C, NC, A> cmn::ResourceMethodsBuilder for GuideCategoryMethods<'a, C, NC, A> {} +impl<'a, C, NC, A> ResourceMethodsBuilder for GuideCategoryMethods<'a, C, NC, A> {} impl<'a, C, NC, A> GuideCategoryMethods<'a, C, NC, A> { @@ -4308,7 +4304,6 @@ impl<'a, C, NC, A> GuideCategoryMethods<'a, C, NC, A> { /// ```test_harness,no_run /// extern crate hyper; /// extern crate "yup-oauth2" as oauth2; -/// extern crate serde; /// extern crate "google-youtube3" as youtube3; /// /// # #[test] fn egal() { @@ -4333,7 +4328,7 @@ pub struct PlaylistMethods<'a, C, NC, A> hub: &'a YouTube, } -impl<'a, C, NC, A> cmn::ResourceMethodsBuilder for PlaylistMethods<'a, C, NC, A> {} +impl<'a, C, NC, A> ResourceMethodsBuilder for PlaylistMethods<'a, C, NC, A> {} impl<'a, C, NC, A> PlaylistMethods<'a, C, NC, A> { @@ -4415,7 +4410,6 @@ impl<'a, C, NC, A> PlaylistMethods<'a, C, NC, A> { /// ```test_harness,no_run /// extern crate hyper; /// extern crate "yup-oauth2" as oauth2; -/// extern crate serde; /// extern crate "google-youtube3" as youtube3; /// /// # #[test] fn egal() { @@ -4440,7 +4434,7 @@ pub struct ThumbnailMethods<'a, C, NC, A> hub: &'a YouTube, } -impl<'a, C, NC, A> cmn::ResourceMethodsBuilder for ThumbnailMethods<'a, C, NC, A> {} +impl<'a, C, NC, A> ResourceMethodsBuilder for ThumbnailMethods<'a, C, NC, A> {} impl<'a, C, NC, A> ThumbnailMethods<'a, C, NC, A> { @@ -4471,7 +4465,6 @@ impl<'a, C, NC, A> ThumbnailMethods<'a, C, NC, A> { /// ```test_harness,no_run /// extern crate hyper; /// extern crate "yup-oauth2" as oauth2; -/// extern crate serde; /// extern crate "google-youtube3" as youtube3; /// /// # #[test] fn egal() { @@ -4496,7 +4489,7 @@ pub struct VideoMethods<'a, C, NC, A> hub: &'a YouTube, } -impl<'a, C, NC, A> cmn::ResourceMethodsBuilder for VideoMethods<'a, C, NC, A> {} +impl<'a, C, NC, A> ResourceMethodsBuilder for VideoMethods<'a, C, NC, A> {} impl<'a, C, NC, A> VideoMethods<'a, C, NC, A> { @@ -4613,7 +4606,6 @@ impl<'a, C, NC, A> VideoMethods<'a, C, NC, A> { /// ```test_harness,no_run /// extern crate hyper; /// extern crate "yup-oauth2" as oauth2; -/// extern crate serde; /// extern crate "google-youtube3" as youtube3; /// /// # #[test] fn egal() { @@ -4638,7 +4630,7 @@ pub struct SubscriptionMethods<'a, C, NC, A> hub: &'a YouTube, } -impl<'a, C, NC, A> cmn::ResourceMethodsBuilder for SubscriptionMethods<'a, C, NC, A> {} +impl<'a, C, NC, A> ResourceMethodsBuilder for SubscriptionMethods<'a, C, NC, A> {} impl<'a, C, NC, A> SubscriptionMethods<'a, C, NC, A> { @@ -4705,7 +4697,6 @@ impl<'a, C, NC, A> SubscriptionMethods<'a, C, NC, A> { /// ```test_harness,no_run /// extern crate hyper; /// extern crate "yup-oauth2" as oauth2; -/// extern crate serde; /// extern crate "google-youtube3" as youtube3; /// /// # #[test] fn egal() { @@ -4730,7 +4721,7 @@ pub struct SearchMethods<'a, C, NC, A> hub: &'a YouTube, } -impl<'a, C, NC, A> cmn::ResourceMethodsBuilder for SearchMethods<'a, C, NC, A> {} +impl<'a, C, NC, A> ResourceMethodsBuilder for SearchMethods<'a, C, NC, A> {} impl<'a, C, NC, A> SearchMethods<'a, C, NC, A> { @@ -4789,7 +4780,6 @@ impl<'a, C, NC, A> SearchMethods<'a, C, NC, A> { /// ```test_harness,no_run /// extern crate hyper; /// extern crate "yup-oauth2" as oauth2; -/// extern crate serde; /// extern crate "google-youtube3" as youtube3; /// /// # #[test] fn egal() { @@ -4814,7 +4804,7 @@ pub struct I18nRegionMethods<'a, C, NC, A> hub: &'a YouTube, } -impl<'a, C, NC, A> cmn::ResourceMethodsBuilder for I18nRegionMethods<'a, C, NC, A> {} +impl<'a, C, NC, A> ResourceMethodsBuilder for I18nRegionMethods<'a, C, NC, A> {} impl<'a, C, NC, A> I18nRegionMethods<'a, C, NC, A> { @@ -4845,7 +4835,6 @@ impl<'a, C, NC, A> I18nRegionMethods<'a, C, NC, A> { /// ```test_harness,no_run /// extern crate hyper; /// extern crate "yup-oauth2" as oauth2; -/// extern crate serde; /// extern crate "google-youtube3" as youtube3; /// /// # #[test] fn egal() { @@ -4870,7 +4859,7 @@ pub struct LiveStreamMethods<'a, C, NC, A> hub: &'a YouTube, } -impl<'a, C, NC, A> cmn::ResourceMethodsBuilder for LiveStreamMethods<'a, C, NC, A> {} +impl<'a, C, NC, A> ResourceMethodsBuilder for LiveStreamMethods<'a, C, NC, A> {} impl<'a, C, NC, A> LiveStreamMethods<'a, C, NC, A> { @@ -4953,7 +4942,6 @@ impl<'a, C, NC, A> LiveStreamMethods<'a, C, NC, A> { /// ```test_harness,no_run /// extern crate hyper; /// extern crate "yup-oauth2" as oauth2; -/// extern crate serde; /// extern crate "google-youtube3" as youtube3; /// /// # #[test] fn egal() { @@ -4978,7 +4966,7 @@ pub struct ChannelMethods<'a, C, NC, A> hub: &'a YouTube, } -impl<'a, C, NC, A> cmn::ResourceMethodsBuilder for ChannelMethods<'a, C, NC, A> {} +impl<'a, C, NC, A> ResourceMethodsBuilder for ChannelMethods<'a, C, NC, A> {} impl<'a, C, NC, A> ChannelMethods<'a, C, NC, A> { @@ -5032,7 +5020,6 @@ impl<'a, C, NC, A> ChannelMethods<'a, C, NC, A> { /// ```test_harness,no_run /// extern crate hyper; /// extern crate "yup-oauth2" as oauth2; -/// extern crate serde; /// extern crate "google-youtube3" as youtube3; /// /// # #[test] fn egal() { @@ -5057,7 +5044,7 @@ pub struct PlaylistItemMethods<'a, C, NC, A> hub: &'a YouTube, } -impl<'a, C, NC, A> cmn::ResourceMethodsBuilder for PlaylistItemMethods<'a, C, NC, A> {} +impl<'a, C, NC, A> ResourceMethodsBuilder for PlaylistItemMethods<'a, C, NC, A> {} impl<'a, C, NC, A> PlaylistItemMethods<'a, C, NC, A> { @@ -5135,7 +5122,6 @@ impl<'a, C, NC, A> PlaylistItemMethods<'a, C, NC, A> { /// ```test_harness,no_run /// extern crate hyper; /// extern crate "yup-oauth2" as oauth2; -/// extern crate serde; /// extern crate "google-youtube3" as youtube3; /// /// # #[test] fn egal() { @@ -5160,7 +5146,7 @@ pub struct WatermarkMethods<'a, C, NC, A> hub: &'a YouTube, } -impl<'a, C, NC, A> cmn::ResourceMethodsBuilder for WatermarkMethods<'a, C, NC, A> {} +impl<'a, C, NC, A> ResourceMethodsBuilder for WatermarkMethods<'a, C, NC, A> {} impl<'a, C, NC, A> WatermarkMethods<'a, C, NC, A> { @@ -5206,7 +5192,6 @@ impl<'a, C, NC, A> WatermarkMethods<'a, C, NC, A> { /// ```test_harness,no_run /// extern crate hyper; /// extern crate "yup-oauth2" as oauth2; -/// extern crate serde; /// extern crate "google-youtube3" as youtube3; /// /// # #[test] fn egal() { @@ -5231,7 +5216,7 @@ pub struct LiveBroadcastMethods<'a, C, NC, A> hub: &'a YouTube, } -impl<'a, C, NC, A> cmn::ResourceMethodsBuilder for LiveBroadcastMethods<'a, C, NC, A> {} +impl<'a, C, NC, A> ResourceMethodsBuilder for LiveBroadcastMethods<'a, C, NC, A> {} impl<'a, C, NC, A> LiveBroadcastMethods<'a, C, NC, A> { @@ -5368,7 +5353,6 @@ impl<'a, C, NC, A> LiveBroadcastMethods<'a, C, NC, A> { /// ```test_harness,no_run /// extern crate hyper; /// extern crate "yup-oauth2" as oauth2; -/// extern crate serde; /// extern crate "google-youtube3" as youtube3; /// /// # #[test] fn egal() { @@ -5393,7 +5377,7 @@ pub struct VideoCategoryMethods<'a, C, NC, A> hub: &'a YouTube, } -impl<'a, C, NC, A> cmn::ResourceMethodsBuilder for VideoCategoryMethods<'a, C, NC, A> {} +impl<'a, C, NC, A> ResourceMethodsBuilder for VideoCategoryMethods<'a, C, NC, A> {} impl<'a, C, NC, A> VideoCategoryMethods<'a, C, NC, A> { @@ -5426,7 +5410,6 @@ impl<'a, C, NC, A> VideoCategoryMethods<'a, C, NC, A> { /// ```test_harness,no_run /// extern crate hyper; /// extern crate "yup-oauth2" as oauth2; -/// extern crate serde; /// extern crate "google-youtube3" as youtube3; /// /// # #[test] fn egal() { @@ -5451,7 +5434,7 @@ pub struct ActivityMethods<'a, C, NC, A> hub: &'a YouTube, } -impl<'a, C, NC, A> cmn::ResourceMethodsBuilder for ActivityMethods<'a, C, NC, A> {} +impl<'a, C, NC, A> ResourceMethodsBuilder for ActivityMethods<'a, C, NC, A> {} impl<'a, C, NC, A> ActivityMethods<'a, C, NC, A> { @@ -5527,7 +5510,6 @@ impl<'a, C, NC, A> ActivityMethods<'a, C, NC, A> { /// ```test_harness,no_run /// # extern crate hyper; /// # extern crate "yup-oauth2" as oauth2; -/// # extern crate serde; /// # extern crate "google-youtube3" as youtube3; /// # #[test] fn egal() { /// # use std::default::Default; @@ -5614,12 +5596,12 @@ impl<'a, C, NC, A> I18nLanguageListCall<'a, C, NC, A> where NC: hyper::net::Netw dlg.finished(false); return Result::MissingToken } - let auth_header = Authorization(token.unwrap().access_token); + let auth_header = Authorization("Bearer ".to_string() + &token.unwrap().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_slice()) .header(UserAgent(self.hub._user_agent.clone())) - .header(auth_header); + .header(auth_header.clone()); dlg.pre_request(); req.send() @@ -5759,7 +5741,6 @@ impl<'a, C, NC, A> I18nLanguageListCall<'a, C, NC, A> where NC: hyper::net::Netw /// ```test_harness,no_run /// # extern crate hyper; /// # extern crate "yup-oauth2" as oauth2; -/// # extern crate serde; /// # extern crate "google-youtube3" as youtube3; /// use youtube3::ChannelBannerResource; /// use std::fs; @@ -5855,6 +5836,7 @@ impl<'a, C, NC, A> ChannelBannerInsertCall<'a, C, NC, A> where NC: hyper::net::N request_value_reader.seek(io::SeekFrom::Start(0)).unwrap(); let mut should_ask_dlg_for_url = false; + let mut upload_url_from_server = true; let mut upload_url: Option = None; loop { @@ -5866,14 +5848,18 @@ impl<'a, C, NC, A> ChannelBannerInsertCall<'a, C, NC, A> where NC: hyper::net::N dlg.finished(false); return Result::MissingToken } - let auth_header = Authorization(token.unwrap().access_token); + let auth_header = Authorization("Bearer ".to_string() + &token.unwrap().access_token); request_value_reader.seek(io::SeekFrom::Start(0)).unwrap(); let mut req_result = { if should_ask_dlg_for_url && (upload_url = dlg.upload_url()) == () && upload_url.is_some() { should_ask_dlg_for_url = false; + upload_url_from_server = false; let mut response = hyper::client::Response::new(Box::new(cmn::DummyNetworkStream)); match response { - Ok(ref mut res) => res.headers.set(Location(upload_url.as_ref().unwrap().clone())), + Ok(ref mut res) => { + res.status = hyper::status::StatusCode::Ok; + res.headers.set(Location(upload_url.as_ref().unwrap().clone())) + } _ => unreachable!(), } response @@ -5884,6 +5870,9 @@ impl<'a, C, NC, A> ChannelBannerInsertCall<'a, C, NC, A> where NC: hyper::net::N mp_reader.reserve_exact(2); let size = reader.seek(io::SeekFrom::End(0)).unwrap(); reader.seek(io::SeekFrom::Start(0)).unwrap(); + if size > 0 { + return Result::UploadSizeLimitExceeded(size, 0) + } mp_reader.add_part(&mut request_value_reader, request_size, json_mime_type.clone()) .add_part(&mut reader, size, reader_mime_type.clone()); let mime_type = mp_reader.mime_type(); @@ -5894,9 +5883,10 @@ impl<'a, C, NC, A> ChannelBannerInsertCall<'a, C, NC, A> where NC: hyper::net::N let mut client = &mut *self.hub.client.borrow_mut(); let mut req = client.borrow_mut().request(hyper::method::Method::Post, url.as_slice()) .header(UserAgent(self.hub._user_agent.clone())) - .header(auth_header) + .header(auth_header.clone()) .header(content_type) .body(body_reader.into_body()); + upload_url_from_server = true; if protocol == "resumable" { req = req.header(cmn::XUploadContentType(reader_mime_type.clone())); } @@ -5931,16 +5921,29 @@ impl<'a, C, NC, A> ChannelBannerInsertCall<'a, C, NC, A> where NC: hyper::net::N if protocol == "resumable" { let size = reader.seek(io::SeekFrom::End(0)).unwrap(); reader.seek(io::SeekFrom::Start(0)).unwrap(); + if size > 0 { + return Result::UploadSizeLimitExceeded(size, 0) + } let mut client = &mut *self.hub.client.borrow_mut(); - match (cmn::ResumableUploadHelper { - client: &mut client.borrow_mut(), - delegate: dlg, - auth: &mut *self.hub.auth.borrow_mut(), - url: &res.headers.get::().expect("Location header is part of protocol").0, - reader: &mut reader, - media_type: reader_mime_type.clone(), - content_size: size - }.upload()) { + let upload_result = { + let url = &res.headers.get::().expect("Location header is part of protocol").0; + if upload_url_from_server { + dlg.store_upload_url(url); + } + + cmn::ResumableUploadHelper { + client: &mut client.borrow_mut(), + delegate: dlg, + auth: &mut *self.hub.auth.borrow_mut(), + user_agent: &self.hub._user_agent, + auth_token: auth_header.0.clone(), + url: url, + reader: &mut reader, + media_type: reader_mime_type.clone(), + content_size: size + }.upload() + }; + match upload_result { Err(err) => { dlg.finished(false); return Result::HttpError(err) @@ -6090,7 +6093,6 @@ impl<'a, C, NC, A> ChannelBannerInsertCall<'a, C, NC, A> where NC: hyper::net::N /// ```test_harness,no_run /// # extern crate hyper; /// # extern crate "yup-oauth2" as oauth2; -/// # extern crate serde; /// # extern crate "google-youtube3" as youtube3; /// # #[test] fn egal() { /// # use std::default::Default; @@ -6192,12 +6194,12 @@ impl<'a, C, NC, A> ChannelSectionListCall<'a, C, NC, A> where NC: hyper::net::Ne dlg.finished(false); return Result::MissingToken } - let auth_header = Authorization(token.unwrap().access_token); + let auth_header = Authorization("Bearer ".to_string() + &token.unwrap().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_slice()) .header(UserAgent(self.hub._user_agent.clone())) - .header(auth_header); + .header(auth_header.clone()); dlg.pre_request(); req.send() @@ -6375,7 +6377,6 @@ impl<'a, C, NC, A> ChannelSectionListCall<'a, C, NC, A> where NC: hyper::net::Ne /// ```test_harness,no_run /// # extern crate hyper; /// # extern crate "yup-oauth2" as oauth2; -/// # extern crate serde; /// # extern crate "google-youtube3" as youtube3; /// use youtube3::ChannelSection; /// # #[test] fn egal() { @@ -6483,13 +6484,13 @@ impl<'a, C, NC, A> ChannelSectionInsertCall<'a, C, NC, A> where NC: hyper::net:: dlg.finished(false); return Result::MissingToken } - let auth_header = Authorization(token.unwrap().access_token); + let auth_header = Authorization("Bearer ".to_string() + &token.unwrap().access_token); 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_slice()) .header(UserAgent(self.hub._user_agent.clone())) - .header(auth_header) + .header(auth_header.clone()) .header(ContentType(json_mime_type.clone())) .header(ContentLength(request_size as u64)) .body(request_value_reader.into_body()); @@ -6661,7 +6662,6 @@ impl<'a, C, NC, A> ChannelSectionInsertCall<'a, C, NC, A> where NC: hyper::net:: /// ```test_harness,no_run /// # extern crate hyper; /// # extern crate "yup-oauth2" as oauth2; -/// # extern crate serde; /// # extern crate "google-youtube3" as youtube3; /// # #[test] fn egal() { /// # use std::default::Default; @@ -6747,12 +6747,12 @@ impl<'a, C, NC, A> ChannelSectionDeleteCall<'a, C, NC, A> where NC: hyper::net:: dlg.finished(false); return Result::MissingToken } - let auth_header = Authorization(token.unwrap().access_token); + let auth_header = Authorization("Bearer ".to_string() + &token.unwrap().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_slice()) .header(UserAgent(self.hub._user_agent.clone())) - .header(auth_header); + .header(auth_header.clone()); dlg.pre_request(); req.send() @@ -6888,7 +6888,6 @@ impl<'a, C, NC, A> ChannelSectionDeleteCall<'a, C, NC, A> where NC: hyper::net:: /// ```test_harness,no_run /// # extern crate hyper; /// # extern crate "yup-oauth2" as oauth2; -/// # extern crate serde; /// # extern crate "google-youtube3" as youtube3; /// use youtube3::ChannelSection; /// # #[test] fn egal() { @@ -6991,13 +6990,13 @@ impl<'a, C, NC, A> ChannelSectionUpdateCall<'a, C, NC, A> where NC: hyper::net:: dlg.finished(false); return Result::MissingToken } - let auth_header = Authorization(token.unwrap().access_token); + let auth_header = Authorization("Bearer ".to_string() + &token.unwrap().access_token); 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_slice()) .header(UserAgent(self.hub._user_agent.clone())) - .header(auth_header) + .header(auth_header.clone()) .header(ContentType(json_mime_type.clone())) .header(ContentLength(request_size as u64)) .body(request_value_reader.into_body()); @@ -7171,7 +7170,6 @@ impl<'a, C, NC, A> ChannelSectionUpdateCall<'a, C, NC, A> where NC: hyper::net:: /// ```test_harness,no_run /// # extern crate hyper; /// # extern crate "yup-oauth2" as oauth2; -/// # extern crate serde; /// # extern crate "google-youtube3" as youtube3; /// # #[test] fn egal() { /// # use std::default::Default; @@ -7268,12 +7266,12 @@ impl<'a, C, NC, A> GuideCategoryListCall<'a, C, NC, A> where NC: hyper::net::Net dlg.finished(false); return Result::MissingToken } - let auth_header = Authorization(token.unwrap().access_token); + let auth_header = Authorization("Bearer ".to_string() + &token.unwrap().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_slice()) .header(UserAgent(self.hub._user_agent.clone())) - .header(auth_header); + .header(auth_header.clone()); dlg.pre_request(); req.send() @@ -7440,7 +7438,6 @@ impl<'a, C, NC, A> GuideCategoryListCall<'a, C, NC, A> where NC: hyper::net::Net /// ```test_harness,no_run /// # extern crate hyper; /// # extern crate "yup-oauth2" as oauth2; -/// # extern crate serde; /// # extern crate "google-youtube3" as youtube3; /// use youtube3::Playlist; /// # #[test] fn egal() { @@ -7548,13 +7545,13 @@ impl<'a, C, NC, A> PlaylistInsertCall<'a, C, NC, A> where NC: hyper::net::Networ dlg.finished(false); return Result::MissingToken } - let auth_header = Authorization(token.unwrap().access_token); + let auth_header = Authorization("Bearer ".to_string() + &token.unwrap().access_token); 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_slice()) .header(UserAgent(self.hub._user_agent.clone())) - .header(auth_header) + .header(auth_header.clone()) .header(ContentType(json_mime_type.clone())) .header(ContentLength(request_size as u64)) .body(request_value_reader.into_body()); @@ -7742,7 +7739,6 @@ impl<'a, C, NC, A> PlaylistInsertCall<'a, C, NC, A> where NC: hyper::net::Networ /// ```test_harness,no_run /// # extern crate hyper; /// # extern crate "yup-oauth2" as oauth2; -/// # extern crate serde; /// # extern crate "google-youtube3" as youtube3; /// # #[test] fn egal() { /// # use std::default::Default; @@ -7859,12 +7855,12 @@ impl<'a, C, NC, A> PlaylistListCall<'a, C, NC, A> where NC: hyper::net::NetworkC dlg.finished(false); return Result::MissingToken } - let auth_header = Authorization(token.unwrap().access_token); + let auth_header = Authorization("Bearer ".to_string() + &token.unwrap().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_slice()) .header(UserAgent(self.hub._user_agent.clone())) - .header(auth_header); + .header(auth_header.clone()); dlg.pre_request(); req.send() @@ -8058,7 +8054,6 @@ impl<'a, C, NC, A> PlaylistListCall<'a, C, NC, A> where NC: hyper::net::NetworkC /// ```test_harness,no_run /// # extern crate hyper; /// # extern crate "yup-oauth2" as oauth2; -/// # extern crate serde; /// # extern crate "google-youtube3" as youtube3; /// # #[test] fn egal() { /// # use std::default::Default; @@ -8144,12 +8139,12 @@ impl<'a, C, NC, A> PlaylistDeleteCall<'a, C, NC, A> where NC: hyper::net::Networ dlg.finished(false); return Result::MissingToken } - let auth_header = Authorization(token.unwrap().access_token); + let auth_header = Authorization("Bearer ".to_string() + &token.unwrap().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_slice()) .header(UserAgent(self.hub._user_agent.clone())) - .header(auth_header); + .header(auth_header.clone()); dlg.pre_request(); req.send() @@ -8285,7 +8280,6 @@ impl<'a, C, NC, A> PlaylistDeleteCall<'a, C, NC, A> where NC: hyper::net::Networ /// ```test_harness,no_run /// # extern crate hyper; /// # extern crate "yup-oauth2" as oauth2; -/// # extern crate serde; /// # extern crate "google-youtube3" as youtube3; /// use youtube3::Playlist; /// # #[test] fn egal() { @@ -8388,13 +8382,13 @@ impl<'a, C, NC, A> PlaylistUpdateCall<'a, C, NC, A> where NC: hyper::net::Networ dlg.finished(false); return Result::MissingToken } - let auth_header = Authorization(token.unwrap().access_token); + let auth_header = Authorization("Bearer ".to_string() + &token.unwrap().access_token); 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_slice()) .header(UserAgent(self.hub._user_agent.clone())) - .header(auth_header) + .header(auth_header.clone()) .header(ContentType(json_mime_type.clone())) .header(ContentLength(request_size as u64)) .body(request_value_reader.into_body()); @@ -8556,7 +8550,6 @@ impl<'a, C, NC, A> PlaylistUpdateCall<'a, C, NC, A> where NC: hyper::net::Networ /// ```test_harness,no_run /// # extern crate hyper; /// # extern crate "yup-oauth2" as oauth2; -/// # extern crate serde; /// # extern crate "google-youtube3" as youtube3; /// use std::fs; /// # #[test] fn egal() { @@ -8643,6 +8636,7 @@ impl<'a, C, NC, A> ThumbnailSetCall<'a, C, NC, A> where NC: hyper::net::NetworkC let mut should_ask_dlg_for_url = false; + let mut upload_url_from_server = true; let mut upload_url: Option = None; loop { @@ -8654,13 +8648,17 @@ impl<'a, C, NC, A> ThumbnailSetCall<'a, C, NC, A> where NC: hyper::net::NetworkC dlg.finished(false); return Result::MissingToken } - let auth_header = Authorization(token.unwrap().access_token); + let auth_header = Authorization("Bearer ".to_string() + &token.unwrap().access_token); let mut req_result = { if should_ask_dlg_for_url && (upload_url = dlg.upload_url()) == () && upload_url.is_some() { should_ask_dlg_for_url = false; + upload_url_from_server = false; let mut response = hyper::client::Response::new(Box::new(cmn::DummyNetworkStream)); match response { - Ok(ref mut res) => res.headers.set(Location(upload_url.as_ref().unwrap().clone())), + Ok(ref mut res) => { + res.status = hyper::status::StatusCode::Ok; + res.headers.set(Location(upload_url.as_ref().unwrap().clone())) + } _ => unreachable!(), } response @@ -8668,14 +8666,18 @@ impl<'a, C, NC, A> ThumbnailSetCall<'a, C, NC, A> where NC: hyper::net::NetworkC let mut client = &mut *self.hub.client.borrow_mut(); let mut req = client.borrow_mut().request(hyper::method::Method::Post, url.as_slice()) .header(UserAgent(self.hub._user_agent.clone())) - .header(auth_header); + .header(auth_header.clone()); if protocol == "simple" { let size = reader.seek(io::SeekFrom::End(0)).unwrap(); reader.seek(io::SeekFrom::Start(0)).unwrap(); + if size > 0 { + return Result::UploadSizeLimitExceeded(size, 0) + } req = req.header(ContentType(reader_mime_type.clone())) .header(ContentLength(size)) .body(reader.into_body()); } + upload_url_from_server = true; if protocol == "resumable" { req = req.header(cmn::XUploadContentType(reader_mime_type.clone())); } @@ -8710,16 +8712,29 @@ impl<'a, C, NC, A> ThumbnailSetCall<'a, C, NC, A> where NC: hyper::net::NetworkC if protocol == "resumable" { let size = reader.seek(io::SeekFrom::End(0)).unwrap(); reader.seek(io::SeekFrom::Start(0)).unwrap(); + if size > 0 { + return Result::UploadSizeLimitExceeded(size, 0) + } let mut client = &mut *self.hub.client.borrow_mut(); - match (cmn::ResumableUploadHelper { - client: &mut client.borrow_mut(), - delegate: dlg, - auth: &mut *self.hub.auth.borrow_mut(), - url: &res.headers.get::().expect("Location header is part of protocol").0, - reader: &mut reader, - media_type: reader_mime_type.clone(), - content_size: size - }.upload()) { + let upload_result = { + let url = &res.headers.get::().expect("Location header is part of protocol").0; + if upload_url_from_server { + dlg.store_upload_url(url); + } + + cmn::ResumableUploadHelper { + client: &mut client.borrow_mut(), + delegate: dlg, + auth: &mut *self.hub.auth.borrow_mut(), + user_agent: &self.hub._user_agent, + auth_token: auth_header.0.clone(), + url: url, + reader: &mut reader, + media_type: reader_mime_type.clone(), + content_size: size + }.upload() + }; + match upload_result { Err(err) => { dlg.finished(false); return Result::HttpError(err) @@ -8878,7 +8893,6 @@ impl<'a, C, NC, A> ThumbnailSetCall<'a, C, NC, A> where NC: hyper::net::NetworkC /// ```test_harness,no_run /// # extern crate hyper; /// # extern crate "yup-oauth2" as oauth2; -/// # extern crate serde; /// # extern crate "google-youtube3" as youtube3; /// # #[test] fn egal() { /// # use std::default::Default; @@ -9010,12 +9024,12 @@ impl<'a, C, NC, A> VideoListCall<'a, C, NC, A> where NC: hyper::net::NetworkConn dlg.finished(false); return Result::MissingToken } - let auth_header = Authorization(token.unwrap().access_token); + let auth_header = Authorization("Bearer ".to_string() + &token.unwrap().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_slice()) .header(UserAgent(self.hub._user_agent.clone())) - .header(auth_header); + .header(auth_header.clone()); dlg.pre_request(); req.send() @@ -9242,7 +9256,6 @@ impl<'a, C, NC, A> VideoListCall<'a, C, NC, A> where NC: hyper::net::NetworkConn /// ```test_harness,no_run /// # extern crate hyper; /// # extern crate "yup-oauth2" as oauth2; -/// # extern crate serde; /// # extern crate "google-youtube3" as youtube3; /// # #[test] fn egal() { /// # use std::default::Default; @@ -9330,12 +9343,12 @@ impl<'a, C, NC, A> VideoRateCall<'a, C, NC, A> where NC: hyper::net::NetworkConn dlg.finished(false); return Result::MissingToken } - let auth_header = Authorization(token.unwrap().access_token); + let auth_header = Authorization("Bearer ".to_string() + &token.unwrap().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_slice()) .header(UserAgent(self.hub._user_agent.clone())) - .header(auth_header); + .header(auth_header.clone()); dlg.pre_request(); req.send() @@ -9468,7 +9481,6 @@ impl<'a, C, NC, A> VideoRateCall<'a, C, NC, A> where NC: hyper::net::NetworkConn /// ```test_harness,no_run /// # extern crate hyper; /// # extern crate "yup-oauth2" as oauth2; -/// # extern crate serde; /// # extern crate "google-youtube3" as youtube3; /// # #[test] fn egal() { /// # use std::default::Default; @@ -9555,12 +9567,12 @@ impl<'a, C, NC, A> VideoGetRatingCall<'a, C, NC, A> where NC: hyper::net::Networ dlg.finished(false); return Result::MissingToken } - let auth_header = Authorization(token.unwrap().access_token); + let auth_header = Authorization("Bearer ".to_string() + &token.unwrap().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_slice()) .header(UserAgent(self.hub._user_agent.clone())) - .header(auth_header); + .header(auth_header.clone()); dlg.pre_request(); req.send() @@ -9693,7 +9705,6 @@ impl<'a, C, NC, A> VideoGetRatingCall<'a, C, NC, A> where NC: hyper::net::Networ /// ```test_harness,no_run /// # extern crate hyper; /// # extern crate "yup-oauth2" as oauth2; -/// # extern crate serde; /// # extern crate "google-youtube3" as youtube3; /// # #[test] fn egal() { /// # use std::default::Default; @@ -9779,12 +9790,12 @@ impl<'a, C, NC, A> VideoDeleteCall<'a, C, NC, A> where NC: hyper::net::NetworkCo dlg.finished(false); return Result::MissingToken } - let auth_header = Authorization(token.unwrap().access_token); + let auth_header = Authorization("Bearer ".to_string() + &token.unwrap().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_slice()) .header(UserAgent(self.hub._user_agent.clone())) - .header(auth_header); + .header(auth_header.clone()); dlg.pre_request(); req.send() @@ -9930,7 +9941,6 @@ impl<'a, C, NC, A> VideoDeleteCall<'a, C, NC, A> where NC: hyper::net::NetworkCo /// ```test_harness,no_run /// # extern crate hyper; /// # extern crate "yup-oauth2" as oauth2; -/// # extern crate serde; /// # extern crate "google-youtube3" as youtube3; /// use youtube3::Video; /// # #[test] fn egal() { @@ -10043,13 +10053,13 @@ impl<'a, C, NC, A> VideoUpdateCall<'a, C, NC, A> where NC: hyper::net::NetworkCo dlg.finished(false); return Result::MissingToken } - let auth_header = Authorization(token.unwrap().access_token); + let auth_header = Authorization("Bearer ".to_string() + &token.unwrap().access_token); 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_slice()) .header(UserAgent(self.hub._user_agent.clone())) - .header(auth_header) + .header(auth_header.clone()) .header(ContentType(json_mime_type.clone())) .header(ContentLength(request_size as u64)) .body(request_value_reader.into_body()); @@ -10257,7 +10267,6 @@ impl<'a, C, NC, A> VideoUpdateCall<'a, C, NC, A> where NC: hyper::net::NetworkCo /// ```test_harness,no_run /// # extern crate hyper; /// # extern crate "yup-oauth2" as oauth2; -/// # extern crate serde; /// # extern crate "google-youtube3" as youtube3; /// use youtube3::Video; /// use std::fs; @@ -10390,6 +10399,7 @@ impl<'a, C, NC, A> VideoInsertCall<'a, C, NC, A> where NC: hyper::net::NetworkCo request_value_reader.seek(io::SeekFrom::Start(0)).unwrap(); let mut should_ask_dlg_for_url = false; + let mut upload_url_from_server = true; let mut upload_url: Option = None; loop { @@ -10401,14 +10411,18 @@ impl<'a, C, NC, A> VideoInsertCall<'a, C, NC, A> where NC: hyper::net::NetworkCo dlg.finished(false); return Result::MissingToken } - let auth_header = Authorization(token.unwrap().access_token); + let auth_header = Authorization("Bearer ".to_string() + &token.unwrap().access_token); request_value_reader.seek(io::SeekFrom::Start(0)).unwrap(); let mut req_result = { if should_ask_dlg_for_url && (upload_url = dlg.upload_url()) == () && upload_url.is_some() { should_ask_dlg_for_url = false; + upload_url_from_server = false; let mut response = hyper::client::Response::new(Box::new(cmn::DummyNetworkStream)); match response { - Ok(ref mut res) => res.headers.set(Location(upload_url.as_ref().unwrap().clone())), + Ok(ref mut res) => { + res.status = hyper::status::StatusCode::Ok; + res.headers.set(Location(upload_url.as_ref().unwrap().clone())) + } _ => unreachable!(), } response @@ -10419,6 +10433,9 @@ impl<'a, C, NC, A> VideoInsertCall<'a, C, NC, A> where NC: hyper::net::NetworkCo mp_reader.reserve_exact(2); let size = reader.seek(io::SeekFrom::End(0)).unwrap(); reader.seek(io::SeekFrom::Start(0)).unwrap(); + if size > 0 { + return Result::UploadSizeLimitExceeded(size, 0) + } mp_reader.add_part(&mut request_value_reader, request_size, json_mime_type.clone()) .add_part(&mut reader, size, reader_mime_type.clone()); let mime_type = mp_reader.mime_type(); @@ -10429,9 +10446,10 @@ impl<'a, C, NC, A> VideoInsertCall<'a, C, NC, A> where NC: hyper::net::NetworkCo let mut client = &mut *self.hub.client.borrow_mut(); let mut req = client.borrow_mut().request(hyper::method::Method::Post, url.as_slice()) .header(UserAgent(self.hub._user_agent.clone())) - .header(auth_header) + .header(auth_header.clone()) .header(content_type) .body(body_reader.into_body()); + upload_url_from_server = true; if protocol == "resumable" { req = req.header(cmn::XUploadContentType(reader_mime_type.clone())); } @@ -10466,16 +10484,29 @@ impl<'a, C, NC, A> VideoInsertCall<'a, C, NC, A> where NC: hyper::net::NetworkCo if protocol == "resumable" { let size = reader.seek(io::SeekFrom::End(0)).unwrap(); reader.seek(io::SeekFrom::Start(0)).unwrap(); + if size > 0 { + return Result::UploadSizeLimitExceeded(size, 0) + } let mut client = &mut *self.hub.client.borrow_mut(); - match (cmn::ResumableUploadHelper { - client: &mut client.borrow_mut(), - delegate: dlg, - auth: &mut *self.hub.auth.borrow_mut(), - url: &res.headers.get::().expect("Location header is part of protocol").0, - reader: &mut reader, - media_type: reader_mime_type.clone(), - content_size: size - }.upload()) { + let upload_result = { + let url = &res.headers.get::().expect("Location header is part of protocol").0; + if upload_url_from_server { + dlg.store_upload_url(url); + } + + cmn::ResumableUploadHelper { + client: &mut client.borrow_mut(), + delegate: dlg, + auth: &mut *self.hub.auth.borrow_mut(), + user_agent: &self.hub._user_agent, + auth_token: auth_header.0.clone(), + url: url, + reader: &mut reader, + media_type: reader_mime_type.clone(), + content_size: size + }.upload() + }; + match upload_result { Err(err) => { dlg.finished(false); return Result::HttpError(err) @@ -10704,7 +10735,6 @@ impl<'a, C, NC, A> VideoInsertCall<'a, C, NC, A> where NC: hyper::net::NetworkCo /// ```test_harness,no_run /// # extern crate hyper; /// # extern crate "yup-oauth2" as oauth2; -/// # extern crate serde; /// # extern crate "google-youtube3" as youtube3; /// use youtube3::Subscription; /// # #[test] fn egal() { @@ -10802,13 +10832,13 @@ impl<'a, C, NC, A> SubscriptionInsertCall<'a, C, NC, A> where NC: hyper::net::Ne dlg.finished(false); return Result::MissingToken } - let auth_header = Authorization(token.unwrap().access_token); + let auth_header = Authorization("Bearer ".to_string() + &token.unwrap().access_token); 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_slice()) .header(UserAgent(self.hub._user_agent.clone())) - .header(auth_header) + .header(auth_header.clone()) .header(ContentType(json_mime_type.clone())) .header(ContentLength(request_size as u64)) .body(request_value_reader.into_body()); @@ -10973,7 +11003,6 @@ impl<'a, C, NC, A> SubscriptionInsertCall<'a, C, NC, A> where NC: hyper::net::Ne /// ```test_harness,no_run /// # extern crate hyper; /// # extern crate "yup-oauth2" as oauth2; -/// # extern crate serde; /// # extern crate "google-youtube3" as youtube3; /// # #[test] fn egal() { /// # use std::default::Default; @@ -11105,12 +11134,12 @@ impl<'a, C, NC, A> SubscriptionListCall<'a, C, NC, A> where NC: hyper::net::Netw dlg.finished(false); return Result::MissingToken } - let auth_header = Authorization(token.unwrap().access_token); + let auth_header = Authorization("Bearer ".to_string() + &token.unwrap().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_slice()) .header(UserAgent(self.hub._user_agent.clone())) - .header(auth_header); + .header(auth_header.clone()); dlg.pre_request(); req.send() @@ -11327,7 +11356,6 @@ impl<'a, C, NC, A> SubscriptionListCall<'a, C, NC, A> where NC: hyper::net::Netw /// ```test_harness,no_run /// # extern crate hyper; /// # extern crate "yup-oauth2" as oauth2; -/// # extern crate serde; /// # extern crate "google-youtube3" as youtube3; /// # #[test] fn egal() { /// # use std::default::Default; @@ -11408,12 +11436,12 @@ impl<'a, C, NC, A> SubscriptionDeleteCall<'a, C, NC, A> where NC: hyper::net::Ne dlg.finished(false); return Result::MissingToken } - let auth_header = Authorization(token.unwrap().access_token); + let auth_header = Authorization("Bearer ".to_string() + &token.unwrap().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_slice()) .header(UserAgent(self.hub._user_agent.clone())) - .header(auth_header); + .header(auth_header.clone()); dlg.pre_request(); req.send() @@ -11540,7 +11568,6 @@ impl<'a, C, NC, A> SubscriptionDeleteCall<'a, C, NC, A> where NC: hyper::net::Ne /// ```test_harness,no_run /// # extern crate hyper; /// # extern crate "yup-oauth2" as oauth2; -/// # extern crate serde; /// # extern crate "google-youtube3" as youtube3; /// # #[test] fn egal() { /// # use std::default::Default; @@ -11767,12 +11794,12 @@ impl<'a, C, NC, A> SearchListCall<'a, C, NC, A> where NC: hyper::net::NetworkCon dlg.finished(false); return Result::MissingToken } - let auth_header = Authorization(token.unwrap().access_token); + let auth_header = Authorization("Bearer ".to_string() + &token.unwrap().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_slice()) .header(UserAgent(self.hub._user_agent.clone())) - .header(auth_header); + .header(auth_header.clone()); dlg.pre_request(); req.send() @@ -12152,7 +12179,6 @@ impl<'a, C, NC, A> SearchListCall<'a, C, NC, A> where NC: hyper::net::NetworkCon /// ```test_harness,no_run /// # extern crate hyper; /// # extern crate "yup-oauth2" as oauth2; -/// # extern crate serde; /// # extern crate "google-youtube3" as youtube3; /// # #[test] fn egal() { /// # use std::default::Default; @@ -12239,12 +12265,12 @@ impl<'a, C, NC, A> I18nRegionListCall<'a, C, NC, A> where NC: hyper::net::Networ dlg.finished(false); return Result::MissingToken } - let auth_header = Authorization(token.unwrap().access_token); + let auth_header = Authorization("Bearer ".to_string() + &token.unwrap().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_slice()) .header(UserAgent(self.hub._user_agent.clone())) - .header(auth_header); + .header(auth_header.clone()); dlg.pre_request(); req.send() @@ -12394,7 +12420,6 @@ impl<'a, C, NC, A> I18nRegionListCall<'a, C, NC, A> where NC: hyper::net::Networ /// ```test_harness,no_run /// # extern crate hyper; /// # extern crate "yup-oauth2" as oauth2; -/// # extern crate serde; /// # extern crate "google-youtube3" as youtube3; /// use youtube3::LiveStream; /// # #[test] fn egal() { @@ -12504,13 +12529,13 @@ impl<'a, C, NC, A> LiveStreamUpdateCall<'a, C, NC, A> where NC: hyper::net::Netw dlg.finished(false); return Result::MissingToken } - let auth_header = Authorization(token.unwrap().access_token); + let auth_header = Authorization("Bearer ".to_string() + &token.unwrap().access_token); 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_slice()) .header(UserAgent(self.hub._user_agent.clone())) - .header(auth_header) + .header(auth_header.clone()) .header(ContentType(json_mime_type.clone())) .header(ContentLength(request_size as u64)) .body(request_value_reader.into_body()); @@ -12688,7 +12713,6 @@ impl<'a, C, NC, A> LiveStreamUpdateCall<'a, C, NC, A> where NC: hyper::net::Netw /// ```test_harness,no_run /// # extern crate hyper; /// # extern crate "yup-oauth2" as oauth2; -/// # extern crate serde; /// # extern crate "google-youtube3" as youtube3; /// # #[test] fn egal() { /// # use std::default::Default; @@ -12779,12 +12803,12 @@ impl<'a, C, NC, A> LiveStreamDeleteCall<'a, C, NC, A> where NC: hyper::net::Netw dlg.finished(false); return Result::MissingToken } - let auth_header = Authorization(token.unwrap().access_token); + let auth_header = Authorization("Bearer ".to_string() + &token.unwrap().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_slice()) .header(UserAgent(self.hub._user_agent.clone())) - .header(auth_header); + .header(auth_header.clone()); dlg.pre_request(); req.send() @@ -12934,7 +12958,6 @@ impl<'a, C, NC, A> LiveStreamDeleteCall<'a, C, NC, A> where NC: hyper::net::Netw /// ```test_harness,no_run /// # extern crate hyper; /// # extern crate "yup-oauth2" as oauth2; -/// # extern crate serde; /// # extern crate "google-youtube3" as youtube3; /// # #[test] fn egal() { /// # use std::default::Default; @@ -13046,12 +13069,12 @@ impl<'a, C, NC, A> LiveStreamListCall<'a, C, NC, A> where NC: hyper::net::Networ dlg.finished(false); return Result::MissingToken } - let auth_header = Authorization(token.unwrap().access_token); + let auth_header = Authorization("Bearer ".to_string() + &token.unwrap().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_slice()) .header(UserAgent(self.hub._user_agent.clone())) - .header(auth_header); + .header(auth_header.clone()); dlg.pre_request(); req.send() @@ -13249,7 +13272,6 @@ impl<'a, C, NC, A> LiveStreamListCall<'a, C, NC, A> where NC: hyper::net::Networ /// ```test_harness,no_run /// # extern crate hyper; /// # extern crate "yup-oauth2" as oauth2; -/// # extern crate serde; /// # extern crate "google-youtube3" as youtube3; /// use youtube3::LiveStream; /// # #[test] fn egal() { @@ -13359,13 +13381,13 @@ impl<'a, C, NC, A> LiveStreamInsertCall<'a, C, NC, A> where NC: hyper::net::Netw dlg.finished(false); return Result::MissingToken } - let auth_header = Authorization(token.unwrap().access_token); + let auth_header = Authorization("Bearer ".to_string() + &token.unwrap().access_token); 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_slice()) .header(UserAgent(self.hub._user_agent.clone())) - .header(auth_header) + .header(auth_header.clone()) .header(ContentType(json_mime_type.clone())) .header(ContentLength(request_size as u64)) .body(request_value_reader.into_body()); @@ -13554,7 +13576,6 @@ impl<'a, C, NC, A> LiveStreamInsertCall<'a, C, NC, A> where NC: hyper::net::Netw /// ```test_harness,no_run /// # extern crate hyper; /// # extern crate "yup-oauth2" as oauth2; -/// # extern crate serde; /// # extern crate "google-youtube3" as youtube3; /// use youtube3::Channel; /// # #[test] fn egal() { @@ -13657,13 +13678,13 @@ impl<'a, C, NC, A> ChannelUpdateCall<'a, C, NC, A> where NC: hyper::net::Network dlg.finished(false); return Result::MissingToken } - let auth_header = Authorization(token.unwrap().access_token); + let auth_header = Authorization("Bearer ".to_string() + &token.unwrap().access_token); 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_slice()) .header(UserAgent(self.hub._user_agent.clone())) - .header(auth_header) + .header(auth_header.clone()) .header(ContentType(json_mime_type.clone())) .header(ContentLength(request_size as u64)) .body(request_value_reader.into_body()); @@ -13842,7 +13863,6 @@ impl<'a, C, NC, A> ChannelUpdateCall<'a, C, NC, A> where NC: hyper::net::Network /// ```test_harness,no_run /// # extern crate hyper; /// # extern crate "yup-oauth2" as oauth2; -/// # extern crate serde; /// # extern crate "google-youtube3" as youtube3; /// # #[test] fn egal() { /// # use std::default::Default; @@ -13969,12 +13989,12 @@ impl<'a, C, NC, A> ChannelListCall<'a, C, NC, A> where NC: hyper::net::NetworkCo dlg.finished(false); return Result::MissingToken } - let auth_header = Authorization(token.unwrap().access_token); + let auth_header = Authorization("Bearer ".to_string() + &token.unwrap().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_slice()) .header(UserAgent(self.hub._user_agent.clone())) - .header(auth_header); + .header(auth_header.clone()); dlg.pre_request(); req.send() @@ -14180,7 +14200,6 @@ impl<'a, C, NC, A> ChannelListCall<'a, C, NC, A> where NC: hyper::net::NetworkCo /// ```test_harness,no_run /// # extern crate hyper; /// # extern crate "yup-oauth2" as oauth2; -/// # extern crate serde; /// # extern crate "google-youtube3" as youtube3; /// # #[test] fn egal() { /// # use std::default::Default; @@ -14261,12 +14280,12 @@ impl<'a, C, NC, A> PlaylistItemDeleteCall<'a, C, NC, A> where NC: hyper::net::Ne dlg.finished(false); return Result::MissingToken } - let auth_header = Authorization(token.unwrap().access_token); + let auth_header = Authorization("Bearer ".to_string() + &token.unwrap().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_slice()) .header(UserAgent(self.hub._user_agent.clone())) - .header(auth_header); + .header(auth_header.clone()); dlg.pre_request(); req.send() @@ -14395,7 +14414,6 @@ impl<'a, C, NC, A> PlaylistItemDeleteCall<'a, C, NC, A> where NC: hyper::net::Ne /// ```test_harness,no_run /// # extern crate hyper; /// # extern crate "yup-oauth2" as oauth2; -/// # extern crate serde; /// # extern crate "google-youtube3" as youtube3; /// # #[test] fn egal() { /// # use std::default::Default; @@ -14507,12 +14525,12 @@ impl<'a, C, NC, A> PlaylistItemListCall<'a, C, NC, A> where NC: hyper::net::Netw dlg.finished(false); return Result::MissingToken } - let auth_header = Authorization(token.unwrap().access_token); + let auth_header = Authorization("Bearer ".to_string() + &token.unwrap().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_slice()) .header(UserAgent(self.hub._user_agent.clone())) - .header(auth_header); + .header(auth_header.clone()); dlg.pre_request(); req.send() @@ -14708,7 +14726,6 @@ impl<'a, C, NC, A> PlaylistItemListCall<'a, C, NC, A> where NC: hyper::net::Netw /// ```test_harness,no_run /// # extern crate hyper; /// # extern crate "yup-oauth2" as oauth2; -/// # extern crate serde; /// # extern crate "google-youtube3" as youtube3; /// use youtube3::PlaylistItem; /// # #[test] fn egal() { @@ -14812,13 +14829,13 @@ impl<'a, C, NC, A> PlaylistItemInsertCall<'a, C, NC, A> where NC: hyper::net::Ne dlg.finished(false); return Result::MissingToken } - let auth_header = Authorization(token.unwrap().access_token); + let auth_header = Authorization("Bearer ".to_string() + &token.unwrap().access_token); 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_slice()) .header(UserAgent(self.hub._user_agent.clone())) - .header(auth_header) + .header(auth_header.clone()) .header(ContentType(json_mime_type.clone())) .header(ContentLength(request_size as u64)) .body(request_value_reader.into_body()); @@ -14994,7 +15011,6 @@ impl<'a, C, NC, A> PlaylistItemInsertCall<'a, C, NC, A> where NC: hyper::net::Ne /// ```test_harness,no_run /// # extern crate hyper; /// # extern crate "yup-oauth2" as oauth2; -/// # extern crate serde; /// # extern crate "google-youtube3" as youtube3; /// use youtube3::PlaylistItem; /// # #[test] fn egal() { @@ -15093,13 +15109,13 @@ impl<'a, C, NC, A> PlaylistItemUpdateCall<'a, C, NC, A> where NC: hyper::net::Ne dlg.finished(false); return Result::MissingToken } - let auth_header = Authorization(token.unwrap().access_token); + let auth_header = Authorization("Bearer ".to_string() + &token.unwrap().access_token); 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_slice()) .header(UserAgent(self.hub._user_agent.clone())) - .header(auth_header) + .header(auth_header.clone()) .header(ContentType(json_mime_type.clone())) .header(ContentLength(request_size as u64)) .body(request_value_reader.into_body()); @@ -15253,7 +15269,6 @@ impl<'a, C, NC, A> PlaylistItemUpdateCall<'a, C, NC, A> where NC: hyper::net::Ne /// ```test_harness,no_run /// # extern crate hyper; /// # extern crate "yup-oauth2" as oauth2; -/// # extern crate serde; /// # extern crate "google-youtube3" as youtube3; /// use youtube3::InvideoBranding; /// use std::fs; @@ -15350,6 +15365,7 @@ impl<'a, C, NC, A> WatermarkSetCall<'a, C, NC, A> where NC: hyper::net::NetworkC request_value_reader.seek(io::SeekFrom::Start(0)).unwrap(); let mut should_ask_dlg_for_url = false; + let mut upload_url_from_server = true; let mut upload_url: Option = None; loop { @@ -15361,14 +15377,18 @@ impl<'a, C, NC, A> WatermarkSetCall<'a, C, NC, A> where NC: hyper::net::NetworkC dlg.finished(false); return Result::MissingToken } - let auth_header = Authorization(token.unwrap().access_token); + let auth_header = Authorization("Bearer ".to_string() + &token.unwrap().access_token); request_value_reader.seek(io::SeekFrom::Start(0)).unwrap(); let mut req_result = { if should_ask_dlg_for_url && (upload_url = dlg.upload_url()) == () && upload_url.is_some() { should_ask_dlg_for_url = false; + upload_url_from_server = false; let mut response = hyper::client::Response::new(Box::new(cmn::DummyNetworkStream)); match response { - Ok(ref mut res) => res.headers.set(Location(upload_url.as_ref().unwrap().clone())), + Ok(ref mut res) => { + res.status = hyper::status::StatusCode::Ok; + res.headers.set(Location(upload_url.as_ref().unwrap().clone())) + } _ => unreachable!(), } response @@ -15379,6 +15399,9 @@ impl<'a, C, NC, A> WatermarkSetCall<'a, C, NC, A> where NC: hyper::net::NetworkC mp_reader.reserve_exact(2); let size = reader.seek(io::SeekFrom::End(0)).unwrap(); reader.seek(io::SeekFrom::Start(0)).unwrap(); + if size > 0 { + return Result::UploadSizeLimitExceeded(size, 0) + } mp_reader.add_part(&mut request_value_reader, request_size, json_mime_type.clone()) .add_part(&mut reader, size, reader_mime_type.clone()); let mime_type = mp_reader.mime_type(); @@ -15389,9 +15412,10 @@ impl<'a, C, NC, A> WatermarkSetCall<'a, C, NC, A> where NC: hyper::net::NetworkC let mut client = &mut *self.hub.client.borrow_mut(); let mut req = client.borrow_mut().request(hyper::method::Method::Post, url.as_slice()) .header(UserAgent(self.hub._user_agent.clone())) - .header(auth_header) + .header(auth_header.clone()) .header(content_type) .body(body_reader.into_body()); + upload_url_from_server = true; if protocol == "resumable" { req = req.header(cmn::XUploadContentType(reader_mime_type.clone())); } @@ -15426,16 +15450,29 @@ impl<'a, C, NC, A> WatermarkSetCall<'a, C, NC, A> where NC: hyper::net::NetworkC if protocol == "resumable" { let size = reader.seek(io::SeekFrom::End(0)).unwrap(); reader.seek(io::SeekFrom::Start(0)).unwrap(); + if size > 0 { + return Result::UploadSizeLimitExceeded(size, 0) + } let mut client = &mut *self.hub.client.borrow_mut(); - match (cmn::ResumableUploadHelper { - client: &mut client.borrow_mut(), - delegate: dlg, - auth: &mut *self.hub.auth.borrow_mut(), - url: &res.headers.get::().expect("Location header is part of protocol").0, - reader: &mut reader, - media_type: reader_mime_type.clone(), - content_size: size - }.upload()) { + let upload_result = { + let url = &res.headers.get::().expect("Location header is part of protocol").0; + if upload_url_from_server { + dlg.store_upload_url(url); + } + + cmn::ResumableUploadHelper { + client: &mut client.borrow_mut(), + delegate: dlg, + auth: &mut *self.hub.auth.borrow_mut(), + user_agent: &self.hub._user_agent, + auth_token: auth_header.0.clone(), + url: url, + reader: &mut reader, + media_type: reader_mime_type.clone(), + content_size: size + }.upload() + }; + match upload_result { Err(err) => { dlg.finished(false); return Result::HttpError(err) @@ -15568,7 +15605,6 @@ impl<'a, C, NC, A> WatermarkSetCall<'a, C, NC, A> where NC: hyper::net::NetworkC /// ```test_harness,no_run /// # extern crate hyper; /// # extern crate "yup-oauth2" as oauth2; -/// # extern crate serde; /// # extern crate "google-youtube3" as youtube3; /// # #[test] fn egal() { /// # use std::default::Default; @@ -15654,12 +15690,12 @@ impl<'a, C, NC, A> WatermarkUnsetCall<'a, C, NC, A> where NC: hyper::net::Networ dlg.finished(false); return Result::MissingToken } - let auth_header = Authorization(token.unwrap().access_token); + let auth_header = Authorization("Bearer ".to_string() + &token.unwrap().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_slice()) .header(UserAgent(self.hub._user_agent.clone())) - .header(auth_header); + .header(auth_header.clone()); dlg.pre_request(); req.send() @@ -15794,7 +15830,6 @@ impl<'a, C, NC, A> WatermarkUnsetCall<'a, C, NC, A> where NC: hyper::net::Networ /// ```test_harness,no_run /// # extern crate hyper; /// # extern crate "yup-oauth2" as oauth2; -/// # extern crate serde; /// # extern crate "google-youtube3" as youtube3; /// # #[test] fn egal() { /// # use std::default::Default; @@ -15903,12 +15938,12 @@ impl<'a, C, NC, A> LiveBroadcastControlCall<'a, C, NC, A> where NC: hyper::net:: dlg.finished(false); return Result::MissingToken } - let auth_header = Authorization(token.unwrap().access_token); + let auth_header = Authorization("Bearer ".to_string() + &token.unwrap().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_slice()) .header(UserAgent(self.hub._user_agent.clone())) - .header(auth_header); + .header(auth_header.clone()); dlg.pre_request(); req.send() @@ -16112,7 +16147,6 @@ impl<'a, C, NC, A> LiveBroadcastControlCall<'a, C, NC, A> where NC: hyper::net:: /// ```test_harness,no_run /// # extern crate hyper; /// # extern crate "yup-oauth2" as oauth2; -/// # extern crate serde; /// # extern crate "google-youtube3" as youtube3; /// use youtube3::LiveBroadcast; /// # #[test] fn egal() { @@ -16222,13 +16256,13 @@ impl<'a, C, NC, A> LiveBroadcastUpdateCall<'a, C, NC, A> where NC: hyper::net::N dlg.finished(false); return Result::MissingToken } - let auth_header = Authorization(token.unwrap().access_token); + let auth_header = Authorization("Bearer ".to_string() + &token.unwrap().access_token); 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_slice()) .header(UserAgent(self.hub._user_agent.clone())) - .header(auth_header) + .header(auth_header.clone()) .header(ContentType(json_mime_type.clone())) .header(ContentLength(request_size as u64)) .body(request_value_reader.into_body()); @@ -16420,7 +16454,6 @@ impl<'a, C, NC, A> LiveBroadcastUpdateCall<'a, C, NC, A> where NC: hyper::net::N /// ```test_harness,no_run /// # extern crate hyper; /// # extern crate "yup-oauth2" as oauth2; -/// # extern crate serde; /// # extern crate "google-youtube3" as youtube3; /// use youtube3::LiveBroadcast; /// # #[test] fn egal() { @@ -16530,13 +16563,13 @@ impl<'a, C, NC, A> LiveBroadcastInsertCall<'a, C, NC, A> where NC: hyper::net::N dlg.finished(false); return Result::MissingToken } - let auth_header = Authorization(token.unwrap().access_token); + let auth_header = Authorization("Bearer ".to_string() + &token.unwrap().access_token); 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_slice()) .header(UserAgent(self.hub._user_agent.clone())) - .header(auth_header) + .header(auth_header.clone()) .header(ContentType(json_mime_type.clone())) .header(ContentLength(request_size as u64)) .body(request_value_reader.into_body()); @@ -16726,7 +16759,6 @@ impl<'a, C, NC, A> LiveBroadcastInsertCall<'a, C, NC, A> where NC: hyper::net::N /// ```test_harness,no_run /// # extern crate hyper; /// # extern crate "yup-oauth2" as oauth2; -/// # extern crate serde; /// # extern crate "google-youtube3" as youtube3; /// # #[test] fn egal() { /// # use std::default::Default; @@ -16825,12 +16857,12 @@ impl<'a, C, NC, A> LiveBroadcastBindCall<'a, C, NC, A> where NC: hyper::net::Net dlg.finished(false); return Result::MissingToken } - let auth_header = Authorization(token.unwrap().access_token); + let auth_header = Authorization("Bearer ".to_string() + &token.unwrap().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_slice()) .header(UserAgent(self.hub._user_agent.clone())) - .header(auth_header); + .header(auth_header.clone()); dlg.pre_request(); req.send() @@ -17015,7 +17047,6 @@ impl<'a, C, NC, A> LiveBroadcastBindCall<'a, C, NC, A> where NC: hyper::net::Net /// ```test_harness,no_run /// # extern crate hyper; /// # extern crate "yup-oauth2" as oauth2; -/// # extern crate serde; /// # extern crate "google-youtube3" as youtube3; /// # #[test] fn egal() { /// # use std::default::Default; @@ -17132,12 +17163,12 @@ impl<'a, C, NC, A> LiveBroadcastListCall<'a, C, NC, A> where NC: hyper::net::Net dlg.finished(false); return Result::MissingToken } - let auth_header = Authorization(token.unwrap().access_token); + let auth_header = Authorization("Bearer ".to_string() + &token.unwrap().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_slice()) .header(UserAgent(self.hub._user_agent.clone())) - .header(auth_header); + .header(auth_header.clone()); dlg.pre_request(); req.send() @@ -17329,7 +17360,6 @@ impl<'a, C, NC, A> LiveBroadcastListCall<'a, C, NC, A> where NC: hyper::net::Net /// ```test_harness,no_run /// # extern crate hyper; /// # extern crate "yup-oauth2" as oauth2; -/// # extern crate serde; /// # extern crate "google-youtube3" as youtube3; /// # #[test] fn egal() { /// # use std::default::Default; @@ -17420,12 +17450,12 @@ impl<'a, C, NC, A> LiveBroadcastDeleteCall<'a, C, NC, A> where NC: hyper::net::N dlg.finished(false); return Result::MissingToken } - let auth_header = Authorization(token.unwrap().access_token); + let auth_header = Authorization("Bearer ".to_string() + &token.unwrap().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_slice()) .header(UserAgent(self.hub._user_agent.clone())) - .header(auth_header); + .header(auth_header.clone()); dlg.pre_request(); req.send() @@ -17574,7 +17604,6 @@ impl<'a, C, NC, A> LiveBroadcastDeleteCall<'a, C, NC, A> where NC: hyper::net::N /// ```test_harness,no_run /// # extern crate hyper; /// # extern crate "yup-oauth2" as oauth2; -/// # extern crate serde; /// # extern crate "google-youtube3" as youtube3; /// # #[test] fn egal() { /// # use std::default::Default; @@ -17670,12 +17699,12 @@ impl<'a, C, NC, A> LiveBroadcastTransitionCall<'a, C, NC, A> where NC: hyper::ne dlg.finished(false); return Result::MissingToken } - let auth_header = Authorization(token.unwrap().access_token); + let auth_header = Authorization("Bearer ".to_string() + &token.unwrap().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_slice()) .header(UserAgent(self.hub._user_agent.clone())) - .header(auth_header); + .header(auth_header.clone()); dlg.pre_request(); req.send() @@ -17861,7 +17890,6 @@ impl<'a, C, NC, A> LiveBroadcastTransitionCall<'a, C, NC, A> where NC: hyper::ne /// ```test_harness,no_run /// # extern crate hyper; /// # extern crate "yup-oauth2" as oauth2; -/// # extern crate serde; /// # extern crate "google-youtube3" as youtube3; /// # #[test] fn egal() { /// # use std::default::Default; @@ -17958,12 +17986,12 @@ impl<'a, C, NC, A> VideoCategoryListCall<'a, C, NC, A> where NC: hyper::net::Net dlg.finished(false); return Result::MissingToken } - let auth_header = Authorization(token.unwrap().access_token); + let auth_header = Authorization("Bearer ".to_string() + &token.unwrap().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_slice()) .header(UserAgent(self.hub._user_agent.clone())) - .header(auth_header); + .header(auth_header.clone()); dlg.pre_request(); req.send() @@ -18129,7 +18157,6 @@ impl<'a, C, NC, A> VideoCategoryListCall<'a, C, NC, A> where NC: hyper::net::Net /// ```test_harness,no_run /// # extern crate hyper; /// # extern crate "yup-oauth2" as oauth2; -/// # extern crate serde; /// # extern crate "google-youtube3" as youtube3; /// # #[test] fn egal() { /// # use std::default::Default; @@ -18251,12 +18278,12 @@ impl<'a, C, NC, A> ActivityListCall<'a, C, NC, A> where NC: hyper::net::NetworkC dlg.finished(false); return Result::MissingToken } - let auth_header = Authorization(token.unwrap().access_token); + let auth_header = Authorization("Bearer ".to_string() + &token.unwrap().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_slice()) .header(UserAgent(self.hub._user_agent.clone())) - .header(auth_header); + .header(auth_header.clone()); dlg.pre_request(); req.send() @@ -18465,7 +18492,6 @@ impl<'a, C, NC, A> ActivityListCall<'a, C, NC, A> where NC: hyper::net::NetworkC /// ```test_harness,no_run /// # extern crate hyper; /// # extern crate "yup-oauth2" as oauth2; -/// # extern crate serde; /// # extern crate "google-youtube3" as youtube3; /// use youtube3::Activity; /// # #[test] fn egal() { @@ -18563,13 +18589,13 @@ impl<'a, C, NC, A> ActivityInsertCall<'a, C, NC, A> where NC: hyper::net::Networ dlg.finished(false); return Result::MissingToken } - let auth_header = Authorization(token.unwrap().access_token); + let auth_header = Authorization("Bearer ".to_string() + &token.unwrap().access_token); 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_slice()) .header(UserAgent(self.hub._user_agent.clone())) - .header(auth_header) + .header(auth_header.clone()) .header(ContentType(json_mime_type.clone())) .header(ContentLength(request_size as u64)) .body(request_value_reader.into_body()); diff --git a/src/mako/Cargo.toml.mako b/src/mako/Cargo.toml.mako index c32f9cf4095..7c1ff16698d 100644 --- a/src/mako/Cargo.toml.mako +++ b/src/mako/Cargo.toml.mako @@ -6,12 +6,12 @@ [package] name = "${util.crate_name()}" -version = "${cargo.build_version}" +version = "${util.crate_version()}" authors = [${",\n ".join('"%s"' % a for a in cargo.authors)}] description = "A complete library to interact with ${util.canonical_name()} (protocol ${version})" repository = "${util.repository_url()}" homepage = "${documentationLink}" -documentation = "${cargo.doc_base_url}" +documentation = "${cargo.doc_base_url}/${util.crate_name()}" license = "${copyright.license_abbrev}" keywords = ["${name}", ${", ".join(estr(cargo.keywords))}] diff --git a/src/mako/lib/lib.mako b/src/mako/lib/lib.mako index e9c192f7663..789df89e53f 100644 --- a/src/mako/lib/lib.mako +++ b/src/mako/lib/lib.mako @@ -57,7 +57,7 @@ header_methods = (('Upload', upload_methods), ('Download', download_methods), ('Subscription', subscription_methods)) %>\ % if rust_doc: -This documentation was generated from *${util.canonical_name()}* crate version *${cargo.build_version}*. +This documentation was generated from *${util.canonical_name()}* crate version *${util.crate_version()}*. The original source code can be found [on github](${cargo.repo_base_url}/tree/master/${directories.output}/${util.library_name()}). % endif # Features @@ -170,7 +170,7 @@ To use this library, you would put the following lines into your `Cargo.toml` fi ```toml [dependencies] -${util.crate_name()} = "${cargo.build_version}" +${util.crate_name()} = "*" ``` ${'##'} A complete example diff --git a/src/mako/lib/mbuild.mako b/src/mako/lib/mbuild.mako index 1aabbc81260..6c59c3f0bed 100644 --- a/src/mako/lib/mbuild.mako +++ b/src/mako/lib/mbuild.mako @@ -10,7 +10,7 @@ CALL_BUILDER_MARKERT_TRAIT, pass_through, markdown_rust_block, parts_from_params, DELEGATE_PROPERTY_NAME, struct_type_bounds_s, supports_scopes, scope_url_to_variant, re_find_replacements, ADD_PARAM_FN, ADD_PARAM_MEDIA_EXAMPLE, upload_action_fn, METHODS_RESOURCE, - method_name_to_variant, unique_type_name) + method_name_to_variant, unique_type_name, size_to_bytes) def get_parts(part_prop): if not part_prop: @@ -442,7 +442,7 @@ match result { MULTI_SLASH = 'multi-slash-prefix' URL_ENCODE = 'url-encode' - max_size = simple_media_param.max_size + max_size = size_to_bytes(m.get('maxSize', '0kb')) READER_SEEK = "let size = reader.seek(io::SeekFrom::End(0)).unwrap();\nreader.seek(io::SeekFrom::Start(0)).unwrap();\n" READER_SEEK += "if size > %i {\n\treturn Result::UploadSizeLimitExceeded(size, %i)\n}" % (max_size, max_size) diff --git a/src/mako/lib/util.mako b/src/mako/lib/util.mako index e4273b1ad00..d6b6ae5a7f2 100644 --- a/src/mako/lib/util.mako +++ b/src/mako/lib/util.mako @@ -27,6 +27,10 @@ ${util.library_name(name, version)}\ ${util.library_to_crate_name(util.library_name(name, version))}\ +<%def name="crate_version()" buffered="True">\ +${cargo.build_version}+${revision}\ + + ## All crates and standard `use` declaration, required for all examples ## Must be outside of a test function <%def name="test_prelude()">\