Skip to content

Commit

Permalink
fix(API): filter null values of requrest structs
Browse files Browse the repository at this point in the history
Some servers, like youtube, reject null values possibly thanks to
the reliance on parts. Now we are filtering them (in a very inefficient,
but working way), which seems to be fine with the servers.

Effectively, we seem to be able now to upload videos ... .

More testing required !
  • Loading branch information
Byron committed May 8, 2015
1 parent 3fe2732 commit 3efa4f2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions etc/api/type-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ cargo:
- url = "*"
- serde = ">= 0.3.0"
- serde_macros = "*"
- json-tools = "*"
1 change: 0 additions & 1 deletion etc/api/type-cli.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,3 @@ cargo:
- serde = ">= 0.3.0"
- serde_macros = "*"
- clap = "*"
- json-tools = "*"
1 change: 1 addition & 0 deletions src/mako/api/lib.rs.mako
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ extern crate serde;
extern crate yup_oauth2 as oauth2;
extern crate mime;
extern crate url;
extern crate json_tools;

mod cmn;

Expand Down
13 changes: 12 additions & 1 deletion src/mako/api/lib/mbuild.mako
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,18 @@ else {
% if request_value:
let mut json_mime_type = mime::Mime(mime::TopLevel::Application, mime::SubLevel::Json, Default::default());
let mut request_value_reader = io::Cursor::new(json::to_vec(&self.${property(REQUEST_VALUE_PROPERTY_NAME)}));
let mut request_value_reader =
{
let json_cache = json::to_string(&self.${property(REQUEST_VALUE_PROPERTY_NAME)}).unwrap();
io::Cursor::new(json_tools::TokenReader::new(
json_tools::FilterTypedKeyValuePairs::new(
json_tools::Lexer::new(
json_cache.bytes(),
json_tools::BufferType::Span),
json_tools::TokenType::Null),
Some(&json_cache)).bytes().filter_map(|v|v.ok()).collect::${'<Vec<u8>>'}()
)
};
let request_size = request_value_reader.seek(io::SeekFrom::End(0)).unwrap();
request_value_reader.seek(io::SeekFrom::Start(0)).unwrap();
% endif
Expand Down

0 comments on commit 3efa4f2

Please sign in to comment.