ghl_sdk/services/objects.rs
1// @generated by xtask/generate_services.py — do not edit by hand.
2//! `objects` — typed methods for all 9 API v2 operations
3//! in this module.
4//!
5//! Access via [`Ghl::objects`](crate::Ghl::objects).
6//!
7//! Request and response types come from [`ghl_models::v2::objects`](https://docs.rs/ghl-models/latest/ghl_models/v2/objects/); every endpoint is also documented in the
8//! [`objects` API reference](https://github.com/Shahroz/ghl-rs/blob/main/docs/api/objects.md).
9//!
10//! Enable with `features = ["objects"]`.
11
12#![allow(clippy::too_many_arguments)]
13
14use crate::client::Ghl;
15use crate::error::Result;
16use ghl_models::v2::objects as models;
17
18/// Typed access to the `objects` API v2 surface (9 operations). Obtained via
19/// [`Ghl::objects`](crate::Ghl::objects).
20#[derive(Debug, Clone)]
21pub struct ObjectsService {
22 pub(crate) client: Ghl,
23}
24
25impl ObjectsService {
26 pub(crate) fn new(client: Ghl) -> Self {
27 Self { client }
28 }
29}
30
31/// Query parameters for [`ObjectsService::get_all_objects_for_a_location`].
32#[derive(Debug, Clone, Default)]
33pub struct GetAllObjectsForALocationParams {
34 /// location id
35 /// Required by the API.
36 pub location_id: String,
37}
38
39impl GetAllObjectsForALocationParams {
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 [`ObjectsService::get_object_schema_by_key_id`].
54#[derive(Debug, Clone, Default)]
55pub struct GetObjectSchemaByKeyIdParams {
56 /// location id of the sub account
57 /// Required by the API.
58 pub location_id: String,
59 /// Fetch Properties , Fetches all the standard / custom fields of the object when set
60 /// to true
61 pub fetch_properties: Option<String>,
62}
63
64impl GetObjectSchemaByKeyIdParams {
65 /// Start from the parameters the API requires.
66 pub fn new(location_id: impl Into<String>) -> Self {
67 Self {
68 location_id: location_id.into(),
69 ..Default::default()
70 }
71 }
72
73 /// Fetch Properties , Fetches all the standard / custom fields of the object when set
74 /// to true
75 pub fn fetch_properties(mut self, v: impl Into<String>) -> Self {
76 self.fetch_properties = Some(v.into());
77 self
78 }
79
80 fn to_query(&self) -> Vec<(String, String)> {
81 let mut q: Vec<(String, String)> = vec![("locationId".into(), self.location_id.clone())];
82 if let Some(v) = &self.fetch_properties {
83 q.push(("fetchProperties".into(), v.to_string()));
84 }
85 q
86 }
87}
88
89/// Query parameters for [`ObjectsService::update_record`].
90#[derive(Debug, Clone, Default)]
91pub struct UpdateRecordParams {
92 /// `locationId` query parameter.
93 /// Required by the API.
94 pub location_id: String,
95}
96
97impl UpdateRecordParams {
98 /// Start from the parameters the API requires.
99 pub fn new(location_id: impl Into<String>) -> Self {
100 Self {
101 location_id: location_id.into(),
102 }
103 }
104
105 fn to_query(&self) -> Vec<(String, String)> {
106 let q: Vec<(String, String)> = vec![("locationId".into(), self.location_id.clone())];
107 q
108 }
109}
110
111impl ObjectsService {
112 /// Get all objects for a location
113 ///
114 /// Get all objects for a location. Supported Objects are contact, opportunity, business
115 /// and custom objects.To understand objects and records, please have a look at the
116 /// documentation here :
117 /// <https://doc.clickup.com/8631005/d/h/87cpx-277156/93bf0c2e23177b0>
118 ///
119 /// `GET /objects/`
120 ///
121 /// Requires scope: `objects/schema.readonly`.
122 pub async fn get_all_objects_for_a_location(
123 &self,
124 params: &GetAllObjectsForALocationParams,
125 ) -> Result<models::CustomObjectListResponseDTO> {
126 let query = params.to_query();
127 self.client
128 .send_versioned(
129 reqwest::Method::GET,
130 "/objects/",
131 &query,
132 None::<&()>,
133 Some("2021-07-28"),
134 )
135 .await
136 }
137
138 /// Create Custom Object
139 ///
140 /// Allows you to create a custom object schema. To understand objects and records,
141 /// please have a look at the documentation here :
142 /// <https://doc.clickup.com/8631005/d/h/87cpx-277156/93bf0c2e23177b0>
143 ///
144 /// `POST /objects/`
145 ///
146 /// Requires scope: `objects/schema.write`.
147 pub async fn create_custom_object(
148 &self,
149 body: &models::CreateCustomObjectSchemaDTO,
150 ) -> Result<models::CustomObjectResponseDTO> {
151 let query = Vec::new();
152 self.client
153 .send_versioned(
154 reqwest::Method::POST,
155 "/objects/",
156 &query,
157 Some(body),
158 Some("2021-07-28"),
159 )
160 .await
161 }
162
163 /// Get Object Schema by key / id
164 ///
165 /// Retrieve Object Schema by key or ID. This will return the schema of the custom
166 /// object, including all its fields and properties. Supported objects include contact,
167 /// opportunity, business and custom objects.To understand objects and records, please
168 /// have a look the documentation here :
169 /// <https://doc.clickup.com/8631005/d/h/87cpx-277156/93bf0c2e23177b0>
170 ///
171 /// `GET /objects/{key}`
172 ///
173 /// Requires scope: `objects/schema.readonly`.
174 pub async fn get_object_schema_by_key_id(
175 &self,
176 key: &str,
177 params: &GetObjectSchemaByKeyIdParams,
178 ) -> Result<models::CustomObjectByIdResponseDTO> {
179 let path = format!("/objects/{}", crate::services::encode(key));
180 let query = params.to_query();
181 self.client
182 .send_versioned(
183 reqwest::Method::GET,
184 &path,
185 &query,
186 None::<&()>,
187 Some("2021-07-28"),
188 )
189 .await
190 }
191
192 /// Update Object Schema By Key / Id
193 ///
194 /// Update Custom Object Schema or standard object's like contact, opportunity, business
195 /// searchable fields. To understand objects and records, please have a look at the
196 /// documentation here :
197 /// <https://doc.clickup.com/8631005/d/h/87cpx-277156/93bf0c2e23177b0>
198 ///
199 /// `PUT /objects/{key}`
200 ///
201 /// Requires scope: `objects/schema.write`.
202 pub async fn update_object_schema_by_key_id(
203 &self,
204 key: &str,
205 body: &models::UpdateCustomObjectSchemaDTO,
206 ) -> Result<models::CustomObjectResponseDTO> {
207 let path = format!("/objects/{}", crate::services::encode(key));
208 let query = Vec::new();
209 self.client
210 .send_versioned(
211 reqwest::Method::PUT,
212 &path,
213 &query,
214 Some(body),
215 Some("2021-07-28"),
216 )
217 .await
218 }
219
220 /// Create Record
221 ///
222 /// Create a Custom Object Record. Supported Objects business and custom objects.
223 /// Documentation Link -
224 /// <https://doc.clickup.com/8631005/d/h/87cpx-277156/93bf0c2e23177b0/87cpx-376296>
225 ///
226 /// `POST /objects/{schemaKey}/records`
227 ///
228 /// Requires scope: `objects/record.write`.
229 pub async fn create_record(
230 &self,
231 schema_key: &str,
232 body: &models::CreateCustomObjectRecordDto,
233 ) -> Result<models::RecordByIdResponseDTO> {
234 let path = format!("/objects/{}/records", crate::services::encode(schema_key));
235 let query = Vec::new();
236 self.client
237 .send_versioned(
238 reqwest::Method::POST,
239 &path,
240 &query,
241 Some(body),
242 Some("2021-07-28"),
243 )
244 .await
245 }
246
247 /// Search Object Records
248 ///
249 /// Supported Objects are custom objects and standard objects like "business".
250 /// Documentation Link -
251 /// <https://doc.clickup.com/8631005/d/h/87cpx-277156/93bf0c2e23177b0/87cpx-379336>
252 ///
253 /// `POST /objects/{schemaKey}/records/search`
254 ///
255 /// Requires scope: `objects/record.readonly`.
256 pub async fn search_object_records(
257 &self,
258 schema_key: &str,
259 body: &models::SearchRecordsBody,
260 ) -> Result<models::SearchRecordResponseDTO> {
261 let path = format!(
262 "/objects/{}/records/search",
263 crate::services::encode(schema_key)
264 );
265 let query = Vec::new();
266 self.client
267 .send_versioned(
268 reqwest::Method::POST,
269 &path,
270 &query,
271 Some(body),
272 Some("2021-07-28"),
273 )
274 .await
275 }
276
277 /// Delete Record
278 ///
279 /// Delete Record By Id . Supported Objects are business and custom objects.
280 ///
281 /// `DELETE /objects/{schemaKey}/records/{id}`
282 pub async fn delete_record(
283 &self,
284 schema_key: &str,
285 id: &str,
286 ) -> Result<models::ObjectRecordDeleteResponseDTO> {
287 let path = format!(
288 "/objects/{}/records/{}",
289 crate::services::encode(schema_key),
290 crate::services::encode(id)
291 );
292 let query = Vec::new();
293 self.client
294 .send_versioned(
295 reqwest::Method::DELETE,
296 &path,
297 &query,
298 None::<&()>,
299 Some("2021-07-28"),
300 )
301 .await
302 }
303
304 /// Get Record By Id
305 ///
306 /// Allows you to get a Standard Object like business and custom object record by Id
307 ///
308 /// `GET /objects/{schemaKey}/records/{id}`
309 pub async fn get_record_by_id(
310 &self,
311 schema_key: &str,
312 id: &str,
313 ) -> Result<models::RecordByIdResponseDTO> {
314 let path = format!(
315 "/objects/{}/records/{}",
316 crate::services::encode(schema_key),
317 crate::services::encode(id)
318 );
319 let query = Vec::new();
320 self.client
321 .send_versioned(
322 reqwest::Method::GET,
323 &path,
324 &query,
325 None::<&()>,
326 Some("2021-07-28"),
327 )
328 .await
329 }
330
331 /// Update Record
332 ///
333 /// Update a Custom Object Record by Id. Supported Objects are business and custom
334 /// objects. Documentation Link -
335 /// <https://doc.clickup.com/8631005/d/h/87cpx-277156/93bf0c2e23177b0/87cpx-376296>
336 ///
337 /// `PUT /objects/{schemaKey}/records/{id}`
338 pub async fn update_record(
339 &self,
340 schema_key: &str,
341 id: &str,
342 params: &UpdateRecordParams,
343 body: &models::UpdateCustomObjectRecordDto,
344 ) -> Result<models::RecordByIdResponseDTO> {
345 let path = format!(
346 "/objects/{}/records/{}",
347 crate::services::encode(schema_key),
348 crate::services::encode(id)
349 );
350 let query = params.to_query();
351 self.client
352 .send_versioned(
353 reqwest::Method::PUT,
354 &path,
355 &query,
356 Some(body),
357 Some("2021-07-28"),
358 )
359 .await
360 }
361}