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
// @generated by xtask/generate_services.py — do not edit by hand.
//! `surveys` — typed methods for all 2 API v3 operations
//! in this module.
//!
//! Access via [`Ghl::v3`](crate::Ghl::v3)`().surveys()`. These endpoints send `Version: v3`.
//!
//! Request and response types come from [`ghl_models::v3::surveys`](https://docs.rs/ghl-models/latest/ghl_models/v3/surveys/); every endpoint is also documented in the
//! [`surveys` API reference](https://github.com/Shahroz/ghl-rs/blob/main/docs/api/surveys.md).
//!
//! Enable with `features = ["surveys"]`.

#![allow(clippy::too_many_arguments)]

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

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

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

/// Query parameters for [`SurveysService::get_surveys`].
#[derive(Debug, Clone, Default)]
pub struct GetSurveysParams {
    /// `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 GetSurveysParams {
    /// 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 [`SurveysService::get_surveys_submissions`].
#[derive(Debug, Clone, Default)]
pub struct GetSurveysSubmissionsParams {
    /// `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 survey id
    pub survey_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 GetSurveysSubmissionsParams {
    /// 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 survey id
    pub fn survey_id(mut self, v: impl Into<String>) -> Self {
        self.survey_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.survey_id {
            q.push(("surveyId".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
    }
}

impl SurveysService {
    /// Get Surveys
    ///
    /// `GET /surveys/`
    ///
    /// Requires scope: `surveys.readonly`.
    pub async fn get_surveys(
        &self,
        params: &GetSurveysParams,
    ) -> Result<models::GetSurveysSuccessfulResponseDto> {
        let query = params.to_query();
        self.client
            .send_versioned(
                reqwest::Method::GET,
                "/surveys/",
                &query,
                None::<&()>,
                Some("v3"),
            )
            .await
    }

    /// Get Surveys Submissions
    ///
    /// `GET /surveys/submissions`
    ///
    /// Requires scope: `surveys.readonly`.
    pub async fn get_surveys_submissions(
        &self,
        params: &GetSurveysSubmissionsParams,
    ) -> Result<models::GetSurveysSubmissionSuccessfulResponseDto> {
        let query = params.to_query();
        self.client
            .send_versioned(
                reqwest::Method::GET,
                "/surveys/submissions",
                &query,
                None::<&()>,
                Some("v3"),
            )
            .await
    }
}