Skip to main content

highlevel_api/apis/locations/
client.rs

1use std::sync::Arc;
2use crate::{error::Result, http::HttpClient};
3use super::types::*;
4
5pub struct LocationsApi {
6    http: Arc<HttpClient>,
7}
8
9impl LocationsApi {
10    pub fn new(http: Arc<HttpClient>) -> Self {
11        Self { http }
12    }
13
14    pub async fn get(&self, location_id: &str) -> Result<GetLocationResponse> {
15        self.http.get(&format!("/locations/{location_id}")).await
16    }
17
18    pub async fn search(&self, params: &SearchLocationsParams) -> Result<SearchLocationsResponse> {
19        self.http.get_with_query("/locations/search", params).await
20    }
21
22    pub async fn create(&self, params: &CreateLocationParams) -> Result<GetLocationResponse> {
23        self.http.post("/locations", params).await
24    }
25
26    pub async fn update(
27        &self,
28        location_id: &str,
29        params: &UpdateLocationParams,
30    ) -> Result<GetLocationResponse> {
31        self.http.put(&format!("/locations/{location_id}"), params).await
32    }
33
34    pub async fn delete(&self, location_id: &str) -> Result<DeleteLocationResponse> {
35        self.http.delete(&format!("/locations/{location_id}")).await
36    }
37
38    // ── Custom Fields ─────────────────────────────────────────────────────────
39
40    pub async fn get_custom_fields(
41        &self,
42        location_id: &str,
43    ) -> Result<GetCustomFieldsResponse> {
44        self.http
45            .get(&format!("/locations/{location_id}/customFields"))
46            .await
47    }
48
49    pub async fn get_custom_field(
50        &self,
51        location_id: &str,
52        field_id: &str,
53    ) -> Result<GetCustomFieldResponse> {
54        self.http
55            .get(&format!("/locations/{location_id}/customFields/{field_id}"))
56            .await
57    }
58
59    pub async fn create_custom_field(
60        &self,
61        location_id: &str,
62        params: &CreateCustomFieldParams,
63    ) -> Result<GetCustomFieldResponse> {
64        self.http
65            .post(&format!("/locations/{location_id}/customFields"), params)
66            .await
67    }
68
69    pub async fn update_custom_field(
70        &self,
71        location_id: &str,
72        field_id: &str,
73        params: &CreateCustomFieldParams,
74    ) -> Result<GetCustomFieldResponse> {
75        self.http
76            .put(
77                &format!("/locations/{location_id}/customFields/{field_id}"),
78                params,
79            )
80            .await
81    }
82
83    pub async fn delete_custom_field(
84        &self,
85        location_id: &str,
86        field_id: &str,
87    ) -> Result<()> {
88        self.http
89            .delete_no_content(&format!("/locations/{location_id}/customFields/{field_id}"))
90            .await
91    }
92
93    // ── Tags ─────────────────────────────────────────────────────────────────
94
95    pub async fn get_tags(&self, location_id: &str) -> Result<GetTagsResponse> {
96        self.http.get(&format!("/locations/{location_id}/tags")).await
97    }
98
99    pub async fn get_tag(&self, location_id: &str, tag_id: &str) -> Result<GetTagResponse> {
100        self.http
101            .get(&format!("/locations/{location_id}/tags/{tag_id}"))
102            .await
103    }
104
105    pub async fn create_tag(
106        &self,
107        location_id: &str,
108        params: &CreateTagParams,
109    ) -> Result<GetTagResponse> {
110        self.http.post(&format!("/locations/{location_id}/tags"), params).await
111    }
112
113    pub async fn update_tag(
114        &self,
115        location_id: &str,
116        tag_id: &str,
117        params: &CreateTagParams,
118    ) -> Result<GetTagResponse> {
119        self.http
120            .put(&format!("/locations/{location_id}/tags/{tag_id}"), params)
121            .await
122    }
123
124    pub async fn delete_tag(&self, location_id: &str, tag_id: &str) -> Result<()> {
125        self.http
126            .delete_no_content(&format!("/locations/{location_id}/tags/{tag_id}"))
127            .await
128    }
129}