From 79879daf1b2a52593d2bc9b51ba244bfaddcf1f0 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 17 Mar 2015 16:24:04 +0100 Subject: [PATCH] fix(methods): decent solution for free methods Now I just add a 'virtual' resource, which is called 'methods'. The good thing about this is that it works well standalone, or in conjunction with actual resources. Also the system works with it just with minimal changes Fixes #19 --- gen/youtube3/README.md | 7 +- gen/youtube3/src/lib.rs | 402 ++++++++++++++++++++++++--------------- src/mako/lib.rs.mako | 6 +- src/mako/lib/lib.mako | 11 +- src/mako/lib/rbuild.mako | 6 +- src/mako/lib/util.py | 29 ++- 6 files changed, 282 insertions(+), 179 deletions(-) diff --git a/gen/youtube3/README.md b/gen/youtube3/README.md index 0bdc11d12e..308e340716 100644 --- a/gen/youtube3/README.md +++ b/gen/youtube3/README.md @@ -27,7 +27,7 @@ Handle the following *Resources* with ease from the central [hub](http://byron.g * [videos](http://byron.github.io/google-apis-rs/youtube3/struct.Video.html) ([*delete*](http://byron.github.io/google-apis-rs/youtube3/struct.VideoDeleteMethodBuilder.html), [*get rating*](http://byron.github.io/google-apis-rs/youtube3/struct.VideoGetRatingMethodBuilder.html), [*insert*](http://byron.github.io/google-apis-rs/youtube3/struct.VideoInsertMethodBuilder.html), [*list*](http://byron.github.io/google-apis-rs/youtube3/struct.VideoListMethodBuilder.html), [*rate*](http://byron.github.io/google-apis-rs/youtube3/struct.VideoRateMethodBuilder.html) and [*update*](http://byron.github.io/google-apis-rs/youtube3/struct.VideoUpdateMethodBuilder.html)) * watermarks ([*set*](http://byron.github.io/google-apis-rs/youtube3/struct.WatermarkSetMethodBuilder.html) and [*unset*](http://byron.github.io/google-apis-rs/youtube3/struct.WatermarkUnsetMethodBuilder.html)) -Everything else about the *YouTube* API can be found at the +Everything else about the *YouTube* *v3* API can be found at the [official documentation site](https://developers.google.com/youtube/v3). # Structure of this Library @@ -118,8 +118,11 @@ 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::Success(value) => println!("Result Value: {:?}", value), + Result::Success(_) => println!("Success (value doesn't print)"), } ``` diff --git a/gen/youtube3/src/lib.rs b/gen/youtube3/src/lib.rs index 54dafcb20a..21c67ac67f 100644 --- a/gen/youtube3/src/lib.rs +++ b/gen/youtube3/src/lib.rs @@ -2,6 +2,8 @@ // 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*. +//! The original source code can be found [on github](https://github.com/Byron/google-apis-rs/tree/master/gen/youtube3). //! # Features //! //! Handle the following *Resources* with ease from the central [hub](struct.YouTube.html) ... @@ -24,7 +26,7 @@ //! * [videos](struct.Video.html) ([*delete*](struct.VideoDeleteMethodBuilder.html), [*get rating*](struct.VideoGetRatingMethodBuilder.html), [*insert*](struct.VideoInsertMethodBuilder.html), [*list*](struct.VideoListMethodBuilder.html), [*rate*](struct.VideoRateMethodBuilder.html) and [*update*](struct.VideoUpdateMethodBuilder.html)) //! * watermarks ([*set*](struct.WatermarkSetMethodBuilder.html) and [*unset*](struct.WatermarkUnsetMethodBuilder.html)) //! -//! Everything else about the *YouTube* API can be found at the +//! Everything else about the *YouTube* *v3* API can be found at the //! [official documentation site](https://developers.google.com/youtube/v3). //! //! Not what you are looking for ? Find all other google APIs in their Rust [documentation index](../index.html). @@ -118,8 +120,11 @@ //! //! 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::Success(value) => println!("Result Value: {:?}", value), +//! Result::Success(_) => println!("Success (value doesn't print)"), //! } //! # } //! ``` @@ -306,8 +311,11 @@ 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::Success(value) => println!("Result Value: {:?}", value), +/// Result::Success(_) => println!("Success (value doesn't print)"), /// } /// # } /// ``` @@ -6678,13 +6686,15 @@ impl<'a, C, NC, A> I18nLanguageListMethodBuilder<'a, C, NC, A> where NC: hyper:: } let mut url = "https://www.googleapis.com/youtube/v3/i18nLanguages".to_string(); - if self._scopes.len() == 0 { self._scopes.insert(Scope::Readonly.as_slice().to_string(), ()); } - url.push('?'); - url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + + if params.len() > 0 { + url.push('?'); + url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + } loop { let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys()); @@ -6889,20 +6899,23 @@ impl<'a, C, NC, A> ChannelBannerInsertMethodBuilder<'a, C, NC, A> where NC: hype params.push((&name, value.clone())); } - let mut url = if stream.is_some() { - "https://www.googleapis.com/upload/youtube/v3/channelBanners/insert".to_string() + let (mut url, protocol) = if stream.is_some() { + ("https://www.googleapis.com/upload/youtube/v3/channelBanners/insert".to_string(), "simple") } else if resumeable_stream.is_some() { - "https://www.googleapis.com/resumable/upload/youtube/v3/channelBanners/insert".to_string() + ("https://www.googleapis.com/resumable/upload/youtube/v3/channelBanners/insert".to_string(), "resumable") } else { unreachable!() }; - + params.push(("uploadType", protocol.to_string())); if self._scopes.len() == 0 { self._scopes.insert(Scope::Full.as_slice().to_string(), ()); } - url.push('?'); - url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + + if params.len() > 0 { + url.push('?'); + url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + } loop { let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys()); @@ -7149,13 +7162,15 @@ impl<'a, C, NC, A> ChannelSectionListMethodBuilder<'a, C, NC, A> where NC: hyper } let mut url = "https://www.googleapis.com/youtube/v3/channelSections".to_string(); - if self._scopes.len() == 0 { self._scopes.insert(Scope::Readonly.as_slice().to_string(), ()); } - url.push('?'); - url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + + if params.len() > 0 { + url.push('?'); + url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + } loop { let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys()); @@ -7410,13 +7425,15 @@ impl<'a, C, NC, A> ChannelSectionInsertMethodBuilder<'a, C, NC, A> where NC: hyp } let mut url = "https://www.googleapis.com/youtube/v3/channelSections".to_string(); - if self._scopes.len() == 0 { self._scopes.insert(Scope::Full.as_slice().to_string(), ()); } - url.push('?'); - url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + + if params.len() > 0 { + url.push('?'); + url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + } loop { let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys()); @@ -7647,13 +7664,15 @@ impl<'a, C, NC, A> ChannelSectionDeleteMethodBuilder<'a, C, NC, A> where NC: hyp } let mut url = "https://www.googleapis.com/youtube/v3/channelSections".to_string(); - if self._scopes.len() == 0 { self._scopes.insert(Scope::Full.as_slice().to_string(), ()); } - url.push('?'); - url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + + if params.len() > 0 { + url.push('?'); + url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + } loop { let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys()); @@ -7869,13 +7888,15 @@ impl<'a, C, NC, A> ChannelSectionUpdateMethodBuilder<'a, C, NC, A> where NC: hyp } let mut url = "https://www.googleapis.com/youtube/v3/channelSections".to_string(); - if self._scopes.len() == 0 { self._scopes.insert(Scope::Full.as_slice().to_string(), ()); } - url.push('?'); - url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + + if params.len() > 0 { + url.push('?'); + url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + } loop { let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys()); @@ -8118,13 +8139,15 @@ impl<'a, C, NC, A> GuideCategoryListMethodBuilder<'a, C, NC, A> where NC: hyper: } let mut url = "https://www.googleapis.com/youtube/v3/guideCategories".to_string(); - if self._scopes.len() == 0 { self._scopes.insert(Scope::Readonly.as_slice().to_string(), ()); } - url.push('?'); - url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + + if params.len() > 0 { + url.push('?'); + url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + } loop { let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys()); @@ -8368,13 +8391,15 @@ impl<'a, C, NC, A> PlaylistInsertMethodBuilder<'a, C, NC, A> where NC: hyper::ne } let mut url = "https://www.googleapis.com/youtube/v3/playlists".to_string(); - if self._scopes.len() == 0 { self._scopes.insert(Scope::Full.as_slice().to_string(), ()); } - url.push('?'); - url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + + if params.len() > 0 { + url.push('?'); + url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + } loop { let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys()); @@ -8651,13 +8676,15 @@ impl<'a, C, NC, A> PlaylistListMethodBuilder<'a, C, NC, A> where NC: hyper::net: } let mut url = "https://www.googleapis.com/youtube/v3/playlists".to_string(); - if self._scopes.len() == 0 { self._scopes.insert(Scope::Readonly.as_slice().to_string(), ()); } - url.push('?'); - url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + + if params.len() > 0 { + url.push('?'); + url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + } loop { let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys()); @@ -8911,13 +8938,15 @@ impl<'a, C, NC, A> PlaylistDeleteMethodBuilder<'a, C, NC, A> where NC: hyper::ne } let mut url = "https://www.googleapis.com/youtube/v3/playlists".to_string(); - if self._scopes.len() == 0 { self._scopes.insert(Scope::Full.as_slice().to_string(), ()); } - url.push('?'); - url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + + if params.len() > 0 { + url.push('?'); + url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + } loop { let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys()); @@ -9133,13 +9162,15 @@ impl<'a, C, NC, A> PlaylistUpdateMethodBuilder<'a, C, NC, A> where NC: hyper::ne } let mut url = "https://www.googleapis.com/youtube/v3/playlists".to_string(); - if self._scopes.len() == 0 { self._scopes.insert(Scope::Full.as_slice().to_string(), ()); } - url.push('?'); - url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + + if params.len() > 0 { + url.push('?'); + url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + } loop { let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys()); @@ -9360,20 +9391,23 @@ impl<'a, C, NC, A> ThumbnailSetMethodBuilder<'a, C, NC, A> where NC: hyper::net: params.push((&name, value.clone())); } - let mut url = if stream.is_some() { - "https://www.googleapis.com/upload/youtube/v3/thumbnails/set".to_string() + let (mut url, protocol) = if stream.is_some() { + ("https://www.googleapis.com/upload/youtube/v3/thumbnails/set".to_string(), "simple") } else if resumeable_stream.is_some() { - "https://www.googleapis.com/resumable/upload/youtube/v3/thumbnails/set".to_string() + ("https://www.googleapis.com/resumable/upload/youtube/v3/thumbnails/set".to_string(), "resumable") } else { unreachable!() }; - + params.push(("uploadType", protocol.to_string())); if self._scopes.len() == 0 { self._scopes.insert(Scope::Full.as_slice().to_string(), ()); } - url.push('?'); - url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + + if params.len() > 0 { + url.push('?'); + url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + } loop { let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys()); @@ -9657,13 +9691,15 @@ impl<'a, C, NC, A> VideoListMethodBuilder<'a, C, NC, A> where NC: hyper::net::Ne } let mut url = "https://www.googleapis.com/youtube/v3/videos".to_string(); - if self._scopes.len() == 0 { self._scopes.insert(Scope::Readonly.as_slice().to_string(), ()); } - url.push('?'); - url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + + if params.len() > 0 { + url.push('?'); + url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + } loop { let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys()); @@ -9952,13 +9988,15 @@ impl<'a, C, NC, A> VideoRateMethodBuilder<'a, C, NC, A> where NC: hyper::net::Ne } let mut url = "https://www.googleapis.com/youtube/v3/videos/rate".to_string(); - if self._scopes.len() == 0 { self._scopes.insert(Scope::Full.as_slice().to_string(), ()); } - url.push('?'); - url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + + if params.len() > 0 { + url.push('?'); + url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + } loop { let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys()); @@ -10159,13 +10197,15 @@ impl<'a, C, NC, A> VideoGetRatingMethodBuilder<'a, C, NC, A> where NC: hyper::ne } let mut url = "https://www.googleapis.com/youtube/v3/videos/getRating".to_string(); - if self._scopes.len() == 0 { self._scopes.insert(Scope::Readonly.as_slice().to_string(), ()); } - url.push('?'); - url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + + if params.len() > 0 { + url.push('?'); + url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + } loop { let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys()); @@ -10358,13 +10398,15 @@ impl<'a, C, NC, A> VideoDeleteMethodBuilder<'a, C, NC, A> where NC: hyper::net:: } let mut url = "https://www.googleapis.com/youtube/v3/videos".to_string(); - if self._scopes.len() == 0 { self._scopes.insert(Scope::Full.as_slice().to_string(), ()); } - url.push('?'); - url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + + if params.len() > 0 { + url.push('?'); + url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + } loop { let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys()); @@ -10600,13 +10642,15 @@ impl<'a, C, NC, A> VideoUpdateMethodBuilder<'a, C, NC, A> where NC: hyper::net:: } let mut url = "https://www.googleapis.com/youtube/v3/videos".to_string(); - if self._scopes.len() == 0 { self._scopes.insert(Scope::Full.as_slice().to_string(), ()); } - url.push('?'); - url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + + if params.len() > 0 { + url.push('?'); + url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + } loop { let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys()); @@ -10915,20 +10959,23 @@ impl<'a, C, NC, A> VideoInsertMethodBuilder<'a, C, NC, A> where NC: hyper::net:: params.push((&name, value.clone())); } - let mut url = if stream.is_some() { - "https://www.googleapis.com/upload/youtube/v3/videos".to_string() + let (mut url, protocol) = if stream.is_some() { + ("https://www.googleapis.com/upload/youtube/v3/videos".to_string(), "simple") } else if resumeable_stream.is_some() { - "https://www.googleapis.com/resumable/upload/youtube/v3/videos".to_string() + ("https://www.googleapis.com/resumable/upload/youtube/v3/videos".to_string(), "resumable") } else { unreachable!() }; - + params.push(("uploadType", protocol.to_string())); if self._scopes.len() == 0 { self._scopes.insert(Scope::Full.as_slice().to_string(), ()); } - url.push('?'); - url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + + if params.len() > 0 { + url.push('?'); + url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + } loop { let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys()); @@ -11246,13 +11293,15 @@ impl<'a, C, NC, A> SubscriptionInsertMethodBuilder<'a, C, NC, A> where NC: hyper } let mut url = "https://www.googleapis.com/youtube/v3/subscriptions".to_string(); - if self._scopes.len() == 0 { self._scopes.insert(Scope::Full.as_slice().to_string(), ()); } - url.push('?'); - url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + + if params.len() > 0 { + url.push('?'); + url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + } loop { let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys()); @@ -11521,13 +11570,15 @@ impl<'a, C, NC, A> SubscriptionListMethodBuilder<'a, C, NC, A> where NC: hyper:: } let mut url = "https://www.googleapis.com/youtube/v3/subscriptions".to_string(); - if self._scopes.len() == 0 { self._scopes.insert(Scope::Readonly.as_slice().to_string(), ()); } - url.push('?'); - url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + + if params.len() > 0 { + url.push('?'); + url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + } loop { let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys()); @@ -11799,13 +11850,15 @@ impl<'a, C, NC, A> SubscriptionDeleteMethodBuilder<'a, C, NC, A> where NC: hyper } let mut url = "https://www.googleapis.com/youtube/v3/subscriptions".to_string(); - if self._scopes.len() == 0 { self._scopes.insert(Scope::Full.as_slice().to_string(), ()); } - url.push('?'); - url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + + if params.len() > 0 { + url.push('?'); + url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + } loop { let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys()); @@ -12140,13 +12193,15 @@ impl<'a, C, NC, A> SearchListMethodBuilder<'a, C, NC, A> where NC: hyper::net::N } let mut url = "https://www.googleapis.com/youtube/v3/search".to_string(); - if self._scopes.len() == 0 { self._scopes.insert(Scope::Readonly.as_slice().to_string(), ()); } - url.push('?'); - url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + + if params.len() > 0 { + url.push('?'); + url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + } loop { let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys()); @@ -12586,13 +12641,15 @@ impl<'a, C, NC, A> I18nRegionListMethodBuilder<'a, C, NC, A> where NC: hyper::ne } let mut url = "https://www.googleapis.com/youtube/v3/i18nRegions".to_string(); - if self._scopes.len() == 0 { self._scopes.insert(Scope::Readonly.as_slice().to_string(), ()); } - url.push('?'); - url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + + if params.len() > 0 { + url.push('?'); + url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + } loop { let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys()); @@ -12821,13 +12878,15 @@ impl<'a, C, NC, A> LiveStreamUpdateMethodBuilder<'a, C, NC, A> where NC: hyper:: } let mut url = "https://www.googleapis.com/youtube/v3/liveStreams".to_string(); - if self._scopes.len() == 0 { self._scopes.insert(Scope::Full.as_slice().to_string(), ()); } - url.push('?'); - url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + + if params.len() > 0 { + url.push('?'); + url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + } loop { let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys()); @@ -13069,13 +13128,15 @@ impl<'a, C, NC, A> LiveStreamDeleteMethodBuilder<'a, C, NC, A> where NC: hyper:: } let mut url = "https://www.googleapis.com/youtube/v3/liveStreams".to_string(); - if self._scopes.len() == 0 { self._scopes.insert(Scope::Full.as_slice().to_string(), ()); } - url.push('?'); - url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + + if params.len() > 0 { + url.push('?'); + url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + } loop { let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys()); @@ -13318,13 +13379,15 @@ impl<'a, C, NC, A> LiveStreamListMethodBuilder<'a, C, NC, A> where NC: hyper::ne } let mut url = "https://www.googleapis.com/youtube/v3/liveStreams".to_string(); - if self._scopes.len() == 0 { self._scopes.insert(Scope::Readonly.as_slice().to_string(), ()); } - url.push('?'); - url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + + if params.len() > 0 { + url.push('?'); + url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + } loop { let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys()); @@ -13601,13 +13664,15 @@ impl<'a, C, NC, A> LiveStreamInsertMethodBuilder<'a, C, NC, A> where NC: hyper:: } let mut url = "https://www.googleapis.com/youtube/v3/liveStreams".to_string(); - if self._scopes.len() == 0 { self._scopes.insert(Scope::Full.as_slice().to_string(), ()); } - url.push('?'); - url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + + if params.len() > 0 { + url.push('?'); + url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + } loop { let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys()); @@ -13867,13 +13932,15 @@ impl<'a, C, NC, A> ChannelUpdateMethodBuilder<'a, C, NC, A> where NC: hyper::net } let mut url = "https://www.googleapis.com/youtube/v3/channels".to_string(); - if self._scopes.len() == 0 { self._scopes.insert(Scope::Full.as_slice().to_string(), ()); } - url.push('?'); - url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + + if params.len() > 0 { + url.push('?'); + url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + } loop { let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys()); @@ -14151,13 +14218,15 @@ impl<'a, C, NC, A> ChannelListMethodBuilder<'a, C, NC, A> where NC: hyper::net:: } let mut url = "https://www.googleapis.com/youtube/v3/channels".to_string(); - if self._scopes.len() == 0 { self._scopes.insert(Scope::Readonly.as_slice().to_string(), ()); } - url.push('?'); - url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + + if params.len() > 0 { + url.push('?'); + url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + } loop { let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys()); @@ -14418,13 +14487,15 @@ impl<'a, C, NC, A> PlaylistItemDeleteMethodBuilder<'a, C, NC, A> where NC: hyper } let mut url = "https://www.googleapis.com/youtube/v3/playlistItems".to_string(); - if self._scopes.len() == 0 { self._scopes.insert(Scope::Full.as_slice().to_string(), ()); } - url.push('?'); - url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + + if params.len() > 0 { + url.push('?'); + url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + } loop { let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys()); @@ -14646,13 +14717,15 @@ impl<'a, C, NC, A> PlaylistItemListMethodBuilder<'a, C, NC, A> where NC: hyper:: } let mut url = "https://www.googleapis.com/youtube/v3/playlistItems".to_string(); - if self._scopes.len() == 0 { self._scopes.insert(Scope::Readonly.as_slice().to_string(), ()); } - url.push('?'); - url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + + if params.len() > 0 { + url.push('?'); + url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + } loop { let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys()); @@ -14921,13 +14994,15 @@ impl<'a, C, NC, A> PlaylistItemInsertMethodBuilder<'a, C, NC, A> where NC: hyper } let mut url = "https://www.googleapis.com/youtube/v3/playlistItems".to_string(); - if self._scopes.len() == 0 { self._scopes.insert(Scope::Full.as_slice().to_string(), ()); } - url.push('?'); - url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + + if params.len() > 0 { + url.push('?'); + url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + } loop { let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys()); @@ -15170,13 +15245,15 @@ impl<'a, C, NC, A> PlaylistItemUpdateMethodBuilder<'a, C, NC, A> where NC: hyper } let mut url = "https://www.googleapis.com/youtube/v3/playlistItems".to_string(); - if self._scopes.len() == 0 { self._scopes.insert(Scope::Full.as_slice().to_string(), ()); } - url.push('?'); - url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + + if params.len() > 0 { + url.push('?'); + url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + } loop { let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys()); @@ -15396,20 +15473,23 @@ impl<'a, C, NC, A> WatermarkSetMethodBuilder<'a, C, NC, A> where NC: hyper::net: params.push((&name, value.clone())); } - let mut url = if stream.is_some() { - "https://www.googleapis.com/upload/youtube/v3/watermarks/set".to_string() + let (mut url, protocol) = if stream.is_some() { + ("https://www.googleapis.com/upload/youtube/v3/watermarks/set".to_string(), "simple") } else if resumeable_stream.is_some() { - "https://www.googleapis.com/resumable/upload/youtube/v3/watermarks/set".to_string() + ("https://www.googleapis.com/resumable/upload/youtube/v3/watermarks/set".to_string(), "resumable") } else { unreachable!() }; - + params.push(("uploadType", protocol.to_string())); if self._scopes.len() == 0 { self._scopes.insert(Scope::Full.as_slice().to_string(), ()); } - url.push('?'); - url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + + if params.len() > 0 { + url.push('?'); + url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + } loop { let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys()); @@ -15632,13 +15712,15 @@ impl<'a, C, NC, A> WatermarkUnsetMethodBuilder<'a, C, NC, A> where NC: hyper::ne } let mut url = "https://www.googleapis.com/youtube/v3/watermarks/unset".to_string(); - if self._scopes.len() == 0 { self._scopes.insert(Scope::Full.as_slice().to_string(), ()); } - url.push('?'); - url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + + if params.len() > 0 { + url.push('?'); + url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + } loop { let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys()); @@ -15863,13 +15945,15 @@ impl<'a, C, NC, A> LiveBroadcastControlMethodBuilder<'a, C, NC, A> where NC: hyp } let mut url = "https://www.googleapis.com/youtube/v3/liveBroadcasts/control".to_string(); - if self._scopes.len() == 0 { self._scopes.insert(Scope::Full.as_slice().to_string(), ()); } - url.push('?'); - url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + + if params.len() > 0 { + url.push('?'); + url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + } loop { let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys()); @@ -16152,13 +16236,15 @@ impl<'a, C, NC, A> LiveBroadcastUpdateMethodBuilder<'a, C, NC, A> where NC: hype } let mut url = "https://www.googleapis.com/youtube/v3/liveBroadcasts".to_string(); - if self._scopes.len() == 0 { self._scopes.insert(Scope::Full.as_slice().to_string(), ()); } - url.push('?'); - url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + + if params.len() > 0 { + url.push('?'); + url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + } loop { let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys()); @@ -16428,13 +16514,15 @@ impl<'a, C, NC, A> LiveBroadcastInsertMethodBuilder<'a, C, NC, A> where NC: hype } let mut url = "https://www.googleapis.com/youtube/v3/liveBroadcasts".to_string(); - if self._scopes.len() == 0 { self._scopes.insert(Scope::Full.as_slice().to_string(), ()); } - url.push('?'); - url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + + if params.len() > 0 { + url.push('?'); + url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + } loop { let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys()); @@ -16695,13 +16783,15 @@ impl<'a, C, NC, A> LiveBroadcastBindMethodBuilder<'a, C, NC, A> where NC: hyper: } let mut url = "https://www.googleapis.com/youtube/v3/liveBroadcasts/bind".to_string(); - if self._scopes.len() == 0 { self._scopes.insert(Scope::Full.as_slice().to_string(), ()); } - url.push('?'); - url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + + if params.len() > 0 { + url.push('?'); + url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + } loop { let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys()); @@ -16976,13 +17066,15 @@ impl<'a, C, NC, A> LiveBroadcastListMethodBuilder<'a, C, NC, A> where NC: hyper: } let mut url = "https://www.googleapis.com/youtube/v3/liveBroadcasts".to_string(); - if self._scopes.len() == 0 { self._scopes.insert(Scope::Readonly.as_slice().to_string(), ()); } - url.push('?'); - url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + + if params.len() > 0 { + url.push('?'); + url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + } loop { let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys()); @@ -17239,13 +17331,15 @@ impl<'a, C, NC, A> LiveBroadcastDeleteMethodBuilder<'a, C, NC, A> where NC: hype } let mut url = "https://www.googleapis.com/youtube/v3/liveBroadcasts".to_string(); - if self._scopes.len() == 0 { self._scopes.insert(Scope::Full.as_slice().to_string(), ()); } - url.push('?'); - url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + + if params.len() > 0 { + url.push('?'); + url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + } loop { let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys()); @@ -17471,13 +17565,15 @@ impl<'a, C, NC, A> LiveBroadcastTransitionMethodBuilder<'a, C, NC, A> where NC: } let mut url = "https://www.googleapis.com/youtube/v3/liveBroadcasts/transition".to_string(); - if self._scopes.len() == 0 { self._scopes.insert(Scope::Full.as_slice().to_string(), ()); } - url.push('?'); - url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + + if params.len() > 0 { + url.push('?'); + url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + } loop { let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys()); @@ -17733,13 +17829,15 @@ impl<'a, C, NC, A> VideoCategoryListMethodBuilder<'a, C, NC, A> where NC: hyper: } let mut url = "https://www.googleapis.com/youtube/v3/videoCategories".to_string(); - if self._scopes.len() == 0 { self._scopes.insert(Scope::Readonly.as_slice().to_string(), ()); } - url.push('?'); - url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + + if params.len() > 0 { + url.push('?'); + url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + } loop { let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys()); @@ -18000,13 +18098,15 @@ impl<'a, C, NC, A> ActivityListMethodBuilder<'a, C, NC, A> where NC: hyper::net: } let mut url = "https://www.googleapis.com/youtube/v3/activities".to_string(); - if self._scopes.len() == 0 { self._scopes.insert(Scope::Readonly.as_slice().to_string(), ()); } - url.push('?'); - url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + + if params.len() > 0 { + url.push('?'); + url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + } loop { let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys()); @@ -18282,13 +18382,15 @@ impl<'a, C, NC, A> ActivityInsertMethodBuilder<'a, C, NC, A> where NC: hyper::ne } let mut url = "https://www.googleapis.com/youtube/v3/activities".to_string(); - if self._scopes.len() == 0 { self._scopes.insert(Scope::Full.as_slice().to_string(), ()); } - url.push('?'); - url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + + if params.len() > 0 { + url.push('?'); + url.push_str(&url::form_urlencoded::serialize(params.iter().map(|t| (t.0, t.1.as_slice())))); + } loop { let mut token = self.hub.auth.borrow_mut().token(self._scopes.keys()); diff --git a/src/mako/lib.rs.mako b/src/mako/lib.rs.mako index ac68efd5b7..59e216ad14 100644 --- a/src/mako/lib.rs.mako +++ b/src/mako/lib.rs.mako @@ -4,9 +4,9 @@ <%namespace name="mbuild" file="lib/mbuild.mako"/>\ <%namespace name="schema" file="lib/schema.mako"/>\ <% - from util import (new_context, rust_comment, rust_doc_comment, - rust_module_doc_comment, rb_type, hub_type, mangle_ident, hub_type_params_s, - hub_type_bounds, rb_type_params_s, find_fattest_resource, HUB_TYPE_PARAMETERS) + from util import (new_context, rust_comment, rust_doc_comment, rust_module_doc_comment, + rb_type, hub_type, mangle_ident, hub_type_params_s, hub_type_bounds, + rb_type_params_s, find_fattest_resource, HUB_TYPE_PARAMETERS, METHODS_RESOURCE) c = new_context(schemas, resources, context.get('methods')) hub_type = hub_type(c.schemas, util.canonical_name()) diff --git a/src/mako/lib/lib.mako b/src/mako/lib/lib.mako index b5e00a61c1..37a819f2be 100644 --- a/src/mako/lib/lib.mako +++ b/src/mako/lib/lib.mako @@ -3,7 +3,8 @@ unindent_first_by, mangle_ident, mb_type, singular, scope_url_to_variant, PART_MARKER_TRAIT, RESOURCE_MARKER_TRAIT, METHOD_BUILDER_MARKERT_TRAIT, find_fattest_resource, build_all_params, pass_through, parts_from_params, - REQUEST_MARKER_TRAIT, RESPONSE_MARKER_TRAIT, supports_scopes, to_api_version) %>\ + REQUEST_MARKER_TRAIT, RESPONSE_MARKER_TRAIT, supports_scopes, to_api_version, + to_fqan) %>\ <%namespace name="util" file="util.mako"/>\ <%namespace name="mbuild" file="mbuild.mako"/>\ @@ -97,11 +98,7 @@ Or specifically ... ```ignore % for an, a in c.sta_map[fr.id].iteritems(): <% category, resource, activity = activity_split(an) %>\ -% if resource: let r = hub.${mangle_ident(resource)}().${mangle_ident(activity)}(...).${api.terms.action}() -% else: -let r = hub.${mangle_ident(activity)}(...).${api.terms.action}() -% endif % endfor ``` % endif @@ -212,7 +209,9 @@ let mut hub = ${hub_type}::new(hyper::Client::new(), auth);\ last_param_count = None for fqan in c.sta_map[fr.id]: category, aresource, amethod = activity_split(fqan) - am = c.fqan_map[fqan] + # Cannot use fqan directly, as it might need remapping thanks to 'special case' resource. + # see METHODS_RESOURCE for more information + am = c.fqan_map[to_fqan(category, aresource, amethod)] build_all_params(c, am) aparams, arequest_value = build_all_params(c, am) diff --git a/src/mako/lib/rbuild.mako b/src/mako/lib/rbuild.mako index 8fc61078c1..a5ab6a2064 100644 --- a/src/mako/lib/rbuild.mako +++ b/src/mako/lib/rbuild.mako @@ -90,11 +90,11 @@ impl${rb_params} ${ThisType} { % for p in optional_props: ${property(p.name)}: Default::default(), % endfor - % for prop_key, custom_name in api.properties.iteritems(): +% for prop_key, custom_name in api.properties.iteritems(): % if prop_key == 'scopes' and (not auth or not auth.oauth2): - <% continue %>\ +<% continue %>\ % endif -${custom_name}: Default::default(), + ${custom_name}: Default::default(), % endfor } } diff --git a/src/mako/lib/util.py b/src/mako/lib/util.py index 4bba69727c..634824c9b0 100644 --- a/src/mako/lib/util.py +++ b/src/mako/lib/util.py @@ -52,6 +52,7 @@ IO_REQUEST = 'request' IO_TYPES = (IO_REQUEST, IO_RESPONSE) INS_METHOD = 'insert' DEL_METHOD = 'delete' +METHODS_RESOURCE = 'methods' SPACES_PER_TAB = 4 @@ -416,7 +417,7 @@ def activity_split(fqan): if not mt: # make this the method, with not resource mt = [t[1]] - t[1] = None + t[1] = METHODS_RESOURCE # end return t[0], t[1], '.'.join(mt) @@ -593,11 +594,14 @@ def new_context(schemas, resources, methods): continue for mn, m in a.methods.iteritems(): assert m.id not in fqan - fqan[m.id] = m category, resource, method = activity_split(m.id) - # Put the same method under different names to make access easier - if resource is None: - fqan[to_fqan(category, category, method)] = m + # This may be another name by which people try to find the method. + # As it has no resource, we put in a 'fake resource' (METHODS_RESOURCE), which + # needs some special treatment only in key-spots + fqan_key = m.id + if resource == METHODS_RESOURCE: + fqan_key = to_fqan(category, resource, method) + fqan[fqan_key] = m for in_out_type_name in IO_TYPES: t = m.get(in_out_type_name, None) if t is None: @@ -612,12 +616,11 @@ def new_context(schemas, resources, methods): # delete: has no response or request # getrating: response is a 'SomethingResult', which is still related to activities name # the latter is used to deduce the resource name - if resource: - tn = activity_name_to_type_name(resource) - info = res.setdefault(tn, dict()) - if m.id not in info: - info.setdefault(m.id, []) - # end handle other cases + tn = activity_name_to_type_name(resource) + info = res.setdefault(tn, dict()) + if m.id not in info: + info.setdefault(m.id, []) + # end handle other cases # end for each method # end for each activity return res, fqan @@ -702,13 +705,9 @@ def new_context(schemas, resources, methods): _sta_map, _fqan_map = build_activity_mappings(data_source) for an in _fqan_map: category, resource, activity = activity_split(an) - resource = resource or category rta_map.setdefault(resource, list()).append(activity) assert rtc_map.setdefault(resource, category) == category # end for each fqan - # TODO: DEBUG: Remove this when it was run on all APIs - assert len(set(sta_map.keys()) & set(_sta_map.keys())) == 0 - assert len(set(fqan_map.keys()) & set(_fqan_map.keys())) == 0, set(fqan_map.keys()) & set(_fqan_map.keys()) sta_map.update(_sta_map) fqan_map.update(_fqan_map) # end for each data source