Can now retrieve songs
This commit is contained in:
@@ -165,6 +165,34 @@ impl CommitManager {
|
|||||||
// TODO: Implement
|
// TODO: Implement
|
||||||
fn retrieve_object(&self) {
|
fn retrieve_object(&self) {
|
||||||
println!("Deleting song");
|
println!("Deleting song");
|
||||||
|
let rt = self.ica_action.retrieve_flag_value(&String::from("-rt"));
|
||||||
|
|
||||||
|
if rt != "songs" {
|
||||||
|
panic!("Unsupported -rt: {}", rt);
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut prsr = parsers::api_parser::APIParser {
|
||||||
|
api: models::api::API::default(),
|
||||||
|
ica_act: self.ica_action.clone(),
|
||||||
|
};
|
||||||
|
prsr.parse_api();
|
||||||
|
|
||||||
|
let api = prsr.retrieve_api();
|
||||||
|
let token = self.parse_token(&api);
|
||||||
|
let mut repo = syncers::retrieve_records::RetrieveRecords { api: api.clone() };
|
||||||
|
let result_fut = repo.get_all_songs(&token);
|
||||||
|
|
||||||
|
let result = Runtime::new().unwrap().block_on(result_fut);
|
||||||
|
match result {
|
||||||
|
Ok(o) => {
|
||||||
|
for song in o {
|
||||||
|
println!("{:?} - {:?}", song.artist, song.title);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(er) => {
|
||||||
|
println!("Error: {:?}", er);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn upload_song(&self) {
|
fn upload_song(&self) {
|
||||||
|
|||||||
@@ -19,13 +19,25 @@ impl Default for RetrieveRecords {
|
|||||||
|
|
||||||
impl RetrieveRecords {
|
impl RetrieveRecords {
|
||||||
pub async fn get_all_songs(
|
pub async fn get_all_songs(
|
||||||
&self,
|
&mut self,
|
||||||
token: &models::token::Token,
|
token: &models::token::Token,
|
||||||
) -> Result<Vec<models::song::Song>, Error> {
|
) -> Result<Vec<models::song::Song>, Error> {
|
||||||
|
self.api.endpoint = String::from("song");
|
||||||
let mut songs: Vec<models::song::Song> = Vec::new();
|
let mut songs: Vec<models::song::Song> = Vec::new();
|
||||||
let url = self.retrieve_url();
|
let url = self.retrieve_url();
|
||||||
let access_token = token.bearer_token();
|
let access_token = token.bearer_token();
|
||||||
let client = reqwest::Client::new();
|
|
||||||
|
let mut headers = reqwest::header::HeaderMap::new();
|
||||||
|
headers.insert(
|
||||||
|
reqwest::header::AUTHORIZATION,
|
||||||
|
http::header::HeaderValue::from_str(&access_token.clone()).unwrap(),
|
||||||
|
);
|
||||||
|
headers.insert(
|
||||||
|
reqwest::header::CONTENT_TYPE,
|
||||||
|
http::header::HeaderValue::from_static("application/json"),
|
||||||
|
);
|
||||||
|
|
||||||
|
let client = reqwest::Client::builder().build().unwrap();
|
||||||
let response = client
|
let response = client
|
||||||
.get(&url)
|
.get(&url)
|
||||||
.header(reqwest::header::AUTHORIZATION, access_token)
|
.header(reqwest::header::AUTHORIZATION, access_token)
|
||||||
@@ -57,7 +69,6 @@ impl RetrieveRecords {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn retrieve_url(&self) -> String {
|
fn retrieve_url(&self) -> String {
|
||||||
// let mut url: String = String::new();
|
|
||||||
let api = &self.api;
|
let api = &self.api;
|
||||||
let mut url: String = String::from(&api.url);
|
let mut url: String = String::from(&api.url);
|
||||||
url += &String::from("api/");
|
url += &String::from("api/");
|
||||||
@@ -65,7 +76,6 @@ impl RetrieveRecords {
|
|||||||
url += &String::from("/");
|
url += &String::from("/");
|
||||||
url += &String::from(&api.endpoint);
|
url += &String::from(&api.endpoint);
|
||||||
url += &String::from("/");
|
url += &String::from("/");
|
||||||
// url += &song.id.unwrap().to_string();
|
|
||||||
|
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user