From 6da12775075927176208756daab7f3f40747ed73 Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Sat, 28 Nov 2015 18:12:43 -0500 Subject: [PATCH] Factor out auth_header and accept_header --- src/client.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/client.rs b/src/client.rs index 0c18909..7e820ff 100644 --- a/src/client.rs +++ b/src/client.rs @@ -152,16 +152,17 @@ impl Client { Ok(uri.serialize()) } - /// Requests an access token using an authorization code. - pub fn request_token(&self, code: &str) -> Result { - let auth_header = header::Authorization( + fn auth_header(&self) -> header::Authorization { + header::Authorization( header::Basic { username: self.client_id.clone(), password: Some(self.client_secret.clone()), } - ); + ) + } - let accept_header = header::Accept(vec![ + fn accept_header(&self) -> header::Accept { + header::Accept(vec![ header::qitem( mime::Mime( mime::TopLevel::Application, @@ -169,8 +170,11 @@ impl Client { vec![] ) ), - ]); + ]) + } + /// Requests an access token using an authorization code. + pub fn request_token(&self, code: &str) -> Result { let mut body_pairs = vec![ ("grant_type", "authorization_code"), ("code", code), @@ -182,8 +186,8 @@ impl Client { let body_str = form_urlencoded::serialize(body_pairs); let request = self.http_client.post(&self.token_uri) - .header(auth_header) - .header(accept_header) + .header(self.auth_header()) + .header(self.accept_header()) .header(header::ContentType::form_url_encoded()) .body(&body_str);