mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
Add CLIENT_ID env var for compiling with a client id, remove unnecessary serde_derive
This commit is contained in:
parent
7ead896ae7
commit
9784d98847
2 changed files with 15 additions and 3 deletions
|
@ -13,9 +13,22 @@ pub struct Token {
|
|||
pub scope: Vec<String>,
|
||||
}
|
||||
|
||||
pub fn get_token(session: &Session, client_id: &str, scopes: &str) -> Box<Future<Item = Token, Error = MercuryError>> {
|
||||
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_id, scopes);
|
||||
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();
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
#[macro_use] extern crate log;
|
||||
#[macro_use] extern crate serde_json;
|
||||
#[macro_use] extern crate serde_derive;
|
||||
|
||||
extern crate base64;
|
||||
extern crate crypto;
|
||||
|
|
Loading…
Reference in a new issue