ghl-sdk 0.5.2

Unofficial async Rust SDK for the GoHighLevel (HighLevel) API 2.0 — OAuth 2.0, Private Integration Tokens, rate-limit-aware retries, paginated streams
Documentation
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
// @generated by xtask/generate_services.py — do not edit by hand.
//! `funnels` — typed methods for all 7 API v3 operations
//! in this module.
//!
//! Access via [`Ghl::v3`](crate::Ghl::v3)`().funnels()`. These endpoints send `Version: v3`.
//!
//! Request and response types come from [`ghl_models::v3::funnels`](https://docs.rs/ghl-models/latest/ghl_models/v3/funnels/); every endpoint is also documented in the
//! [`funnels` API reference](https://github.com/Shahroz/ghl-rs/blob/main/docs/api/funnels.md).
//!
//! Enable with `features = ["funnels"]`.

#![allow(clippy::too_many_arguments)]

use crate::client::Ghl;
use crate::error::Result;
use ghl_models::v3::funnels as models;

/// Typed access to the `funnels` API v3 surface (7 operations). Obtained via
/// [`Ghl::v3`](crate::Ghl::v3)`().funnels()`.
#[derive(Debug, Clone)]
pub struct FunnelsService {
    pub(crate) client: Ghl,
}

impl FunnelsService {
    pub(crate) fn new(client: Ghl) -> Self {
        Self { client }
    }
}

/// Query parameters for [`FunnelsService::fetch_list_of_funnels`].
#[derive(Debug, Clone, Default)]
pub struct FetchListOfFunnelsParams {
    /// `locationId` query parameter.
    /// Required by the API.
    pub location_id: String,
    /// `type` query parameter.
    pub type_: Option<String>,
    /// `category` query parameter.
    pub category: Option<String>,
    /// `offset` query parameter.
    pub offset: Option<String>,
    /// `limit` query parameter.
    pub limit: Option<String>,
    /// `parentId` query parameter.
    pub parent_id: Option<String>,
    /// `name` query parameter.
    pub name: Option<String>,
}

impl FetchListOfFunnelsParams {
    /// 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 `type` query parameter.
    pub fn type_(mut self, v: impl Into<String>) -> Self {
        self.type_ = Some(v.into());
        self
    }

    /// Set the `category` query parameter.
    pub fn category(mut self, v: impl Into<String>) -> Self {
        self.category = Some(v.into());
        self
    }

    /// Set the `offset` query parameter.
    pub fn offset(mut self, v: impl Into<String>) -> Self {
        self.offset = Some(v.into());
        self
    }

    /// Set the `limit` query parameter.
    pub fn limit(mut self, v: impl Into<String>) -> Self {
        self.limit = Some(v.into());
        self
    }

    /// Set the `parentId` query parameter.
    pub fn parent_id(mut self, v: impl Into<String>) -> Self {
        self.parent_id = Some(v.into());
        self
    }

    /// Set the `name` query parameter.
    pub fn name(mut self, v: impl Into<String>) -> Self {
        self.name = 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.type_ {
            q.push(("type".into(), v.to_string()));
        }
        if let Some(v) = &self.category {
            q.push(("category".into(), v.to_string()));
        }
        if let Some(v) = &self.offset {
            q.push(("offset".into(), v.to_string()));
        }
        if let Some(v) = &self.limit {
            q.push(("limit".into(), v.to_string()));
        }
        if let Some(v) = &self.parent_id {
            q.push(("parentId".into(), v.to_string()));
        }
        if let Some(v) = &self.name {
            q.push(("name".into(), v.to_string()));
        }
        q
    }
}

/// Query parameters for [`FunnelsService::fetch_list_of_redirects`].
#[derive(Debug, Clone, Default)]
pub struct FetchListOfRedirectsParams {
    /// `locationId` query parameter.
    /// Required by the API.
    pub location_id: String,
    /// `limit` query parameter.
    /// Required by the API.
    pub limit: f64,
    /// `offset` query parameter.
    /// Required by the API.
    pub offset: f64,
    /// `search` query parameter.
    pub search: Option<String>,
}

impl FetchListOfRedirectsParams {
    /// Start from the parameters the API requires.
    pub fn new(location_id: impl Into<String>, limit: f64, offset: f64) -> Self {
        Self {
            location_id: location_id.into(),
            limit,
            offset,
            ..Default::default()
        }
    }

