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