From de0c7a4ae049b6f7fbc256d64bc363ebd8de2101 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 8 Mar 2015 14:00:02 +0100 Subject: [PATCH] feat(mbuild): `param()` to set any parameter That way, things like drive.files.insert alt=media has a chance to work. We should actually check for this to support various 'alt' values --- gen/youtube3/README.md | 1 + src/mako/lib/lib.mako | 1 + src/mako/lib/mbuild.mako | 15 ++++++++++++++- src/mako/lib/rbuild.mako | 1 + 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/gen/youtube3/README.md b/gen/youtube3/README.md index 8cbdbcab0d..f6b4ed9d87 100644 --- a/gen/youtube3/README.md +++ b/gen/youtube3/README.md @@ -110,6 +110,7 @@ let mut hub = YouTube::new(hyper::Client::new(), auth); * pods are copy * strings are &str * request values are borrowed +* additional parameters using `param()` [builder-pattern]: http://en.wikipedia.org/wiki/Builder_pattern [google-go-api]: https://github.com/google/google-api-go-client diff --git a/src/mako/lib/lib.mako b/src/mako/lib/lib.mako index a9144ce6c9..dd0753d525 100644 --- a/src/mako/lib/lib.mako +++ b/src/mako/lib/lib.mako @@ -80,6 +80,7 @@ ${'##'} About builder arguments * pods are copy * strings are &str * request values are borrowed +* additional parameters using `param()` [builder-pattern]: http://en.wikipedia.org/wiki/Builder_pattern [google-go-api]: https://github.com/google/google-api-go-client diff --git a/src/mako/lib/mbuild.mako b/src/mako/lib/mbuild.mako index 922bec7dcc..5033a525f3 100644 --- a/src/mako/lib/mbuild.mako +++ b/src/mako/lib/mbuild.mako @@ -95,6 +95,8 @@ pub struct ${ThisType} ${activity_rust_type(p)}, % endif % endfor +## A generic map for additinal parameters. Sometimes you can set some that are documented online only + _additional_params: HashMap } impl${mb_tparams} MethodBuilder for ${ThisType} {} @@ -107,6 +109,17 @@ impl${mb_tparams} ${ThisType} { % for p in params: ${self._setter_fn(resource, method, m, p, part_prop, ThisType, c)}\ % endfor + + /// 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. + pub fn param(mut self, name: &str, value: &str) -> ${ThisType} { + self._additional_params.insert(name.to_string(), value.to_string()); + self + } } @@ -157,7 +170,7 @@ ${self._setter_fn(resource, method, m, p, part_prop, ThisType, c)}\ % endif pub fn ${mangle_ident(p.name)}(mut self, ${value_name}: ${InType}) -> ${ThisType} { self.${property(p.name)} = ${new_value_copied}; - return self; + self } diff --git a/src/mako/lib/rbuild.mako b/src/mako/lib/rbuild.mako index 998c34f8da..cd8c423a3c 100644 --- a/src/mako/lib/rbuild.mako +++ b/src/mako/lib/rbuild.mako @@ -84,6 +84,7 @@ impl${rb_params} ${ThisType} { % for p in optional_props: ${property(p.name)}: Default::default(), % endfor + _additional_params: Default::default() } } % endfor ## for each activity