refactor(url): simplify form_urlencode call

It's a great simplification and also uses less (if not zero) overhead,
finally.
Requires url v0.2.33
This commit is contained in:
Sebastian Thiel
2015-05-05 08:57:13 +02:00
parent 33e5849d0b
commit 9cafc3720e
2 changed files with 10 additions and 12 deletions

View File

@@ -185,12 +185,12 @@ impl<C> DeviceFlow<C>
// 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_ref())
.intersperse(" ")
.collect::<String>()
.as_ref())].iter().cloned());
&[("client_id", client_id),
("scope", scopes.into_iter()
.map(|s| s.as_ref())
.intersperse(" ")
.collect::<String>()
.as_ref())]);
match self.client.borrow_mut().post(FlowType::Device.as_ref())
.header(ContentType("application/x-www-form-urlencoded".parse().unwrap()))
@@ -277,11 +277,10 @@ impl<C> DeviceFlow<C>
// We should be ready for a new request
let req = form_urlencoded::serialize(
[("client_id", &self.id[..]),
&[("client_id", &self.id[..]),
("client_secret", &self.secret),
("code", &self.device_code),
("grant_type", "http://oauth.net/grant_type/device/1.0")]
.iter().cloned());
("grant_type", "http://oauth.net/grant_type/device/1.0")]);
let json_str =
match self.client.borrow_mut().post(GOOGLE_TOKEN_URL)

View File

@@ -66,11 +66,10 @@ impl<C> RefreshFlow<C>
}
let req = form_urlencoded::serialize(
[("client_id", client_id),
&[("client_id", client_id),
("client_secret", client_secret),
("refresh_token", refresh_token),
("grant_type", "refresh_token")]
.iter().cloned());
("grant_type", "refresh_token")]);
let json_str =
match self.client.borrow_mut().post(GOOGLE_TOKEN_URL)