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

#![allow(clippy::too_many_arguments)]

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

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

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

/// Query parameters for [`BusinessesService::get_businesses_by_location`].
#[derive(Debug, Clone, Default)]
pub struct GetBusinessesByLocationParams {
    /// `locationId` query parameter.
    /// Required by the API.
    pub location_id: String,
    /// `limit` query parameter.
    pub limit: Option<String>,
    /// `skip` query parameter.
    pub skip: Option<String>,
}

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

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

impl BusinessesService {
    /// Get Businesses by Location
    ///
    /// `GET /businesses/`
    ///
    /// Requires scope: `businesses.readonly`.
    pub async fn get_businesses_by_location(
        &self,
        params: &GetBusinessesByLocationParams,
    ) -> Result<models::GetBusinessByLocationResponseDto> {
        let query = params.to_query();
        self.client
            .send_versioned(
                reqwest::Method::GET,
                "/businesses/",
                &query,
                None::<&()>,
                Some("v3"),
            )
            .await
    }

    /// Create Business
    ///
    /// `POST /businesses/`
    ///
    /// Requires scope: `businesses.write`.
    pub async fn create_business(
        &self,
        body: &models::CreateBusinessDto,
    ) -> Result<models::UpdateBusinessResponseDto> {
        let query = Vec::new();
        self.client
            .send_versioned(
                reqwest::Method::POST,
                "/businesses/",
                &query,
                Some(body),
                Some("v3"),
            )
            .await
    }

    /// Delete Business
    ///
    /// `DELETE /businesses/{businessId}`
    ///
    /// Requires scope: `businesses.write`.
    pub async fn delete_business(
        &self,
        business_id: &str,
    ) -> Result<models::DeleteBusinessResponseDto> {
        let path = format!("/businesses/{}", crate::services::encode(business_id));
        let query = Vec::new();
        self.client
            .send_versioned(
                reqwest::Method::DELETE,
                &path,
                &query,
                None::<&()>,
                Some("v3"),
            )
            .await
    }

    /// Get Business
    ///
    /// `GET /businesses/{businessId}`
    ///
    /// Requires scope: `businesses.readonly`.
    pub async fn get_business(
        &self,
        business_id: &str,
    ) -> Result<models::GetBusinessByIdResponseDto> {
        let path = format!("/businesses/{}", crate::services::encode(business_id));
        let query = Vec::new();
        self.client
            .send_versioned(reqwest::Method::GET, &path, &query, None::<&()>, Some("v3"))
            .await
    }

    /// Update Business
    ///
    /// `PUT /businesses/{businessId}`
    ///
    /// Requires scope: `businesses.write`.
    pub async fn update_business(
        &self,
        business_id: &str,
        body: &models::UpdateBusinessDto,
    ) -> Result<models::UpdateBusinessResponseDto> {
        let path = format!("/businesses/{}", crate::services::encode(business_id));
        let query = Vec::new();
        self.client
            .send_versioned(reqwest::Method::PUT, &path, &query, Some(body), Some("v3"))
            .await
    }
}