From baea071a6f1c52410c0ca79cf24ab325f6efa586 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 8 Mar 2015 17:42:41 +0100 Subject: [PATCH] fix(mbuild): added size and mime type support This information must be provided, I just forgot it --- gen/youtube3/cargo.toml | 1 + gen/youtube3/src/lib.rs | 86 +++++++++++++++++++++++----------------- src/mako/cargo.toml.mako | 1 + src/mako/lib.rs.mako | 1 + src/mako/lib/mbuild.mako | 30 +++++++++----- src/mako/lib/util.py | 2 + 6 files changed, 75 insertions(+), 46 deletions(-) diff --git a/gen/youtube3/cargo.toml b/gen/youtube3/cargo.toml index 35b6a9fa08d..79bd5abbfbf 100644 --- a/gen/youtube3/cargo.toml +++ b/gen/youtube3/cargo.toml @@ -15,6 +15,7 @@ keywords = ["youtube", "google", "protocol", "web", "api"] [dependencies] hyper = "*" +mime = "*" rustc-serialize = "*" yup-oauth2 = "*" diff --git a/gen/youtube3/src/lib.rs b/gen/youtube3/src/lib.rs index 8b1cf45a6ea..047f2282d59 100644 --- a/gen/youtube3/src/lib.rs +++ b/gen/youtube3/src/lib.rs @@ -120,6 +120,7 @@ extern crate hyper; extern crate "rustc-serialize" as rustc_serialize; extern crate "yup-oauth2" as oauth2; +extern crate mime; mod cmn; @@ -5021,6 +5022,7 @@ impl<'a, C, NC, A> I18nLanguageListMethodBuilder<'a, C, NC, A> { /// # extern crate "rustc-serialize" as rustc_serialize; /// # extern crate youtube3; /// # use youtube3::ChannelBannerResource; +/// # use std::fs::File; /// # #[test] fn egal() { /// # use std::default::Default; /// # use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage}; @@ -5037,11 +5039,11 @@ impl<'a, C, NC, A> I18nLanguageListMethodBuilder<'a, C, NC, A> { /// let mut req: ChannelBannerResource = Default::default(); /// /// // You can configure optional parameters by calling the respective setters at will, and -/// // execute the final call using `doit()`. +/// // execute the final call using `upload_resumable(...)`. /// // Values shown here are possibly random and not representative ! /// let result = hub.channel_banners().insert(&req) /// .on_behalf_of_content_owner("Stet") -/// .doit(); +/// .upload_resumable(File::open("filepath.ext").unwrap(), 282, "application/octet-stream".parse().unwrap()); /// // TODO: show how to handle the result ! /// # } /// ``` @@ -5063,18 +5065,19 @@ impl<'a, C, NC, A> ChannelBannerInsertMethodBuilder<'a, C, NC, A> { /// Perform the operation you have build so far. /// TODO: Build actual call - fn doit(mut self, stream: Option, resumeable_stream: Option) -> () where R: BorrowMut, RS: BorrowMut { + fn doit(mut self, stream: Option<(R, u64, mime::Mime)>, resumeable_stream: Option<(RS, u64, mime::Mime)>) -> () where R: Read, RS: ReadSeek { } - pub fn upload(mut self, stream: R) -> () - where R: BorrowMut { - let mut v: Option = None; - self.doit(Some(stream), v) + /// TODO: FOO + pub fn upload(mut self, stream: R, size: u64, mime_type: mime::Mime) -> () + where R: Read { + self.doit(Some((stream, size, mime_type)), None::<(File, u64, mime::Mime)>, ) } - pub fn upload_resumable(mut self, resumeable_stream: RS) -> () - where RS: BorrowMut { - self.doit(None, Some(resumeable_stream), ) + /// TODO: BAR + pub fn upload_resumable(mut self, resumeable_stream: RS, size: u64, mime_type: mime::Mime) -> () + where RS: ReadSeek { + self.doit(None::<(File, u64, mime::Mime)>, Some((resumeable_stream, size, mime_type)), ) } /// Sets the *request* property to the given value. @@ -6322,6 +6325,7 @@ impl<'a, C, NC, A> PlaylistUpdateMethodBuilder<'a, C, NC, A> { /// # extern crate "yup-oauth2" as oauth2; /// # extern crate "rustc-serialize" as rustc_serialize; /// # extern crate youtube3; +/// # use std::fs::File; /// # #[test] fn egal() { /// # use std::default::Default; /// # use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage}; @@ -6333,11 +6337,11 @@ impl<'a, C, NC, A> PlaylistUpdateMethodBuilder<'a, C, NC, A> { /// # ::default(), None); /// # let mut hub = YouTube::new(hyper::Client::new(), auth); /// // You can configure optional parameters by calling the respective setters at will, and -/// // execute the final call using `doit()`. +/// // execute the final call using `upload_resumable(...)`. /// // Values shown here are possibly random and not representative ! /// let result = hub.thumbnails().set("videoId") /// .on_behalf_of_content_owner("kasd") -/// .doit(); +/// .upload_resumable(File::open("filepath.ext").unwrap(), 282, "application/octet-stream".parse().unwrap()); /// // TODO: show how to handle the result ! /// # } /// ``` @@ -6359,17 +6363,19 @@ impl<'a, C, NC, A> ThumbnailSetMethodBuilder<'a, C, NC, A> { /// Perform the operation you have build so far. /// TODO: Build actual call - fn doit(mut self, stream: Option, resumeable_stream: Option) -> () where R: BorrowMut, RS: BorrowMut { + fn doit(mut self, stream: Option<(R, u64, mime::Mime)>, resumeable_stream: Option<(RS, u64, mime::Mime)>) -> () where R: Read, RS: ReadSeek { } - pub fn upload(mut self, stream: R) -> () - where R: BorrowMut { - self.doit(Some(stream), None, ) + /// TODO: FOO + pub fn upload(mut self, stream: R, size: u64, mime_type: mime::Mime) -> () + where R: Read { + self.doit(Some((stream, size, mime_type)), None::<(File, u64, mime::Mime)>, ) } - pub fn upload_resumable(mut self, resumeable_stream: RS) -> () - where RS: BorrowMut { - self.doit(None, Some(resumeable_stream), ) + /// TODO: BAR + pub fn upload_resumable(mut self, resumeable_stream: RS, size: u64, mime_type: mime::Mime) -> () + where RS: ReadSeek { + self.doit(None::<(File, u64, mime::Mime)>, Some((resumeable_stream, size, mime_type)), ) } /// Sets the *video id* query property to the given value. @@ -7128,6 +7134,7 @@ impl<'a, C, NC, A> VideoUpdateMethodBuilder<'a, C, NC, A> { /// # extern crate "rustc-serialize" as rustc_serialize; /// # extern crate youtube3; /// # use youtube3::Video; +/// # use std::fs::File; /// # #[test] fn egal() { /// # use std::default::Default; /// # use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage}; @@ -7156,7 +7163,7 @@ impl<'a, C, NC, A> VideoUpdateMethodBuilder<'a, C, NC, A> { /// req.recording_details = Default::default(); // is VideoRecordingDetails /// /// // You can configure optional parameters by calling the respective setters at will, and -/// // execute the final call using `doit()`. +/// // execute the final call using `upload_resumable(...)`. /// // Values shown here are possibly random and not representative ! /// let result = hub.videos().insert(&req) /// .stabilize(true) @@ -7164,7 +7171,7 @@ impl<'a, C, NC, A> VideoUpdateMethodBuilder<'a, C, NC, A> { /// .on_behalf_of_content_owner("accusam") /// .notify_subscribers(true) /// .auto_levels(false) -/// .doit(); +/// .upload_resumable(File::open("filepath.ext").unwrap(), 282, "application/octet-stream".parse().unwrap()); /// // TODO: show how to handle the result ! /// # } /// ``` @@ -7191,17 +7198,19 @@ impl<'a, C, NC, A> VideoInsertMethodBuilder<'a, C, NC, A> { /// Perform the operation you have build so far. /// TODO: Build actual call - fn doit(mut self, stream: Option, resumeable_stream: Option) -> () where R: BorrowMut, RS: BorrowMut { + fn doit(mut self, stream: Option<(R, u64, mime::Mime)>, resumeable_stream: Option<(RS, u64, mime::Mime)>) -> () where R: Read, RS: ReadSeek { } - pub fn upload(mut self, stream: R) -> () - where R: BorrowMut { - self.doit(Some(stream), None, ) + /// TODO: FOO + pub fn upload(mut self, stream: R, size: u64, mime_type: mime::Mime) -> () + where R: Read { + self.doit(Some((stream, size, mime_type)), None::<(File, u64, mime::Mime)>, ) } - pub fn upload_resumable(mut self, resumeable_stream: RS) -> () - where RS: BorrowMut { - self.doit(None, Some(resumeable_stream), ) + /// TODO: BAR + pub fn upload_resumable(mut self, resumeable_stream: RS, size: u64, mime_type: mime::Mime) -> () + where RS: ReadSeek { + self.doit(None::<(File, u64, mime::Mime)>, Some((resumeable_stream, size, mime_type)), ) } /// Sets the *request* property to the given value. @@ -9655,6 +9664,7 @@ impl<'a, C, NC, A> PlaylistItemUpdateMethodBuilder<'a, C, NC, A> { /// # extern crate "rustc-serialize" as rustc_serialize; /// # extern crate youtube3; /// # use youtube3::InvideoBranding; +/// # use std::fs::File; /// # #[test] fn egal() { /// # use std::default::Default; /// # use oauth2::{Authenticator, DefaultAuthenticatorDelegate, ApplicationSecret, MemoryStorage}; @@ -9671,11 +9681,11 @@ impl<'a, C, NC, A> PlaylistItemUpdateMethodBuilder<'a, C, NC, A> { /// let mut req: InvideoBranding = Default::default(); /// /// // You can configure optional parameters by calling the respective setters at will, and -/// // execute the final call using `doit()`. +/// // execute the final call using `upload_resumable(...)`. /// // Values shown here are possibly random and not representative ! /// let result = hub.watermarks().set(&req, "channelId") /// .on_behalf_of_content_owner("sanctus") -/// .doit(); +/// .upload_resumable(File::open("filepath.ext").unwrap(), 282, "application/octet-stream".parse().unwrap()); /// // TODO: show how to handle the result ! /// # } /// ``` @@ -9698,17 +9708,19 @@ impl<'a, C, NC, A> WatermarkSetMethodBuilder<'a, C, NC, A> { /// Perform the operation you have build so far. /// TODO: Build actual call - fn doit(mut self, stream: Option, resumeable_stream: Option) -> () where R: BorrowMut, RS: BorrowMut { + fn doit(mut self, stream: Option<(R, u64, mime::Mime)>, resumeable_stream: Option<(RS, u64, mime::Mime)>) -> () where R: Read, RS: ReadSeek { } - pub fn upload(mut self, stream: R) -> () - where R: BorrowMut { - self.doit(Some(stream), None, ) + /// TODO: FOO + pub fn upload(mut self, stream: R, size: u64, mime_type: mime::Mime) -> () + where R: Read { + self.doit(Some((stream, size, mime_type)), None::<(File, u64, mime::Mime)>, ) } - pub fn upload_resumable(mut self, resumeable_stream: RS) -> () - where RS: BorrowMut { - self.doit(None, Some(resumeable_stream), ) + /// TODO: BAR + pub fn upload_resumable(mut self, resumeable_stream: RS, size: u64, mime_type: mime::Mime) -> () + where RS: ReadSeek { + self.doit(None::<(File, u64, mime::Mime)>, Some((resumeable_stream, size, mime_type)), ) } /// Sets the *request* property to the given value. diff --git a/src/mako/cargo.toml.mako b/src/mako/cargo.toml.mako index 5677d90a6bb..44549cfc31e 100644 --- a/src/mako/cargo.toml.mako +++ b/src/mako/cargo.toml.mako @@ -17,6 +17,7 @@ keywords = ["${name}", ${", ".join(estr(cargo.keywords))}] [dependencies] hyper = "*" +mime = "*" rustc-serialize = "*" yup-oauth2 = "*" diff --git a/src/mako/lib.rs.mako b/src/mako/lib.rs.mako index 6449888f222..93e57c44147 100644 --- a/src/mako/lib.rs.mako +++ b/src/mako/lib.rs.mako @@ -24,6 +24,7 @@ ${lib.docs(c)} extern crate hyper; extern crate "rustc-serialize" as rustc_serialize; extern crate "yup-oauth2" as oauth2; +extern crate mime; mod cmn; diff --git a/src/mako/lib/mbuild.mako b/src/mako/lib/mbuild.mako index 64e1f5e461a..a65e11f3aef 100644 --- a/src/mako/lib/mbuild.mako +++ b/src/mako/lib/mbuild.mako @@ -78,7 +78,7 @@ the *${m.scopes[0]}* scope to make a valid call. /// Instantiate a resource method builder /// <%block filter="rust_doc_comment">\ -${self.usage(resource, method, params, request_value, parts)}\ +${self.usage(resource, method, m, params, request_value, parts)}\ pub struct ${ThisType} where NC: 'a, @@ -178,7 +178,7 @@ ${self._setter_fn(resource, method, m, p, part_prop, ThisType, c)}\ ## creates usage docs the method builder ############################################################################################### ############################################################################################### -<%def name="usage(resource, method, params, request_value, parts)">\ +<%def name="usage(resource, method, m, params, request_value, parts)">\ <% hub_type_name = hub_type(util.canonical_name()) required_props, optional_props, part_prop = organize_params(params, request_value) @@ -202,6 +202,11 @@ ${self._setter_fn(resource, method, m, p, part_prop, ThisType, c)}\ # end for each required property required_args = ', '.join(required_args) + media_params = method_media_params(m) + + action_name = media_params and (api.terms.upload_action + media_params[-1].type.suffix) or api.terms.action + action_args = media_params and media_params[-1].type.example_value or '' + random_value_warning = "Values shown here are possibly random and not representative !" %>\ <%block filter="rust_doc_test_norun">\ @@ -209,6 +214,9 @@ ${capture(util.test_prelude) | hide_rust_doc_test}\ % if request_value: # use ${util.library_name()}::${request_value.id}; % endif +% if media_params: +# use std::fs::File; +% endif <%block filter="rust_test_fn_invisible">\ ${capture(lib.test_hub, hub_type_name, comments=False) | hide_rust_doc_test} % if request_value: @@ -237,7 +245,7 @@ ${rb_name}.${mangle_ident(spn)} = ${assignment} % endif // You can configure optional parameters by calling the respective setters at will, and -// execute the final call using `${api.terms.action}()`. +// execute the final call using `${action_name}(${action_args and '...' or ''})`. % if optional_props: // ${random_value_warning} % endif @@ -249,7 +257,7 @@ let result = hub.${mangle_ident(resource)}().${mangle_ident(method)}(${required_ \ % endfor -${'.' + api.terms.action | indent_by(13)}(); +${'.' + action_name | indent_by(13)}(${action_args}); // TODO: show how to handle the result ! \ @@ -275,7 +283,7 @@ ${'.' + api.terms.action | indent_by(13)}(); for p in media_params: type_params += p.type.param + ', ' where += p.type.param + ': ' + p.type.where + ', ' - add_args += p.type.arg_name + ': ' + ('Option<%s>' % p.type.param) + ', ' + add_args += p.type.arg_name + ': ' + ('Option<(%s, u64, mime::Mime)>' % p.type.param) + ', ' # end for each param where = ' where ' + stripped(where) type_params = '<' + stripped(type_params) + '>' @@ -291,15 +299,19 @@ ${'.' + api.terms.action | indent_by(13)}(); } % for p in media_params: - pub fn ${api.terms.upload_action}${p.type.suffix}<${p.type.param}>(mut self, ${p.type.arg_name}: ${p.type.param}) -> ${rtype} + <% + none_type = 'None::<(' + p.type.default + ', u64, mime::Mime)>' + %>\ + /// ${p.description} + pub fn ${api.terms.upload_action}${p.type.suffix}<${p.type.param}>(mut self, ${p.type.arg_name}: ${p.type.param}, size: u64, mime_type: mime::Mime) -> ${rtype} where ${p.type.param}: ${p.type.where} { self.${api.terms.action}(\ % for _ in range(0, loop.index): -None::<${p.type.default}>, \ +${none_type}, \ % endfor -Some(${p.type.arg_name}), \ +Some((${p.type.arg_name}, size, mime_type)), \ % for _ in range(loop.index+1, len(media_params)): -None::<${p.type.default}>, \ +${none_type}, \ % endfor ) } diff --git a/src/mako/lib/util.py b/src/mako/lib/util.py index 07a601fe1c8..8ea152a082c 100644 --- a/src/mako/lib/util.py +++ b/src/mako/lib/util.py @@ -54,6 +54,7 @@ 'default': 'File', 'where': 'Read', 'suffix': '', + 'example_value': 'File::open("filepath.ext").unwrap(), 148, "application/octet-stream".parse().unwrap()' }, 'resumable' : { 'arg_name': 'resumeable_stream', @@ -62,6 +63,7 @@ 'default': 'File', 'where': 'ReadSeek', 'suffix': '_resumable', + 'example_value': 'File::open("filepath.ext").unwrap(), 282, "application/octet-stream".parse().unwrap()' } }