ring_client/client/api/location/
mod.rs1mod event;
2
3use crate::client::Client;
4use crate::helper;
5use crate::helper::url::Url;
6use chrono::{DateTime, Utc};
7use serde::Deserialize;
8
9use crate::client::api::error::ApiError;
10use crate::client::{api::RingApi, authentication::Tokens};
11pub use event::*;
12
13#[derive(Debug)]
15pub struct Location<'a> {
16 session: &'a Client,
17
18 pub data: LocationData,
20}
21
22impl Location<'_> {
23 pub(crate) const fn new(session: &Client, data: LocationData) -> Location<'_> {
24 Location { session, data }
25 }
26}
27
28#[allow(missing_docs)]
29#[derive(Debug, Deserialize)]
30pub struct LocationAddress {
31 pub address1: String,
32 pub address2: String,
33 pub city: String,
34 pub country: String,
35 pub cross_street: String,
36 pub state: String,
37 pub timezone: String,
38 pub zip_code: String,
39}
40
41#[allow(missing_docs)]
42#[derive(Debug, Deserialize)]
43pub struct GeoCoordinates {
44 pub latitude: f64,
45 pub longitude: f64,
46}
47
48#[allow(missing_docs)]
49#[derive(Debug, Deserialize)]
50#[serde(rename_all = "snake_case")]
51pub enum GeoServiceVerified {
52 Verified,
53 Unverified,
54 AddressCoordinates,
55}
56
57#[derive(Debug, Deserialize)]
59pub struct LocationData {
60 #[serde(rename = "location_id")]
61 pub(crate) id: String,
62
63 pub address: LocationAddress,
65
66 pub created_at: DateTime<Utc>,
68
69 pub geo_coordinates: GeoCoordinates,
71
72 pub geo_service_verified: GeoServiceVerified,
74
75 pub is_jobsite: bool,
77
78 pub is_owner: bool,
80
81 pub name: String,
83
84 pub owner_id: i32,
86
87 pub updated_at: DateTime<Utc>,
89
90 pub user_verified: bool,
92}
93
94#[derive(Debug, Deserialize)]
95struct Response {
96 user_locations: Vec<LocationData>,
97}
98
99impl RingApi {
100 pub(crate) async fn get_location_data(
101 &self,
102 tokens: &Tokens,
103 ) -> Result<Vec<LocationData>, ApiError> {
104 Ok(self
105 .client
106 .get(helper::url::get_base_url(&Url::Locations))
107 .header("User-Agent", self.operating_system.get_user_agent())
108 .bearer_auth(&tokens.access_token)
109 .send()
110 .await?
111 .json::<Response>()
112 .await?
113 .user_locations)
114 }
115}