UreqClient

Struct UreqClient 

Source
pub struct UreqClient { /* private fields */ }

Implementations§

Source§

impl UreqClient

Source

pub fn new(token: String) -> Self

Create new client using the ureq Http client token is the Eskom API token

Examples found in repository?
examples/ureq_client.rs (line 7)
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}
Source

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.

Source

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?
examples/ureq_client.rs (line 8)
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}
Source

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.

Source

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.

Search area based on text

Source

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

Source

pub fn check_allowance(&self) -> Result<AllowanceCheck, HttpError>

Check allowance allocated for token NOTE: This call doesn’t count towards your quota.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,