Add: Cmd performs a real api call \o/

main
Óscar M. Lage 2021-11-14 14:56:09 +01:00
parent 2441d8c4a2
commit 15fd062258
1 changed files with 15 additions and 5 deletions

View File

@ -3,17 +3,27 @@ use std::path::PathBuf;
#[path = "./config.rs"]
mod config;
pub fn get_projects(config_file: &PathBuf) {
pub fn api_call(config_file: &PathBuf, endpoint: String) -> String {
// Config
let mut default_config = config::Config::default();
let config = default_config.parse(&config_file);
// Call api
println!("Call API, Config: {:?}", config);
let endpoint = format!("{}{}", &config.url, endpoint);
let client = reqwest::blocking::Client::new();
let res = client.get(endpoint)
.header("Authorization", &config.key)
.send();
// Return json result
let projects = String::from("we");
println!("{}", projects);
match res {
Ok(res) => return res.text().unwrap(),
Err(e) => panic!("Problem with endpoint: {:?}", e),
};
}
pub fn get_projects(config_file: &PathBuf) {
let projects_json = api_call(&config_file, String::from("stamps"));
println!("{:?}", projects_json);
}
pub fn get_tasks(config_file: &PathBuf, project: i32) {