Removed functions
This commit is contained in:
+9
-29
@@ -1,6 +1,7 @@
|
||||
use std::default::Default;
|
||||
|
||||
use crate::models;
|
||||
use crate::syncers;
|
||||
|
||||
pub struct Download {
|
||||
pub api: models::api::API,
|
||||
@@ -27,23 +28,17 @@ impl Download {
|
||||
song: &icarus_models::song::Song,
|
||||
) -> Result<String, MyError> {
|
||||
self.api.endpoint = String::from("song/data/download");
|
||||
let url = self.retrieve_url(&song);
|
||||
let url = syncers::common::retrieve_url(&self.api, true, song.id);
|
||||
let access_token = token.bearer_token();
|
||||
|
||||
let mut headers = reqwest::header::HeaderMap::new();
|
||||
headers.insert(
|
||||
reqwest::header::AUTHORIZATION,
|
||||
http::header::HeaderValue::from_str(&access_token.clone()).unwrap(),
|
||||
);
|
||||
|
||||
let client = reqwest::Client::builder().build().unwrap();
|
||||
let response = client
|
||||
|
||||
match client
|
||||
.get(&url)
|
||||
.header(reqwest::header::AUTHORIZATION, &access_token)
|
||||
.send()
|
||||
.await;
|
||||
|
||||
match response {
|
||||
.await
|
||||
{
|
||||
Ok(rep) => match rep.status() {
|
||||
reqwest::StatusCode::OK => {
|
||||
let data = rep.text();
|
||||
@@ -52,35 +47,20 @@ impl Download {
|
||||
return Ok(e);
|
||||
}
|
||||
Err(er) => {
|
||||
println!("Error {:?}", er);
|
||||
return Err(MyError::Other(er.to_string()));
|
||||
}
|
||||
}
|
||||
}
|
||||
reqwest::StatusCode::UNAUTHORIZED => {
|
||||
println!("Need to grab a new token");
|
||||
return Err(MyError::Other(String::from("Need to grab a new token")));
|
||||
}
|
||||
other => {
|
||||
panic!("Uh oh! Something unexpected happened: {:?}", other);
|
||||
return Err(MyError::Other(other.to_string()));
|
||||
}
|
||||
},
|
||||
Err(er) => {
|
||||
return Err(MyError::Request(er));
|
||||
}
|
||||
}
|
||||
|
||||
return Err(MyError::Other(String::from("Error downloading")));
|
||||
}
|
||||
|
||||
fn retrieve_url(&self, song: &icarus_models::song::Song) -> String {
|
||||
let api = &self.api;
|
||||
let mut url: String = String::from(&api.url);
|
||||
url += &String::from("api/");
|
||||
url += &String::from(&api.version);
|
||||
url += &String::from("/");
|
||||
url += &String::from(&api.endpoint);
|
||||
url += &String::from("/");
|
||||
url += &song.id.to_string();
|
||||
|
||||
return url;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user