Language Migration #21

Merged
kdeng00 merged 47 commits from rust-lg into master 2024-06-15 12:22:18 -04:00
2 changed files with 42 additions and 4 deletions
Showing only changes of commit 9a13ac2776 - Show all commits
+28
View File
@@ -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) {
+14 -4
View File
@@ -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;
}