Skip to main content

ghl_sdk/services/
custom_fields.rs

1// @generated by xtask/generate_services.py — do not edit by hand.
2//! `custom-fields` — typed methods for all 8 API v2 operations
3//! in this module.
4//!
5//! Access via [`Ghl::custom_fields`](crate::Ghl::custom_fields).
6//!
7//! Request and response types come from [`ghl_models::v2::custom_fields`](https://docs.rs/ghl-models/latest/ghl_models/v2/custom_fields/); every endpoint is also documented in the
8//! [`custom-fields` API reference](https://github.com/Shahroz/ghl-rs/blob/main/docs/api/custom-fields.md).
9//!
10//! Enable with `features = ["custom-fields"]`.
11
12#![allow(clippy::too_many_arguments)]
13
14use crate::client::Ghl;
15use crate::error::Result;
16use ghl_models::v2::custom_fields as models;
17
18/// Typed access to the `custom-fields` API v2 surface (8 operations). Obtained via
19/// [`Ghl::custom_fields`](crate::Ghl::custom_fields).
20#[derive(Debug, Clone)]
21pub struct CustomFieldsService {
22    pub(crate) client: Ghl,
23}
24
25impl CustomFieldsService {
26    pub(crate) fn new(client: Ghl) -> Self {
27        Self { client }
28    }
29}
30
31/// Query parameters for [`CustomFieldsService::delete_custom_field_folder`].
32#[derive(Debug, Clone, Default)]
33pub struct DeleteCustomFieldFolderParams {
34    /// Location Id
35    /// Required by the API.
36    pub location_id: String,
37}
38
39impl DeleteCustomFieldFolderParams {
40    /// Start from the parameters the API requires.
41    pub fn new(location_id: impl Into<String>) -> Self {
42        Self {
43            location_id: location_id.into(),
44        }
45    }
46
47    fn to_query(&self) -> Vec<(String, String)> {
48        let q: Vec<(String, String)> = vec![("locationId".into(), self.location_id.clone())];
49        q
50    }
51}
52
53/// Query parameters for [`CustomFieldsService::get_custom_fields_by_object_key`].
54#[derive(Debug, Clone, Default)]
55pub struct GetCustomFieldsByObjectKeyParams {
56    /// `locationId` query parameter.
57    /// Required by the API.
58    pub location_id: String,
59}
60
61impl GetCustomFieldsByObjectKeyParams {
62    /// Start from the parameters the API requires.
63    pub fn new(location_id: impl Into<String>) -> Self {
64        Self {
65            location_id: location_id.into(),
66        }
67    }
68
69    fn to_query(&self) -> Vec<(String, String)> {
70        let q: Vec<(String, String)> = vec![("locationId".into(), self.location_id.clone())];
71        q
72    }
73}
74
75impl CustomFieldsService {
76    /// Create Custom Field
77    ///
78    /// Create Custom Field ! Only supports Custom Objects and Company (Business) today.
79    /// Will be extended to other Standard Objects in the future.
80    ///
81    /// `POST /custom-fields/`
82    ///
83    /// Requires scope: `locations/customFields.write`.
84    pub async fn create_custom_field(
85        &self,
86        body: &models::CreateCustomFieldsDTO,
87    ) -> Result<models::CustomFieldSuccessfulResponseDto> {
88        let query = Vec::new();
89        self.client
90            .send_versioned(
91                reqwest::Method::POST,
92                "/custom-fields/",
93                &query,
94                Some(body),
95                Some("2021-07-28"),
96            )
97            .await
98    }
99
100    /// Create Custom Field Folder
101    ///
102    /// Create Custom Field Folder ! Only supports Custom Objects and Company (Business)
103    /// today. Will be extended to other Standard Objects in the future.
104    ///
105    /// `POST /custom-fields/folder`
106    ///
107    /// Requires scope: `locations/customFields.write`.
108    pub async fn create_custom_field_folder(
109        &self,
110        body: &models::CreateFolder,
111    ) -> Result<models::ICustomFieldFolder> {
112        let query = Vec::new();
113        self.client
114            .send_versioned(
115                reqwest::Method::POST,
116                "/custom-fields/folder",
117                &query,
118                Some(body),
119                Some("2021-07-28"),
120            )
121            .await
122    }
123
124    /// Delete Custom Field Folder
125    ///
126    /// Create Custom Field Folder ! Only supports Custom Objects and Company (Business)
127    /// today. Will be extended to other Standard Objects in the future.
128    ///
129    /// `DELETE /custom-fields/folder/{id}`
130    ///
131    /// Requires scope: `locations/customFields.write`.
132    pub async fn delete_custom_field_folder(
133        &self,
134        id: &str,
135        params: &DeleteCustomFieldFolderParams,
136    ) -> Result<models::CustomFolderDeleteResponseDto> {
137        let path = format!("/custom-fields/folder/{}", crate::services::encode(id));
138        let query = params.to_query();
139        self.client
140            .send_versioned(
141                reqwest::Method::DELETE,
142                &path,
143                &query,
144                None::<&()>,
145                Some("2021-07-28"),
146            )
147            .await
148    }
149
150    /// Update Custom Field Folder Name
151    ///
152    /// Create Custom Field Folder ! Only supports Custom Objects and Company (Business)
153    /// today. Will be extended to other Standard Objects in the future.
154    ///
155    /// `PUT /custom-fields/folder/{id}`
156    ///
157    /// Requires scope: `locations/customFields.write`.
158    pub async fn update_custom_field_folder_name(
159        &self,
160        id: &str,
161        body: &models::UpdateFolder,
162    ) -> Result<models::ICustomFieldFolder> {
163        let path = format!("/custom-fields/folder/{}", crate::services::encode(id));
164        let query = Vec::new();
165        self.client
166            .send_versioned(
167                reqwest::Method::PUT,
168                &path,
169                &query,
170                Some(body),
171                Some("2021-07-28"),
172            )
173            .await
174    }
175
176    /// Get Custom Fields By Object Key
177    ///
178    /// Get Custom Fields By Object Key ! Only supports Custom Objects and Company
179    /// (Business) today. Will be extended to other Standard Objects in the future.
180    ///
181    /// `GET /custom-fields/object-key/{objectKey}`
182    ///
183    /// Requires scope: `locations/customFields.readonly`.
184    pub async fn get_custom_fields_by_object_key(
185        &self,
186        object_key: &str,
187        params: &GetCustomFieldsByObjectKeyParams,
188    ) -> Result<models::CustomFieldsResponseDTO> {
189        let path = format!(
190            "/custom-fields/object-key/{}",
191            crate::services::encode(object_key)
192        );
193        let query = params.to_query();
194        self.client
195            .send_versioned(
196                reqwest::Method::GET,
197                &path,
198                &query,
199                None::<&()>,
200                Some("2021-07-28"),
201            )
202            .await
203    }
204
205    /// Delete Custom Field By Id
206    ///
207    /// Delete Custom Field By Id ! Only supports Custom Objects and Company (Business)
208    /// today. Will be extended to other Standard Objects in the future.
209    ///
210    /// `DELETE /custom-fields/{id}`
211    ///
212    /// Requires scope: `locations/customFields.write`.
213    pub async fn delete_custom_field_by_id(
214        &self,
215        id: &str,
216    ) -> Result<models::CustomFolderDeleteResponseDto> {
217        let path = format!("/custom-fields/{}", crate::services::encode(id));
218        let query = Vec::new();
219        self.client
220            .send_versioned(
221                reqwest::Method::DELETE,
222                &path,
223                &query,
224                None::<&()>,
225                Some("2021-07-28"),
226            )
227            .await
228    }
229
230    /// Get Custom Field / Folder By Id
231    ///
232    /// Get Custom Field / Folder By Id. ! Only supports Custom Objects and Company
233    /// (Business) today. Will be extended to other Standard Objects in the future.
234    ///
235    /// `GET /custom-fields/{id}`
236    ///
237    /// Requires scope: `locations/customFields.readonly`.
238    pub async fn get_custom_field_folder_by_id(
239        &self,
240        id: &str,
241    ) -> Result<models::CustomFieldSuccessfulResponseDto> {
242        let path = format!("/custom-fields/{}", crate::services::encode(id));
243        let query = Vec::new();
244        self.client
245            .send_versioned(
246                reqwest::Method::GET,
247                &path,
248                &query,
249                None::<&()>,
250                Some("2021-07-28"),
251            )
252            .await
253    }
254
255    /// Update Custom Field By Id
256    ///
257    /// Update Custom Field By Id ! Only supports Custom Objects and Company (Business)
258    /// today. Will be extended to other Standard Objects in the future.
259    ///
260    /// `PUT /custom-fields/{id}`
261    ///
262    /// Requires scope: `locations/customFields.write`.
263    pub async fn update_custom_field_by_id(
264        &self,
265        id: &str,
266        body: &models::UpdateCustomFieldsDTO,
267    ) -> Result<models::CustomFieldSuccessfulResponseDto> {
268        let path = format!("/custom-fields/{}", crate::services::encode(id));
269        let query = Vec::new();
270        self.client
271            .send_versioned(
272                reqwest::Method::PUT,
273                &path,
274                &query,
275                Some(body),
276                Some("2021-07-28"),
277            )
278            .await
279    }
280}