Add: Cmd performs a real api call \o/

This commit is contained in:
Óscar M. Lage 2021-11-14 14:56:09 +01:00
parent 2441d8c4a2
commit 15fd062258

View File

@ -3,17 +3,27 @@ use std::path::PathBuf;
#[path = "./config.rs"] #[path = "./config.rs"]
mod config; mod config;
pub fn get_projects(config_file: &PathBuf) { pub fn api_call(config_file: &PathBuf, endpoint: String) -> String {
// Config // Config
let mut default_config = config::Config::default(); let mut default_config = config::Config::default();
let config = default_config.parse(&config_file); let config = default_config.parse(&config_file);
// Call api // 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 match res {
let projects = String::from("we"); Ok(res) => return res.text().unwrap(),
println!("{}", projects); 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) { pub fn get_tasks(config_file: &PathBuf, project: i32) {