Move TokenResponse out of request_token

This commit is contained in:
Curtis McEnroe 2015-11-28 16:56:33 -05:00
parent a7e255b66c
commit 2eae2724b6
1 changed files with 22 additions and 16 deletions

View File

@ -19,6 +19,27 @@ pub struct Client {
redirect_uri: Option<String>,
}
#[derive(RustcDecodable)]
struct TokenResponse {
access_token: String,
token_type: String,
expires_in: Option<i64>,
refresh_token: Option<String>,
scope: Option<String>,
}
impl Into<Token> for TokenResponse {
fn into(self) -> Token {
Token {
access_token: self.access_token,
token_type: self.token_type,
expires: self.expires_in.map(|s| UTC::now() + Duration::seconds(s)),
refresh_token: self.refresh_token,
scope: self.scope,
}
}
}
macro_rules! site_constructors {
(
$(
@ -147,22 +168,7 @@ impl Client {
return Err(Error::Todo);
}
#[derive(RustcDecodable)]
struct TokenResponse {
access_token: String,
token_type: String,
expires_in: Option<i64>,
refresh_token: Option<String>,
scope: Option<String>,
}
let token: TokenResponse = try!(json::decode(&json));
Ok(Token {
access_token: token.access_token,
token_type: token.token_type,
expires: token.expires_in.map(|s| UTC::now() + Duration::seconds(s)),
refresh_token: token.refresh_token,
scope: token.scope,
})
Ok(token.into())
}
}