Mercurial > lbo > hg > async-google-apis
changeset 17:09c6b2d7f1e0
Improve details for scopes and function parameters.
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Sat, 17 Oct 2020 18:45:01 +0200 |
parents | 3243f92caec1 |
children | 17d4446ae609 |
files | generate/generate.py generate/templates.py manual_demo/src/main.rs |
diffstat | 3 files changed, 17 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/generate/generate.py Sat Oct 17 18:28:41 2020 +0200 +++ b/generate/generate.py Sat Oct 17 18:45:01 2020 +0200 @@ -244,6 +244,7 @@ 'param': p, 'snake_param': sp } for (p, sp) in required_parameters.items()], + 'scopes': [{'scope': s} for s in method['scopes']], 'description': method.get('description', ''), 'http_method': http_method } @@ -266,6 +267,7 @@ 'param': p, 'snake_param': sp } for (p, sp) in required_parameters.items()], + 'scopes': [{'scope': s} for s in method['scopes']], 'description': method.get('description', ''), 'http_method': http_method, }
--- a/generate/templates.py Sat Oct 17 18:28:41 2020 +0200 +++ b/generate/templates.py Sat Oct 17 18:45:01 2020 +0200 @@ -70,7 +70,7 @@ # Takes: # name, description, param_type, in_type, out_type -# base_path, rel_path_expr +# base_path, rel_path_expr, scopes (string repr. of rust string array), # params: [{param, snake_param}] # http_method NormalMethodTmpl = ''' @@ -80,6 +80,11 @@ let rel_path = {{{rel_path_expr}}}; let path = "{{{base_path}}}".to_string() + &rel_path; + let mut scopes = &self.scopes; + if scopes.is_empty() { + scopes = &vec![{{#scopes}}"{{{scope}}}".to_string(), + {{/scopes}}]; + } let tok = self.authenticator.token(&self.scopes).await?; let mut url_params = format!("?oauth_token={token}&fields=*", token=tok.as_str()); {{#params}} @@ -96,13 +101,17 @@ .uri(full_uri) .method("{{{http_method}}}") .header("Content-Type", "application/json"); + + let body = hyper::Body::from(""); + {{#in_type}} let mut body_str = serde_json::to_string(req)?; if body_str == "null" { body_str.clear(); } let body = hyper::Body::from(body_str); - let req = reqb.body(body)?; - let resp = self.client.request(req).await?; + {{/in_type}} + let request = reqb.body(body)?; + let resp = self.client.request(request).await?; if !resp.status().is_success() { return Err(anyhow::Error::new(ApiError::HTTPError(resp.status()))); } @@ -142,8 +151,8 @@ .method("{{{http_method}}}") .header("Content-Length", data.len()); let body = hyper::Body::from(data); - let req = reqb.body(body)?; - let resp = self.client.request(req).await?; + let request = reqb.body(body)?; + let resp = self.client.request(request).await?; if !resp.status().is_success() { return Err(anyhow::Error::new(ApiError::HTTPError(resp.status()))); }
--- a/manual_demo/src/main.rs Sat Oct 17 18:28:41 2020 +0200 +++ b/manual_demo/src/main.rs Sat Oct 17 18:45:01 2020 +0200 @@ -90,7 +90,7 @@ let mut params = drive::FilesGetParams::default(); params.file_id = file_id.clone(); - println!("{:?}", cl.get(¶ms, &()).await.unwrap()); + println!("{:?}", cl.get(¶ms).await.unwrap()); } async fn get_about(cl: &mut TlsClient, auth: &mut Authenticator) {