ghl_sdk/services/
forms.rs1#![allow(clippy::too_many_arguments)]
13
14use crate::client::Ghl;
15use crate::error::Result;
16use ghl_models::v2::forms as models;
17
18#[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#[derive(Debug, Clone, Default)]
33pub struct GetFormsParams {
34 pub location_id: String,
37 pub skip: Option<f64>,
39 pub limit: Option<f64>,
41 pub type_: Option<String>,
43}
44
45impl GetFormsParams {
46 pub fn new(location_id: impl Into<String>) -> Self {
48 Self {
49 location_id: location_id.into(),
50 ..Default::default()
51 }
52 }
53
54 pub fn skip(mut self, v: f64) -> Self {
56 self.skip = Some(v);
57 self
58 }
59
60 pub fn limit(mut self, v: f64) -> Self {
62 self.limit = Some(v);
63 self
64 }
65
66 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#[derive(Debug, Clone, Default)]
89pub struct GetFormsSubmissionsParams {
90 pub location_id: String,
93 pub page: Option<f64>,
95 pub limit: Option<f64>,
97 pub form_id: Option<String>,
99 pub q: Option<String>,
101 pub start_at: Option<String>,
104 pub end_at: Option<String>,
107}
108
109impl GetFormsSubmissionsParams {
110 pub fn new(location_id: impl Into<String>) -> Self {
112 Self {
113 location_id: location_id.into(),
114 ..Default::default()
115 }
116 }
117
118 pub fn page(mut self, v: f64) -> Self {
120 self.page = Some(v);
121 self
122 }
123
124 pub fn limit(mut self, v: f64) -> Self {
126 self.limit = Some(v);
127 self
128 }
129
130 pub fn form_id(mut self, v: impl Into<String>) -> Self {
132 self.form_id = Some(v.into());
133 self
134 }
135
136 pub fn q(mut self, v: impl Into<String>) -> Self {
138 self.q = Some(v.into());
139 self
140 }
141
142 pub fn start_at(mut self, v: impl Into<String>) -> Self {
145 self.start_at = Some(v.into());
146 self
147 }
148
149 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#[derive(Debug, Clone, Default)]
182pub struct UploadFilesToCustomFieldsParams {
183 pub contact_id: String,
186 pub location_id: String,
189}
190
191impl UploadFilesToCustomFieldsParams {
192 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 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 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 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}