    /// Set the `search` query parameter.
    pub fn search(mut self, v: impl Into<String>) -> Self {
        self.search = Some(v.into());
        self
    }

    fn to_query(&self) -> Vec<(String, String)> {
        let mut q: Vec<(String, String)> = vec![
            ("locationId".into(), self.location_id.clone()),
            ("limit".into(), self.limit.to_string()),
            ("offset".into(), self.offset.to_string()),
        ];
        if let Some(v) = &self.search {
            q.push(("search".into(), v.to_string()));
        }
        q
    }
}

/// Query parameters for [`FunnelsService::delete_redirect_by_id`].
#[derive(Debug, Clone, Default)]
pub struct DeleteRedirectByIdParams {
    /// `locationId` query parameter.
    /// Required by the API.
    pub location_id: String,
}

impl DeleteRedirectByIdParams {
    /// 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 [`FunnelsService::fetch_list_of_funnel_pages`].
#[derive(Debug, Clone, Default)]
pub struct FetchListOfFunnelPagesParams {
    /// `locationId` query parameter.
    /// Required by the API.
    pub location_id: String,
    /// `funnelId` query parameter.
    /// Required by the API.
    pub funnel_id: String,
    /// `name` query parameter.
    pub name: Option<String>,
    /// `limit` query parameter.
    /// Required by the API.
    pub limit: f64,
    /// `offset` query parameter.
    /// Required by the API.
    pub offset: f64,
}

impl FetchListOfFunnelPagesParams {
    /// Start from the parameters the API requires.
    pub fn new(
        location_id: impl Into<String>,
        funnel_id: impl Into<String>,
        limit: f64,
        offset: f64,
    ) -> Self {
        Self {
            location_id: location_id.into(),
            funnel_id: funnel_id.into(),
            limit,
            offset,
            ..Default::default()
        }
    }

    /// Set the `name` query parameter.
    pub fn name(mut self, v: impl Into<String>) -> Self {
        self.name = Some(v.into());
        self
    }

    fn to_query(&self) -> Vec<(String, String)> {
        let mut q: Vec<(String, String)> = vec![
            ("locationId".into(), self.location_id.clone()),
            ("funnelId".into(), self.funnel_id.clone()),
            ("limit".into(), self.limit.to_string()),
            ("offset".into(), self.offset.to_string()),
        ];
        if let Some(v) = &self.name {
            q.push(("name".into(), v.to_string()));
        }
        q
    }
}

/// Query parameters for [`FunnelsService::fetch_count_of_funnel_pages`].
#[derive(Debug, Clone, Default)]
pub struct FetchCountOfFunnelPagesParams {
    /// `locationId` query parameter.
    /// Required by the API.
    pub location_id: String,
    /// `funnelId` query parameter.
    /// Required by the API.
    pub funnel_id: String,
    /// `name` query parameter.
    pub name: Option<String>,
}

impl FetchCountOfFunnelPagesParams {
    /// Start from the parameters the API requires.
    pub fn new(location_id: impl Into<String>, funnel_id: impl Into<String>) -> Self {
        Self {
            location_id: location_id.into(),
            funnel_id: funnel_id.into(),
            ..Default::default()
        }
    }

    /// Set the `name` query parameter.
    pub fn name(mut self, v: impl Into<String>) -> Self {
        self.name = Some(v.into());
        self
    }

    fn to_query(&self) -> Vec<(String, String)> {
        let mut q: Vec<(String, String)> = vec![
            ("locationId".into(), self.location_id.clone()),
            ("funnelId".into(), self.funnel_id.clone()),
        ];
        if let Some(v) = &self.name {
            q.push(("name".into(), v.to_string()));
        }
        q
    }
}

impl FunnelsService {
    /// Fetch List of Funnels
    ///
    /// Retrieves a list of all funnels based on the given query parameters.
    ///
    /// `GET /funnels/funnel/list`
    pub async fn fetch_list_of_funnels(
        &self,
        params: &FetchListOfFunnelsParams,
    ) -> Result<models::FunnelListResponseDTO> {
        let query = params.to_query();
        self.client
            .send_versioned(
                reqwest::Method::GET,
                "/funnels/funnel/list",
                &query,
                None::<&()>,
                Some("v3"),
            )
            .await
    }

