Add: Cmd performs a real api call \o/
This commit is contained in:
parent
2441d8c4a2
commit
15fd062258
20
src/cmd.rs
20
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user