Language Migration #21
@@ -165,6 +165,34 @@ impl CommitManager {
|
||||
// TODO: Implement
|
||||
fn retrieve_object(&self) {
|
||||
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) {
|
||||
|
||||
@@ -19,13 +19,25 @@ impl Default for RetrieveRecords {
|
||||
|
||||
impl RetrieveRecords {
|
||||
pub async fn get_all_songs(
|
||||
&self,
|
||||
&mut self,
|
||||
token: &models::token::Token,
|
||||
) -> Result<Vec<models::song::Song>, Error> {
|
||||
self.api.endpoint = String::from("song");
|
||||
let mut songs: Vec<models::song::Song> = Vec::new();
|
||||
let url = self.retrieve_url();
|
||||
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
|
||||
.get(&url)
|
||||
.header(reqwest::header::AUTHORIZATION, access_token)
|
||||
@@ -57,7 +69,6 @@ impl RetrieveRecords {
|
||||
}
|
||||
|
||||
fn retrieve_url(&self) -> String {
|
||||
// let mut url: String = String::new();
|
||||
let api = &self.api;
|
||||
let mut url: String = String::from(&api.url);
|
||||
url += &String::from("api/");
|
||||
@@ -65,7 +76,6 @@ impl RetrieveRecords {
|
||||
url += &String::from("/");
|
||||
url += &String::from(&api.endpoint);
|
||||
url += &String::from("/");
|
||||
// url += &song.id.unwrap().to_string();
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user