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.
//! `campaigns` — typed methods for all 1 API v2 operations
//! in this module.
//!
//! Access via [`Ghl::campaigns`](crate::Ghl::campaigns).
//!
//! Request and response types come from [`ghl_models::v2::campaigns`](https://docs.rs/ghl-models/latest/ghl_models/v2/campaigns/); every endpoint is also documented in the
//! [`campaigns` API reference](https://github.com/Shahroz/ghl-rs/blob/main/docs/api/campaigns.md).
//!
//! Enable with `features = ["campaigns"]`.

#![allow(clippy::too_many_arguments)]

use crate::client::Ghl;
use crate::error::Result;
use ghl_models::v2::campaigns as models;

/// Typed access to the `campaigns` API v2 surface (1 operations). Obtained via
/// [`Ghl::campaigns`](crate::Ghl::campaigns).
#[derive(Debug, Clone)]
pub struct CampaignsService {
    pub(crate) client: Ghl,
}

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

/// Query parameters for [`CampaignsService::get_campaigns`].
#[derive(Debug, Clone, Default)]
pub struct GetCampaignsParams {
    /// `locationId` query parameter.
    /// Required by the API.
    pub location_id: String,
    /// `status` query parameter.
    pub status: Option<String>,
}

impl GetCampaignsParams {
    /// 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 `status` query parameter.
    pub fn status(mut self, v: impl Into<String>) -> Self {
        self.status = 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.status {
            q.push(("status".into(), v.to_string()));
        }
        q
    }
}

impl CampaignsService {
    /// Get Campaigns
    ///
    /// `GET /campaigns/`
    ///
    /// Requires scope: `campaigns.readonly`.
    pub async fn get_campaigns(
        &self,
        params: &GetCampaignsParams,
    ) -> Result<models::CampaignsSuccessfulResponseDto> {
        let query = params.to_query();
        self.client
            .send_versioned(
                reqwest::Method::GET,
                "/campaigns/",
                &query,
                None::<&()>,
                Some("2021-07-28"),
            )
            .await
    }
}