diff --git a/src/cmd.rs b/src/cmd.rs index 8384cf2..96421b5 100644 --- a/src/cmd.rs +++ b/src/cmd.rs @@ -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) {