eskom_se_push_api/
area_info.rs

1use derive_builder::Builder;
2use serde::Deserialize;
3use serde::Serialize;
4
5use crate::errors::HttpError;
6use crate::traits::Endpoint;
7#[cfg(any(feature = "async", doc))]
8use crate::traits::EndpointAsync;
9
10/// The URL builder for the Allowance Check endpoint
11/// ```rust
12/// let t = AllowanceCheckURL::default()
13/// // returns the url for built the endpoint
14/// t.url().unwrap()
15/// ```
16#[derive(Default, Builder, Debug)]
17#[builder()]
18pub struct AreaInfoURL {
19  area_id: String,
20}
21
22impl Endpoint for AreaInfoURL {
23  type Output = AreaInfo;
24
25  fn endpoint(&self) -> std::borrow::Cow<'static, str> {
26    std::borrow::Cow::Borrowed("https://developer.sepush.co.za/business/2.0/area")
27  }
28
29  fn url(&self) -> Result<url::Url, crate::errors::HttpError> {
30    let mut u = url::Url::parse(&self.endpoint()).unwrap();
31    if self.area_id.trim().is_empty() {
32      Err(HttpError::AreaIdNotSet)
33    } else {
34      u.set_query(Some(format!("id={}", self.area_id).as_str()));
35      Ok(u)
36    }
37  }
38}
39#[cfg(any(feature = "async", doc))]
40impl EndpointAsync for AreaInfoURL {}
41
42#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
43#[serde(rename_all = "camelCase")]
44pub struct AreaInfo {
45  /// List of sorted events. Will be an empty list if not impacted
46  pub events: Vec<Event>,
47  /// Info of the region requested for
48  pub info: Info,
49  /// Raw loadshedding schedule, per stage (1-8)
50  /// `Note`: An empty list means no events for that stage
51  /// `Note`: Some Municipalities/Regions don't have Stage 5-8 schedules (and there will be 4 records instead of 8 in this list. Stage 5 upwards you can assume Stage 4 schedule impact.
52  pub schedule: Schedule,
53}
54
55#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
56#[serde(rename_all = "camelCase")]
57pub struct Event {
58  // TODO convert to Date
59  /// End time of the event eg `2022-08-08T22:30:00+02:00`
60  pub end: String,
61  // TODO convert to enum
62  /// The stage of the event eg `Stage 2`
63  pub note: String,
64  // TODO convert to Date
65  /// Start time of the event eg `2022-08-08T20:00:00+02:00`
66  pub start: String,
67}
68
69#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
70#[serde(rename_all = "camelCase")]
71pub struct Info {
72  pub name: String,
73  pub region: String,
74}
75
76#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
77#[serde(rename_all = "camelCase")]
78pub struct Schedule {
79  /// Vec of the days and there stages
80  pub days: Vec<Day>,
81  /// Where the data was retrieved from.
82  pub source: String,
83}
84
85#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
86#[serde(rename_all = "camelCase")]
87pub struct Day {
88  // TODO convert to Date
89  /// Date the stages are relevant to eg `2022-08-08`
90  pub date: String,
91  // TODO convert to enum
92  /// Day of week eg `Monday`
93  pub name: String,
94  /// Raw loadshedding schedule, per stage (1-8).
95  /// Index 0 refers to `Stage 1`, index 1 is `Stage 2` and so on and so forth.
96  /// Formatted for display purposes `(i.e. 20:00-22:30)`.
97  /// Any adjacent events have been merged into a single event `(e.g. 12:00-14:30 & 14:00-16:30 become 12:00-16:30)`.
98  ///  * `Note`: An empty list means no events for that stage
99  ///  * `Note`: Some Municipalities/Regions don't have Stage 5-8 schedules (and there will be 4 records instead of 8 in this list. Stage 5 upwards you can assume Stage 4 schedule impact.
100  pub stages: Vec<Vec<String>>,
101}