    /// Create Redirect
    ///
    /// The "Create Redirect" API Allows adding a new url redirect to the system. Use this
    /// endpoint to create a url redirect with the specified details. Ensure that the
    /// required information is provided in the request payload.
    ///
    /// `POST /funnels/lookup/redirect`
    ///
    /// Requires scope: `funnels/redirect.write`.
    pub async fn create_redirect(
        &self,
        body: &models::CreateRedirectParams,
    ) -> Result<models::CreateRedirectResponseDTO> {
        let query = Vec::new();
        self.client
            .send_versioned(
                reqwest::Method::POST,
                "/funnels/lookup/redirect",
                &query,
                Some(body),
                Some("v3"),
            )
            .await
    }

    /// Fetch List of Redirects
    ///
    /// Retrieves a list of all URL redirects based on the given query parameters.
    ///
    /// `GET /funnels/lookup/redirect/list`
    ///
    /// Requires scope: `funnels/redirect.readonly`.
    pub async fn fetch_list_of_redirects(
        &self,
        params: &FetchListOfRedirectsParams,
    ) -> Result<models::RedirectListResponseDTO> {
        let query = params.to_query();
        self.client
            .send_versioned(
                reqwest::Method::GET,
                "/funnels/lookup/redirect/list",
                &query,
                None::<&()>,
                Some("v3"),
            )
            .await
    }

    /// Delete Redirect By Id
    ///
    /// The "Delete Redirect By Id" API Allows deletion of a URL redirect from the system
    /// using its unique identifier. Use this endpoint to delete a URL redirect with the
    /// specified ID using details provided in the request payload.
    ///
    /// `DELETE /funnels/lookup/redirect/{id}`
    ///
    /// Requires scope: `funnels/redirect.write`.
    pub async fn delete_redirect_by_id(
        &self,
        id: &str,
        params: &DeleteRedirectByIdParams,
    ) -> Result<models::DeleteRedirectResponseDTO> {
        let path = format!("/funnels/lookup/redirect/{}", crate::services::encode(id));
        let query = params.to_query();
        self.client
            .send_versioned(
                reqwest::Method::DELETE,
                &path,
                &query,
                None::<&()>,
                Some("v3"),
            )
            .await
    }

    /// Update Redirect By Id
    ///
    /// The "Update Redirect By Id" API Allows updating an existing URL redirect in the
    /// system. Use this endpoint to modify a URL redirect with the specified ID using
    /// details provided in the request payload.
    ///
    /// `PATCH /funnels/lookup/redirect/{id}`
    ///
    /// Requires scope: `funnels/redirect.write`.
    pub async fn update_redirect_by_id(
        &self,
        id: &str,
        body: &models::UpdateRedirectParams,
    ) -> Result<models::UpdateRedirectResponseDTO> {
        let path = format!("/funnels/lookup/redirect/{}", crate::services::encode(id));
        let query = Vec::new();
        self.client
            .send_versioned(
                reqwest::Method::PATCH,
                &path,
                &query,
                Some(body),
                Some("v3"),
            )
            .await
    }

    /// Fetch list of funnel pages
    ///
    /// Retrieves a list of all funnel pages based on the given query parameters.
    ///
    /// `GET /funnels/page`
    pub async fn fetch_list_of_funnel_pages(
        &self,
        params: &FetchListOfFunnelPagesParams,
    ) -> Result<models::FunnelPageResponseDTO> {
        let query = params.to_query();
        self.client
            .send_versioned(
                reqwest::Method::GET,
                "/funnels/page",
                &query,
                None::<&()>,
                Some("v3"),
            )
            .await
    }

    /// Fetch count of funnel pages
    ///
    /// Retrieves count of all funnel pages based on the given query parameters.
    ///
    /// `GET /funnels/page/count`
    pub async fn fetch_count_of_funnel_pages(
        &self,
        params: &FetchCountOfFunnelPagesParams,
    ) -> Result<models::FunnelPageCountResponseDTO> {
        let query = params.to_query();
        self.client
            .send_versioned(
                reqwest::Method::GET,
                "/funnels/page/count",
                &query,
                None::<&()>,
                Some("v3"),
            )
            .await
    }
}