Skip to content

Commit

Permalink
fix(mbuild): added size and mime type support
Browse files Browse the repository at this point in the history
This information must be provided, I just forgot it
  • Loading branch information
Byron committed Mar 8, 2015
1 parent 6fad760 commit baea071
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 46 deletions.
1 change: 1 addition & 0 deletions gen/youtube3/cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ keywords = ["youtube", "google", "protocol", "web", "api"]

[dependencies]
hyper = "*"
mime = "*"
rustc-serialize = "*"
yup-oauth2 = "*"

Expand Down
86 changes: 49 additions & 37 deletions gen/youtube3/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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};
Expand All @@ -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 !
/// # }
/// ```
Expand All @@ -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<R = File, RS = File>(mut self, stream: Option<R>, resumeable_stream: Option<RS>) -> () where R: BorrowMut<Read>, RS: BorrowMut<ReadSeek> {
fn doit<R, RS>(mut self, stream: Option<(R, u64, mime::Mime)>, resumeable_stream: Option<(RS, u64, mime::Mime)>) -> () where R: Read, RS: ReadSeek {

}

pub fn upload<R>(mut self, stream: R) -> ()
where R: BorrowMut<Read> {
let mut v: Option<File> = None;
self.doit(Some(stream), v)
/// TODO: FOO
pub fn upload<R>(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<RS>(mut self, resumeable_stream: RS) -> ()
where RS: BorrowMut<ReadSeek> {
self.doit(None, Some(resumeable_stream), )
/// TODO: BAR
pub fn upload_resumable<RS>(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.
Expand Down Expand Up @@ -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};
Expand All @@ -6333,11 +6337,11 @@ impl<'a, C, NC, A> PlaylistUpdateMethodBuilder<'a, C, NC, A> {
/// # <MemoryStorage as Default>::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 !
/// # }
/// ```
Expand All @@ -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<R = File, RS = File>(mut self, stream: Option<R>, resumeable_stream: Option<RS>) -> () where R: BorrowMut<Read>, RS: BorrowMut<ReadSeek> {
fn doit<R, RS>(mut self, stream: Option<(R, u64, mime::Mime)>, resumeable_stream: Option<(RS, u64, mime::Mime)>) -> () where R: Read, RS: ReadSeek {

}

pub fn upload<R>(mut self, stream: R) -> ()
where R: BorrowMut<Read> {
self.doit(Some(stream), None, )
/// TODO: FOO
pub fn upload<R>(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<RS>(mut self, resumeable_stream: RS) -> ()
where RS: BorrowMut<ReadSeek> {
self.doit(None, Some(resumeable_stream), )
/// TODO: BAR
pub fn upload_resumable<RS>(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.
Expand Down Expand Up @@ -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};
Expand Down Expand Up @@ -7156,15 +7163,15 @@ 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)
/// .on_behalf_of_content_owner_channel("amet")
/// .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 !
/// # }
/// ```
Expand All @@ -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<R = File, RS = File>(mut self, stream: Option<R>, resumeable_stream: Option<RS>) -> () where R: BorrowMut<Read>, RS: BorrowMut<ReadSeek> {
fn doit<R, RS>(mut self, stream: Option<(R, u64, mime::Mime)>, resumeable_stream: Option<(RS, u64, mime::Mime)>) -> () where R: Read, RS: ReadSeek {

}

pub fn upload<R>(mut self, stream: R) -> ()
where R: BorrowMut<Read> {
self.doit(Some(stream), None, )
/// TODO: FOO
pub fn upload<R>(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<RS>(mut self, resumeable_stream: RS) -> ()
where RS: BorrowMut<ReadSeek> {
self.doit(None, Some(resumeable_stream), )
/// TODO: BAR
pub fn upload_resumable<RS>(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.
Expand Down Expand Up @@ -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};
Expand All @@ -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 !
/// # }
/// ```
Expand All @@ -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<R = File, RS = File>(mut self, stream: Option<R>, resumeable_stream: Option<RS>) -> () where R: BorrowMut<Read>, RS: BorrowMut<ReadSeek> {
fn doit<R, RS>(mut self, stream: Option<(R, u64, mime::Mime)>, resumeable_stream: Option<(RS, u64, mime::Mime)>) -> () where R: Read, RS: ReadSeek {

}

pub fn upload<R>(mut self, stream: R) -> ()
where R: BorrowMut<Read> {
self.doit(Some(stream), None, )
/// TODO: FOO
pub fn upload<R>(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<RS>(mut self, resumeable_stream: RS) -> ()
where RS: BorrowMut<ReadSeek> {
self.doit(None, Some(resumeable_stream), )
/// TODO: BAR
pub fn upload_resumable<RS>(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.
Expand Down
1 change: 1 addition & 0 deletions src/mako/cargo.toml.mako
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ keywords = ["${name}", ${", ".join(estr(cargo.keywords))}]
[dependencies]
hyper = "*"
mime = "*"
rustc-serialize = "*"
yup-oauth2 = "*"
Expand Down
1 change: 1 addition & 0 deletions src/mako/lib.rs.mako
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
30 changes: 21 additions & 9 deletions src/mako/lib/mbuild.mako
Original file line number Diff line number Diff line change
Expand Up @@ -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)}\
</%block>
pub struct ${ThisType}
where NC: 'a,
Expand Down Expand Up @@ -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)
Expand All @@ -202,13 +202,21 @@ ${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">\
${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:
Expand Down Expand Up @@ -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
Expand All @@ -249,7 +257,7 @@ let result = hub.${mangle_ident(resource)}().${mangle_ident(method)}(${required_
</%block>\
% endfor
${'.' + api.terms.action | indent_by(13)}();
${'.' + action_name | indent_by(13)}(${action_args});
// TODO: show how to handle the result !
</%block>
</%block>\
Expand All @@ -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) + '>'
Expand All @@ -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
)
}
Expand Down
2 changes: 2 additions & 0 deletions src/mako/lib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -62,6 +63,7 @@
'default': 'File',
'where': 'ReadSeek',
'suffix': '_resumable',
'example_value': 'File::open("filepath.ext").unwrap(), 282, "application/octet-stream".parse().unwrap()'
}
}

Expand Down

0 comments on commit baea071

Please sign in to comment.