Code Tidyup

This commit is contained in:
Sasha Hilton 2018-02-08 02:17:52 +01:00
parent 9784d98847
commit 4205f9c18b

View file

@ -14,21 +14,8 @@ pub struct Token {
}
pub fn get_token(session: &Session, client_id: Option<&str>, scopes: &str) -> Box<Future<Item = Token, Error = MercuryError>> {
let client_id_env: Option<&'static str> = option_env!("CLIENT_ID");
let client_key: &str;
match client_id_env {
None => {
match client_id {
None => { panic!("No Client ID available.") },
Some(ref cid) => { client_key = cid },
}
},
Some(ref cid_env) => { client_key = cid_env }
}
let url = format!("hm://keymaster/token/authenticated?client_id={}&scope={}",
client_key, scopes);
let client_key = option_env!("CLIENT_ID").or(client_id).expect("No Client ID available");
let url = format!("hm://keymaster/token/authenticated?client_id={}&scope={}", client_key, scopes);
Box::new(session.mercury().get(url).map(move |response| {
let data = response.payload.first().expect("Empty payload");
let data = String::from_utf8(data.clone()).unwrap();