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.
//! `forms` — typed methods for all 3 API v3 operations
//! in this module.
//!
//! Access via [`Ghl::v3`](crate::Ghl::v3)`().forms()`. These endpoints send `Version: v3`.
//!
//! Request and response types come from [`ghl_models::v3::forms`](https://docs.rs/ghl-models/latest/ghl_models/v3/forms/); every endpoint is also documented in the
//! [`forms` API reference](https://github.com/Shahroz/ghl-rs/blob/main/docs/api/forms.md).
//!
//! Enable with `features = ["forms"]`.
#![allow(clippy::too_many_arguments)]
use crate::client::Ghl;
use crate::error::Result;
use ghl_models::v3::forms as models;
/// Typed access to the `forms` API v3 surface (3 operations). Obtained via
/// [`Ghl::v3`](crate::Ghl::v3)`().forms()`.
#[derive(Debug, Clone)]
pub struct FormsService {
pub(crate) client: Ghl,
}
impl FormsService {
pub(crate) fn new(client: Ghl) -> Self {
Self { client }
}
}
/// Query parameters for [`FormsService::get_forms`].
#[derive(Debug, Clone, Default)]
pub struct GetFormsParams {
/// `locationId` query parameter.
/// Required by the API.
pub location_id: String,
/// `skip` query parameter.
pub skip: Option<f64>,
/// Limit Per Page records count. will allow maximum up to 50 and default will be 10
pub limit: Option<f64>,
/// `type` query parameter.
pub type_: Option<String>,
}
impl GetFormsParams {
/// Start from the parameters the API requires.
pub fn new(location_id: impl Into<String>) -> Self {
Self {
location_id: location_id.into(),
..Default::default()
}
}
/// Set the `skip` query parameter.
pub fn skip(mut self, v: f64) -> Self {
self.skip = Some(v);
self
}
/// Limit Per Page records count. will allow maximum up to 50 and default will be 10
pub fn limit(mut self, v: f64) -> Self {
self.limit = Some(v);
self
}
/// Set the `type` query parameter.
pub fn type_(mut self, v: impl Into<String>) -> Self {
self.type_ = Some(v.into());
self
}
fn to_query(&self) -> Vec<(String, String)> {
let mut q: Vec<(String, String)> = vec![("locationId".into(), self.location_id.clone())];
if let Some(v) = &self.skip {
q.push(("skip".into(), v.to_string()));
}
if let Some(v) = &self.limit {
q.push(("limit".into(), v.to_string()));
}
if let Some(v) = &self.type_ {
q.push(("type".into(), v.to_string()));
}
q
}
}
/// Query parameters for [`FormsService::get_forms_submissions`].
#[derive(Debug, Clone, Default)]
pub struct GetFormsSubmissionsParams {
/// `locationId` query parameter.
/// Required by the API.
pub location_id: String,
/// Page No. By default it will be 1
pub page: Option<f64>,
/// Limit Per Page records count. will allow maximum up to 100 and default will be 20
pub limit: Option<f64>,
/// Filter submission by form id
pub form_id: Option<String>,
/// Filter by contactId, name, email or phone no.
pub q: Option<String>,
/// Get submission by starting of this date. By default it will be same date of last
/// month(YYYY-MM-DD).
pub start_at: Option<String>,
/// Get submission by ending of this date. By default it will be current
/// date(YYYY-MM-DD).
pub end_at: Option<String>,
}
impl GetFormsSubmissionsParams {
/// Start from the parameters the API requires.
pub fn new(location_id: impl Into<String>) -> Self {
Self {
location_id: location_id.into(),
..Default::default()
}
}
/// Page No. By default it will be 1
pub fn page(mut self, v: f64) -> Self {
self.page = Some(v);
self
}
/// Limit Per Page records count. will allow maximum up to 100 and default will be 20
pub fn limit(mut self, v: f64) -> Self {
self.limit = Some(v);
self
}
/// Filter submission by form id
pub fn form_id(mut self, v: impl Into<String>) -> Self {
self.form_id = Some(v.into());
self
}
/// Filter by contactId, name, email or phone no.
pub fn q(mut self, v: impl Into<String>) -> Self {
self.q = Some(v.into());
self
}
/// Get submission by starting of this date. By default it will be same date of last
/// month(YYYY-MM-DD).
pub fn start_at(mut self, v: impl Into<String>) -> Self {
self.start_at = Some(v.into());
self
}
/// Get submission by ending of this date. By default it will be current
/// date(YYYY-MM-DD).
pub fn end_at(mut self, v: impl Into<String>) -> Self {
self.end_at = Some(v.into());
self
}
fn to_query(&self) -> Vec<(String, String)> {
let mut q: Vec<(String, String)> = vec![("locationId".into(), self.location_id.clone())];
if let Some(v) = &self.page {
q.push(("page".into(), v.to_string()));
}
if let Some(v) = &self.limit {
q.push(("limit".into(), v.to_string()));
}
if let Some(v) = &self.form_id {
q.push(("formId".into(), v.to_string()));
}
if let Some(v) = &self.q {
q.push(("q".into(), v.to_string()));
}
if let Some(v) = &self.start_at {
q.push(("startAt".into(), v.to_string()));
}
if let Some(v) = &self.end_at {
q.push(("endAt".into(), v.to_string()));
}
q
}
}
/// Query parameters for [`FormsService::upload_files_to_custom_fields`].
#[derive(Debug, Clone, Default)]
pub struct UploadFilesToCustomFieldsParams {
/// Contact ID to upload the file to.
/// Required by the API.
pub contact_id: String,
/// Location ID of the contact.
/// Required by the API.
pub location_id: String,
}
impl UploadFilesToCustomFieldsParams {
/// Start from the parameters the API requires.
pub fn new(contact_id: impl Into<String>, location_id: impl Into<String>) -> Self {
Self {
contact_id: contact_id.into(),
location_id: location_id.into(),
}
}
fn to_query(&self) -> Vec<(String, String)> {
let q: Vec<(String, String)> = vec![
("contactId".into(), self.contact_id.clone()),
("locationId".into(), self.location_id.clone()),
];
q
}
}
impl FormsService {
/// Get Forms
///
/// `GET /forms/`
///
/// Requires scope: `forms.readonly`.
pub async fn get_forms(
&self,
params: &GetFormsParams,
) -> Result<models::FormsSuccessfulResponseDto> {
let query = params.to_query();
self.client
.send_versioned(
reqwest::Method::GET,
"/forms/",
&query,
None::<&()>,
Some("v3"),
)
.await
}
/// Get Forms Submissions
///
/// `GET /forms/submissions`
///
/// Requires scope: `forms.readonly`.
pub async fn get_forms_submissions(
&self,
params: &GetFormsSubmissionsParams,
) -> Result<models::FormsSubmissionsSuccessfulResponseDto> {
let query = params.to_query();
self.client
.send_versioned(
reqwest::Method::GET,
"/forms/submissions",
&query,
None::<&()>,
Some("v3"),
)
.await
}
/// Upload files to custom fields
///
/// Post the necessary fields for the API to upload files. The files need to be a buffer
/// with the key "< custom_field_id >_< file_id >". Here custom field id is the ID of
/// your custom field and file id is a randomly generated id (or uuid) There is support
/// for multiple file uploads as well. Have multiple fields in the format mentioned.
/// File size is limited to 50 MB. The allowed file types are: PDF DOCX DOC JPG JPEG PNG
/// GIF CSV XLSX XLS MP4 MPEG ZIP RAR TXT SVG The
///
/// `POST /forms/upload-custom-files`
///
/// Requires scope: `forms.write`.
pub async fn upload_files_to_custom_fields(
&self,
params: &UploadFilesToCustomFieldsParams,
body: &serde_json::Value,
) -> Result<serde_json::Value> {
let query = params.to_query();
self.client
.send_versioned(
reqwest::Method::POST,
"/forms/upload-custom-files",
&query,
Some(body),
Some("v3"),
)
.await
}
}