get_status/
get_status.rs

1use eskom_se_push_api::{
2  constants::TOKEN_KEY,
3  get_token_from_env,
4  status::{EskomStatus, EskomStatusUrlBuilder},
5  ureq_client::handle_ureq_response,
6  Endpoint,
7};
8
9fn main() {
10  match get_token_from_env(None) {
11    Ok(val) => {
12      let api = EskomStatusUrlBuilder::default().build().unwrap();
13      // Need to import the Endpoint trait
14      let response = ureq::request(api.method(), api.url().unwrap().as_str())
15        .set(TOKEN_KEY, &val)
16        .call();
17      match handle_ureq_response::<EskomStatus>(response) {
18        Ok(status) => {
19          println!("{:?}", status);
20        }
21        Err(e) => {
22          eprintln!("Error: {}", e);
23        }
24      }
25    }
26    Err(e) => panic!("Environment variable error: {}", e),
27  }
28}