mirror of
https://github.com/OMGeeky/google-apis-rs.git
synced 2026-02-23 15:49:49 +01:00
feat(fields): put all fields onto a list
Also handle the case when the 'part' field is generated from the request. Additional params still need work
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
from util import (put_and, rust_test_fn_invisible, rust_doc_test_norun, rust_doc_comment,
|
||||
rb_type, mb_type, singular, hub_type, to_fqan, indent_all_but_first_by,
|
||||
method_params, activity_rust_type, mangle_ident, activity_input_type, get_word,
|
||||
split_camelcase_s, property, is_pod_property, TREF, method_io, IO_REQUEST,
|
||||
split_camelcase_s, property, is_pod_property, TREF, IO_REQUEST,
|
||||
schema_to_required_property, rust_copy_value_s, is_required_property,
|
||||
hide_rust_doc_test, build_all_params, REQUEST_VALUE_PROPERTY_NAME, organize_params,
|
||||
indent_by, to_rust_type, rnd_arg_val_for_type, extract_parts, mb_type_params_s,
|
||||
@@ -295,11 +295,55 @@ ${'.' + action_name | indent_by(13)}(${action_args});
|
||||
# end handle media params
|
||||
|
||||
action_fn = qualifier + 'fn ' + api.terms.action + type_params + ('(mut self%s)' % add_args) + ' -> ' + rtype + where
|
||||
|
||||
field_params = [p for p in params if p.get('is_query_param', True)]
|
||||
%>
|
||||
/// Perform the operation you have build so far.
|
||||
/// TODO: Build actual call
|
||||
${action_fn} {
|
||||
let mut params: Vec<(&str, String)> = Vec::with_capacity(${len(params)});
|
||||
% for p in field_params:
|
||||
<%
|
||||
pname = 'self.' + property(p.name) # property identifier
|
||||
%>\
|
||||
## parts can also be derived from the request, but we do that only if it's not set
|
||||
% if p.name == 'part' and request_value:
|
||||
% if not is_required_property(p):
|
||||
if ${pname}.is_none() {
|
||||
${pname} = Some(self.${property(REQUEST_VALUE_PROPERTY_NAME)}.to_parts());
|
||||
}
|
||||
% else:
|
||||
if ${pname}.len() == 0 {
|
||||
${pname} = self.${property(REQUEST_VALUE_PROPERTY_NAME)}.to_parts();
|
||||
}
|
||||
% endif
|
||||
% endif
|
||||
% if not is_required_property(p):
|
||||
if ${pname}.is_some() {
|
||||
params.push(("${p.name}", ${pname}.unwrap().to_string()));
|
||||
}
|
||||
% else:
|
||||
params.push(("${p.name}", ${pname}.to_string()));
|
||||
% endif
|
||||
% endfor
|
||||
## Additional params - may not overlap with optional params
|
||||
## let mut params: Vec<(String, String)> = Vec::with_capacity
|
||||
## // note: cloned() shouldn't be needed, see issue
|
||||
## // https://github.com/servo/rust-url/issues/81
|
||||
## let req = form_urlencoded::serialize(
|
||||
## [("client_id", client_id),
|
||||
## ("scope", scopes.into_iter()
|
||||
## .map(|s| s.as_slice())
|
||||
## .intersperse(" ")
|
||||
## .collect::<String>()
|
||||
## .as_slice())].iter().cloned());
|
||||
|
||||
## match self.client.borrow_mut().post(FlowType::Device.as_slice())
|
||||
## .header(ContentType("application/x-www-form-urlencoded".parse().unwrap()))
|
||||
## .body(req.as_slice())
|
||||
## .send() {
|
||||
## Err(err) => {
|
||||
## return RequestResult::Error(err);
|
||||
## }
|
||||
}
|
||||
|
||||
% for p in media_params:
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
from util import (put_and, rust_test_fn_invisible, rust_doc_test_norun, rust_doc_comment,
|
||||
rb_type, singular, hub_type, mangle_ident, mb_type, method_params, property,
|
||||
to_fqan, indent_all_but_first_by, schema_markers,
|
||||
activity_input_type, TREF, method_io, IO_REQUEST, schema_to_required_property,
|
||||
activity_input_type, TREF, IO_REQUEST, schema_to_required_property,
|
||||
rust_copy_value_s, is_required_property, organize_params, REQUEST_VALUE_PROPERTY_NAME,
|
||||
build_all_params, rb_type_params_s, hub_type_params_s, mb_type_params_s, mb_additional_type_params)
|
||||
%>\
|
||||
|
||||
@@ -418,7 +418,7 @@ def method_params(m, required=None, location=None):
|
||||
|
||||
# return the given method's request or response schema (dict), or None.
|
||||
# optionally return only schemas with the given marker trait
|
||||
def method_io(schemas, c, m, type, marker=None):
|
||||
def method_request(schemas, c, m, type, marker=None):
|
||||
s = schemas.get(m.get('request', dict()).get(TREF))
|
||||
if s is None:
|
||||
return s
|
||||
@@ -440,7 +440,7 @@ def rust_copy_value_s(n, tn, p):
|
||||
# convert a schema into a property (for use with rust type generation).
|
||||
# n = name of the property
|
||||
def schema_to_required_property(s, n):
|
||||
return type(s)({'name': n, TREF: s.id, 'priority': REQUEST_PRIORITY})
|
||||
return type(s)({'name': n, TREF: s.id, 'priority': REQUEST_PRIORITY, 'is_query_param': False})
|
||||
|
||||
def is_required_property(p):
|
||||
return p.get('required', False) or p.get('priority', 0) > 0
|
||||
@@ -495,7 +495,7 @@ def method_media_params(m):
|
||||
# Build all parameters used in a given method !
|
||||
# schemas, context, method(dict), 'request'|'response', request_prop_name -> (params, request_value|None)
|
||||
def build_all_params(schemas, c, m, n, npn):
|
||||
request_value = method_io(schemas, c, m, n)
|
||||
request_value = method_request(schemas, c, m, n)
|
||||
params = method_params(m)
|
||||
if request_value:
|
||||
params.insert(0, schema_to_required_property(request_value, npn))
|
||||
@@ -506,6 +506,7 @@ def build_all_params(schemas, c, m, n, npn):
|
||||
'clone_value': '{}',
|
||||
'skip_example' : True,
|
||||
'priority': 0,
|
||||
'is_query_param': False,
|
||||
'description':
|
||||
"""The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
|
||||
while executing the actual API request.
|
||||
|
||||
@@ -115,6 +115,7 @@ impl<'a, C, NC, A> ChannelSectionMethodsBuilder<'a, C, NC, A> {
|
||||
ChannelSectionInsertMethodBuilder {
|
||||
hub: self.hub,
|
||||
_delegate: Default::default(),
|
||||
_part: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -126,6 +127,7 @@ pub struct ChannelSectionInsertMethodBuilder<'a, C, NC, A>
|
||||
|
||||
hub: &'a YouTube<C, NC, A>,
|
||||
_delegate: Option<&'a mut Delegate>,
|
||||
_part: Option<String>,
|
||||
}
|
||||
|
||||
|
||||
@@ -134,6 +136,10 @@ impl<'a, C, NC, A> ChannelSectionInsertMethodBuilder<'a, C, NC, A> where NC: hyp
|
||||
/// Perform the operation you have build so far.
|
||||
/// TODO: Build actual call
|
||||
pub fn doit(mut self) -> () {
|
||||
let mut params: Vec<(&str, String)> = Vec::with_capacity(1);
|
||||
if self._part.is_none() {
|
||||
self._parts = "parts from request value".to_string();
|
||||
}
|
||||
if self._delegate.is_some() {
|
||||
self._delegate.as_mut().unwrap().connection_error(hyper::HttpError::HttpStatusError);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user