Skip to main content

ghl_sdk/services/
forms.rs

1// @generated by xtask/generate_services.py — do not edit by hand.
2//! `forms` — typed methods for all 3 API v2 operations
3//! in this module.
4//!
5//! Access via [`Ghl::forms`](crate::Ghl::forms).
6//!
7//! Request and response types come from [`ghl_models::v2::forms`](https://docs.rs/ghl-models/latest/ghl_models/v2/forms/); every endpoint is also documented in the
8//! [`forms` API reference](https://github.com/Shahroz/ghl-rs/blob/main/docs/api/forms.md).
9//!
10//! Enable with `features = ["forms"]`.
11
12#![allow(clippy::too_many_arguments)]
13
14use crate::client::Ghl;
15use crate::error::Result;
16use ghl_models::v2::forms as models;
17
18/// Typed access to the `forms` API v2 surface (3 operations). Obtained via
19/// [`Ghl::forms`](crate::Ghl::forms).
20#[derive(Debug, Clone)]
21pub struct FormsService {
22    pub(crate) client: Ghl,
23}
24
25impl FormsService {
26    pub(crate) fn new(client: Ghl) -> Self {
27        Self { client }
28    }
29}
30
31/// Query parameters for [`FormsService::get_forms`].
32#[derive(Debug, Clone, Default)]
33pub struct GetFormsParams {
34    /// `locationId` query parameter.
35    /// Required by the API.
36    pub location_id: String,
37    /// `skip` query parameter.
38    pub skip: Option<f64>,
39    /// Limit Per Page records count. will allow maximum up to 50 and default will be 10
40    pub limit: Option<f64>,
41    /// `type` query parameter.
42    pub type_: Option<String>,
43}
44
45impl GetFormsParams {
46    /// Start from the parameters the API requires.
47    pub fn new(location_id: impl Into<String>) -> Self {
48        Self {
49            location_id: location_id.into(),
50            ..Default::default()
51        }
52    }
53
54    /// Set the `skip` query parameter.
55    pub fn skip(mut self, v: f64) -> Self {
56        self.skip = Some(v);
57        self
58    }
59
60    /// Limit Per Page records count. will allow maximum up to 50 and default will be 10
61    pub fn limit(mut self, v: f64) -> Self {
62        self.limit = Some(v);
63        self
64    }
65
66    /// Set the `type` query parameter.
67    pub fn type_(mut self, v: impl Into<String>) -> Self {
68        self.type_ = Some(v.into());
69        self
70    }
71
72    fn to_query(&self) -> Vec<(String, String)> {
73        let mut q: Vec<(String, String)> = vec![("locationId".into(), self.location_id.clone())];
74        if let Some(v) = &self.skip {
75            q.push(("skip".into(), v.to_string()));
76        }
77        if let Some(v) = &self.limit {
78            q.push(("limit".into(), v.to_string()));
79        }
80        if let Some(v) = &self.type_ {
81            q.push(("type".into(), v.to_string()));
82        }
83        q
84    }
85}
86
87/// Query parameters for [`FormsService::get_forms_submissions`].
88#[derive(Debug, Clone, Default)]
89pub struct GetFormsSubmissionsParams {
90    /// `locationId` query parameter.
91    /// Required by the API.
92    pub location_id: String,
93    /// Page No. By default it will be 1
94    pub page: Option<f64>,
95    /// Limit Per Page records count. will allow maximum up to 100 and default will be 20
96    pub limit: Option<f64>,
97    /// Filter submission by form id
98    pub form_id: Option<String>,
99    /// Filter by contactId, name, email or phone no.
100    pub q: Option<String>,
101    /// Get submission by starting of this date. By default it will be same date of last
102    /// month(YYYY-MM-DD).
103    pub start_at: Option<String>,
104    /// Get submission by ending of this date. By default it will be current
105    /// date(YYYY-MM-DD).
106    pub end_at: Option<String>,
107}
108
109impl GetFormsSubmissionsParams {
110    /// Start from the parameters the API requires.
111    pub fn new(location_id: impl Into<String>) -> Self {
112        Self {
113            location_id: location_id.into(),
114            ..Default::default()
115        }
116    }
117
118    /// Page No. By default it will be 1
119    pub fn page(mut self, v: f64) -> Self {
120        self.page = Some(v);
121        self
122    }
123
124    /// Limit Per Page records count. will allow maximum up to 100 and default will be 20
125    pub fn limit(mut self, v: f64) -> Self {
126        self.limit = Some(v);
127        self
128    }
129
130    /// Filter submission by form id
131    pub fn form_id(mut self, v: impl Into<String>) -> Self {
132        self.form_id = Some(v.into());
133        self
134    }
135
136    /// Filter by contactId, name, email or phone no.
137    pub fn q(mut self, v: impl Into<String>) -> Self {
138        self.q = Some(v.into());
139        self
140    }
141
142    /// Get submission by starting of this date. By default it will be same date of last
143    /// month(YYYY-MM-DD).
144    pub fn start_at(mut self, v: impl Into<String>) -> Self {
145        self.start_at = Some(v.into());
146        self
147    }
148
149    /// Get submission by ending of this date. By default it will be current
150    /// date(YYYY-MM-DD).
151    pub fn end_at(mut self, v: impl Into<String>) -> Self {
152        self.end_at = Some(v.into());
153        self
154    }
155
156    fn to_query(&self) -> Vec<(String, String)> {
157        let mut q: Vec<(String, String)> = vec![("locationId".into(), self.location_id.clone())];
158        if let Some(v) = &self.page {
159            q.push(("page".into(), v.to_string()));
160        }
161        if let Some(v) = &self.limit {
162            q.push(("limit".into(), v.to_string()));
163        }
164        if let Some(v) = &self.form_id {
165            q.push(("formId".into(), v.to_string()));
166        }
167        if let Some(v) = &self.q {
168            q.push(("q".into(), v.to_string()));
169        }
170        if let Some(v) = &self.start_at {
171            q.push(("startAt".into(), v.to_string()));
172        }
173        if let Some(v) = &self.end_at {
174            q.push(("endAt".into(), v.to_string()));
175        }
176        q
177    }
178}
179
180/// Query parameters for [`FormsService::upload_files_to_custom_fields`].
181#[derive(Debug, Clone, Default)]
182pub struct UploadFilesToCustomFieldsParams {
183    /// Contact ID to upload the file to.
184    /// Required by the API.
185    pub contact_id: String,
186    /// Location ID of the contact.
187    /// Required by the API.
188    pub location_id: String,
189}
190
191impl UploadFilesToCustomFieldsParams {
192    /// Start from the parameters the API requires.
193    pub fn new(contact_id: impl Into<String>, location_id: impl Into<String>) -> Self {
194        Self {
195            contact_id: contact_id.into(),
196            location_id: location_id.into(),
197        }
198    }
199
200    fn to_query(&self) -> Vec<(String, String)> {
201        let q: Vec<(String, String)> = vec![
202            ("contactId".into(), self.contact_id.clone()),
203            ("locationId".into(), self.location_id.clone()),
204        ];
205        q
206    }
207}
208
209impl FormsService {
210    /// Get Forms
211    ///
212    /// `GET /forms/`
213    ///
214    /// Requires scope: `forms.readonly`.
215    pub async fn get_forms(
216        &self,
217        params: &GetFormsParams,
218    ) -> Result<models::FormsSuccessfulResponseDto> {
219        let query = params.to_query();
220        self.client
221            .send_versioned(
222                reqwest::Method::GET,
223                "/forms/",
224                &query,
225                None::<&()>,
226                Some("2021-07-28"),
227            )
228            .await
229    }
230
231    /// Get Forms Submissions
232    ///
233    /// `GET /forms/submissions`
234    ///
235    /// Requires scope: `forms.readonly`.
236    pub async fn get_forms_submissions(
237        &self,
238        params: &GetFormsSubmissionsParams,
239    ) -> Result<models::FormsSubmissionsSuccessfulResponseDto> {
240        let query = params.to_query();
241        self.client
242            .send_versioned(
243                reqwest::Method::GET,
244                "/forms/submissions",
245                &query,
246                None::<&()>,
247                Some("2021-07-28"),
248            )
249            .await
250    }
251
252    /// Upload files to custom fields
253    ///
254    /// Post the necessary fields for the API to upload files. The files need to be a buffer
255    /// with the key "< custom_field_id >_< file_id >". Here custom field id is the ID of
256    /// your custom field and file id is a randomly generated id (or uuid) There is support
257    /// for multiple file uploads as well. Have multiple fields in the format mentioned.
258    /// File size is limited to 50 MB. The allowed file types are: PDF DOCX DOC JPG JPEG PNG
259    /// GIF CSV XLSX XLS MP4 MPEG ZIP RAR TXT SVG The
260    ///
261    /// `POST /forms/upload-custom-files`
262    ///
263    /// Requires scope: `forms.write`.
264    pub async fn upload_files_to_custom_fields(
265        &self,
266        params: &UploadFilesToCustomFieldsParams,
267        body: &serde_json::Value,
268    ) -> Result<serde_json::Value> {
269        let query = params.to_query();
270        self.client
271            .send_versioned(
272                reqwest::Method::POST,
273                "/forms/upload-custom-files",
274                &query,
275                Some(body),
276                Some("2021-07-28"),
277            )
278            .await
279    }
280}