ring_client/client/api/location/
mod.rs

1mod 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/// A location in a Ring account.
14#[derive(Debug)]
15pub struct Location<'a> {
16    session: &'a Client,
17
18    /// Data about the location.
19    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/// Data about a location in a Ring account.
58#[derive(Debug, Deserialize)]
59pub struct LocationData {
60    #[serde(rename = "location_id")]
61    pub(crate) id: String,
62
63    /// The address of the location.
64    pub address: LocationAddress,
65
66    /// When the location was first created.
67    pub created_at: DateTime<Utc>,
68
69    /// Geographic coordinates of the location.
70    pub geo_coordinates: GeoCoordinates,
71
72    /// Whether the location's geographic coordinates are verified.
73    pub geo_service_verified: GeoServiceVerified,
74
75    /// Whether the location is a job site.
76    pub is_jobsite: bool,
77
78    /// Whether the location is being shared from a different account.
79    pub is_owner: bool,
80
81    /// The name of the location.
82    pub name: String,
83
84    /// The ID of the owner of the location.
85    pub owner_id: i32,
86
87    /// When the location was last updated.
88    pub updated_at: DateTime<Utc>,
89
90    /// Whether the user is verified.
91    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}