pub struct UreqClient { /* private fields */ }Implementations§
Source§impl UreqClient
impl UreqClient
Sourcepub fn new(token: String) -> Self
pub fn new(token: String) -> Self
Create new client using the ureq Http client
token is the Eskom API token
Examples found in repository?
4fn main() {
5 match get_token_from_env(None) {
6 Ok(val) => {
7 let api = UreqClient::new(val);
8 match api.get_load_shedding_status() {
9 Ok(status) => {
10 println!("{:?}", status);
11 }
12 Err(e) => {
13 eprintln!("Error: {}", e);
14 }
15 }
16 }
17 Err(e) => panic!("Environment variable error: {}", e),
18 }
19}Sourcepub fn new_with_env(var_name: Option<&str>) -> Self
pub fn new_with_env(var_name: Option<&str>) -> Self
Creates new instance of Eskom API using token as a env variable.
Uses the dotenv crate so it will load .env files if available.
Note: The default variable name is ESKOMSEPUSH_API_KEY if var_name is set to None.
Note: It will panic the env variable doesn’t exist.
Sourcepub fn get_load_shedding_status(&self) -> Result<EskomStatus, HttpError>
pub fn get_load_shedding_status(&self) -> Result<EskomStatus, HttpError>
The current and next loadshedding statuses for South Africa and (Optional) municipal overrides
eskom is the National status
Other keys in the status refer to different municipalities and potential overrides from the National status; most typically present is the key for capetown
Examples found in repository?
4fn main() {
5 match get_token_from_env(None) {
6 Ok(val) => {
7 let api = UreqClient::new(val);
8 match api.get_load_shedding_status() {
9 Ok(status) => {
10 println!("{:?}", status);
11 }
12 Err(e) => {
13 eprintln!("Error: {}", e);
14 }
15 }
16 }
17 Err(e) => panic!("Environment variable error: {}", e),
18 }
19}Sourcepub fn get_area_info(&self, area_id: &str) -> Result<AreaInfo, HttpError>
pub fn get_area_info(&self, area_id: &str) -> Result<AreaInfo, HttpError>
Obtain the area_id from Area Find or Area Search and use with this request. This single request has everything you need to monitor upcoming loadshedding events for the chosen suburb.
Sourcepub fn areas_nearby(&self, lat: f32, long: f32) -> Result<AreaNearby, HttpError>
pub fn areas_nearby(&self, lat: f32, long: f32) -> Result<AreaNearby, HttpError>
Find areas based on GPS coordinates (latitude and longitude). The first area returned is typically the best choice for the coordinates - as it’s closest to the GPS coordinates provided. However it could be that you are in the second or third area.
Sourcepub fn areas_search(&self, search_term: &str) -> Result<AreaSearch, HttpError>
pub fn areas_search(&self, search_term: &str) -> Result<AreaSearch, HttpError>
Search area based on text
Sourcepub fn topics_nearby(
&self,
lat: f32,
long: f32,
) -> Result<TopicsNearby, HttpError>
pub fn topics_nearby( &self, lat: f32, long: f32, ) -> Result<TopicsNearby, HttpError>
Find topics created by users based on GPS coordinates (latitude and longitude). Can use this to detect if there is a potential outage/problem nearby
Sourcepub fn check_allowance(&self) -> Result<AllowanceCheck, HttpError>
pub fn check_allowance(&self) -> Result<AllowanceCheck, HttpError>
Check allowance allocated for token
NOTE: This call doesn’t count towards your quota.