eskom_se_push_api/lib.rs
1//! # Eskom-se-Push API
2//!
3//! The library is an unofficial lib and is not maintained by the API developers.
4//!
5//! This library is an API binding to the [EskomSePush](https://sepush.co.za) API.
6//!
7//! It does have a few small helper functions to assist.
8//!
9//! To get up and running, you can either pass in the API key or use environment variables.
10//!
11//! ## API key as a variable
12//!
13//! ```rust
14//! use eskom_se_push_api::EskomAPI;
15//!
16//! fn main() {
17//! let api = EskomAPI::new("XXXXXXXXXXXXXXXXXXXXXXXXX");
18//! let resp = api.check_allowance();
19//! match resp {
20//! Ok(allowance) => {
21//! println!(
22//! "You have made {} API calls today",
23//! allowance.allowance.count
24//! );
25//! }
26//! Err(e) => {
27//! eprintln!("Error: {}", e);
28//! }
29//! }
30//! }
31//! ```
32//!
33//! ## API key as an env variable
34//!
35//! The default env variable is `ESKOMSEPUSH_API_KEY`
36//! ```rust
37//! use eskom_se_push_api::EskomAPI;
38//!
39//! fn main() {
40//! let api = EskomAPI::new_with_env(None);
41//! let resp = api.check_allowance();
42//! match resp {
43//! Ok(allowance) => {
44//! println!(
45//! "You have made {} API calls today",
46//! allowance.allowance.count
47//! );
48//! }
49//! Err(e) => {
50//! eprintln!("Error: {}", e);
51//! }
52//! }
53//! }
54//! ```
55//!
56//! //!
57//! ## API key as an custom env variable
58//!
59//! Able to use custom env keys such as `MY_CUSTOM_KEY`
60//! ```rust
61//! use eskom_se_push_api::EskomAPI;
62//!
63//! fn main() {
64//! let api = EskomAPI::new_with_env(Some("MY_CUSTOM_KEY"));
65//! let resp = api.check_allowance();
66//! match resp {
67//! Ok(allowance) => {
68//! println!(
69//! "You have made {} API calls today",
70//! allowance.allowance.count
71//! );
72//! }
73//! Err(e) => {
74//! eprintln!("Error: {}", e);
75//! }
76//! }
77//! }
78//! ```
79//!
80//! ## Features
81//!
82//! There are currently 4 features but some are used in combinations to enable certain functionality
83//!
84//! * `reqwest` and `async`: Adds an async reqwest client and response handler
85//!
86//! * `reqwest` and `sync`: Adds a blocking reqwest client and response handler
87//!
88//! * `ureq`: Adds a ureq client and response handler
89//!
90//! None of the features are added by default
91
92pub use traits::Endpoint;
93#[cfg(any(feature = "async", doc))]
94pub use traits::EndpointAsync;
95extern crate thiserror;
96
97pub mod allowance;
98pub mod area_info;
99pub mod area_nearby;
100pub mod area_search;
101pub mod constants;
102pub mod errors;
103#[cfg(any(all(feature = "async", feature = "reqwest"), doc))]
104pub mod reqwest_async_client;
105#[cfg(any(all(feature = "sync", feature = "reqwest"), doc))]
106pub mod reqwest_blocking_client;
107pub mod status;
108pub mod topics_nearby;
109mod traits;
110#[cfg(any(feature = "ureq", doc))]
111pub mod ureq_client;
112
113pub fn get_token_from_env(var_name: Option<&str>) -> Result<String, std::env::VarError> {
114 dotenv::dotenv().ok();
115 let key = var_name.unwrap_or("ESKOMSEPUSH_API_KEY");
116 std::env::var(key)
117}
118
119#[cfg(test)]
120mod tests {
121 // use super::*;
122
123 #[test]
124 fn it_works() {
125 // let result = add(2, 2);
126 // assert_eq!(result, 4);
127 }
128}