eskom_se_push_api/
topics_nearby.rs1use 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#[derive(Default, Builder, Debug)]
11#[builder(setter(into))]
12pub struct TopicsNearbyUrl {
13 latitude: f32,
14 longitude: f32,
15}
16
17impl Endpoint for TopicsNearbyUrl {
18 type Output = TopicsNearby;
19
20 fn endpoint(&self) -> std::borrow::Cow<'static, str> {
21 std::borrow::Cow::Borrowed("https://developer.sepush.co.za/business/2.0/topics_nearby")
22 }
23
24 fn url(&self) -> Result<url::Url, crate::errors::HttpError> {
25 let mut u = url::Url::parse(&self.endpoint()).unwrap();
26 if self.latitude == 0. || self.longitude == 0. {
27 Err(HttpError::LongitudeOrLatitudeNotSet {
28 longitude: self.longitude,
29 latitude: self.latitude,
30 })
31 } else {
32 u.set_query(Some(format!("lat={}", self.latitude).as_str()));
33 u.set_query(Some(format!("long={}", self.longitude).as_str()));
34 Ok(u)
35 }
36 }
37}
38
39#[cfg(any(feature = "async", doc))]
40impl EndpointAsync for TopicsNearbyUrl {}
41
42#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
43#[serde(rename_all = "camelCase")]
44pub struct TopicsNearby {
45 pub topics: Vec<Topic>,
47}
48
49#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
50#[serde(rename_all = "camelCase")]
51pub struct Topic {
52 pub active: String,
53 pub body: String,
54 pub category: String,
55 pub distance: f64,
56 pub followers: i64,
57 pub timestamp: String,
58}