Expand description

Eskom-se-Push API

The library is an unofficial lib and is not maintained by the API developers.

This library is an API binding to the EskomSePush API.

It does have a few small helper functions to assist.

To get up and running, you can either pass in the API key or use environment variables.

API key as a variable

use eskom_se_push_api::EskomAPI;

fn main() {
  let api = EskomAPI::new("XXXXXXXXXXXXXXXXXXXXXXXXX");
  let resp = api.check_allowance();
  match resp {
    Ok(allowance) => {
      println!(
        "You have made {} API calls today",
        allowance.allowance.count
      );
    }
    Err(e) => {
      eprintln!("Error: {}", e);
    }
  }
}

API key as an env variable

The default env variable is ESKOMSEPUSH_API_KEY

use eskom_se_push_api::EskomAPI;

fn main() {
  let api = EskomAPI::new_with_env(None);
  let resp = api.check_allowance();
  match resp {
    Ok(allowance) => {
      println!(
        "You have made {} API calls today",
        allowance.allowance.count
      );
    }
    Err(e) => {
      eprintln!("Error: {}", e);
    }
  }
}

//!

API key as an custom env variable

Able to use custom env keys such as MY_CUSTOM_KEY

use eskom_se_push_api::EskomAPI;

fn main() {
  let api = EskomAPI::new_with_env(Some("MY_CUSTOM_KEY"));
  let resp = api.check_allowance();
  match resp {
    Ok(allowance) => {
      println!(
        "You have made {} API calls today",
        allowance.allowance.count
      );
    }
    Err(e) => {
      eprintln!("Error: {}", e);
    }
  }
}

Features

There are currently 4 features but some are used in combinations to enable certain functionality

  • reqwest and async: Adds an async reqwest client and response handler

  • reqwest and sync: Adds a blocking reqwest client and response handler

  • ureq: Adds a ureq client and response handler

None of the features are added by default

Modules

An async client using the reqwest http client.
A blocking client using the reqwest http client.
A blocking client using the ureq http client.

Traits

Functions