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

#![allow(clippy::too_many_arguments)]

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

/// Typed access to the `custom-fields` API v3 surface (8 operations). Obtained via
/// [`Ghl::v3`](crate::Ghl::v3)`().custom_fields()`.
#[derive(Debug, Clone)]
pub struct CustomFieldsService {
    pub(crate) client: Ghl,
}

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

/// Query parameters for [`CustomFieldsService::delete_custom_field_folder`].
#[derive(Debug, Clone, Default)]
pub struct DeleteCustomFieldFolderParams {
    /// Location Id
    /// Required by the API.
    pub location_id: String,
}

impl DeleteCustomFieldFolderParams {
    /// 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 [`CustomFieldsService::get_custom_fields_by_object_key`].
#[derive(Debug, Clone, Default)]
pub struct GetCustomFieldsByObjectKeyParams {
    /// `locationId` query parameter.
    /// Required by the API.
    pub location_id: String,
}

impl GetCustomFieldsByObjectKeyParams {
    /// 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
    }
}

impl CustomFieldsService {
    /// Create Custom Field
    ///
    /// Create Custom Field :::info Only supports Custom Objects and Company (Business)
    /// today. Will be extended to other Standard Objects in the future. :::
    ///
    /// `POST /custom-fields/`
    ///
    /// Requires scope: `locations/customFields.write`.
    pub async fn create_custom_field(
        &self,
        body: &models::CreateCustomFieldsDTO,
    ) -> Result<models::CustomFieldSuccessfulResponseDto> {
        let query = Vec::new();
        self.client
            .send_versioned(
                reqwest::Method::POST,
                "/custom-fields/",
                &query,
                Some(body),
                Some("v3"),
            )
            .await
    }

    /// Create Custom Field Folder
    ///
    /// Create Custom Field Folder :::info Only supports Custom Objects and Company
    /// (Business) today. Will be extended to other Standard Objects in the future. :::
    ///
    /// `POST /custom-fields/folder`
    ///
    /// Requires scope: `locations/customFields.write`.
    pub async fn create_custom_field_folder(
        &self,
        body: &models::CreateFolder,
    ) -> Result<models::ICustomFieldFolder> {
        let query = Vec::new();
        self.client
            .send_versioned(
                reqwest::Method::POST,
                "/custom-fields/folder",
                &query,
                Some(body),
                Some("v3"),
            )
            .await
    }

    /// Delete Custom Field Folder
    ///
    /// Create Custom Field Folder :::info Only supports Custom Objects and Company
    /// (Business) today. Will be extended to other Standard Objects in the future. :::
    ///
    /// `DELETE /custom-fields/folder/{id}`
    ///
    /// Requires scope: `locations/customFields.write`.
    pub async fn delete_custom_field_folder(
        &self,
        id: &str,
        params: &DeleteCustomFieldFolderParams,
    ) -> Result<models::CustomFolderDeleteResponseDto> {
        let path = format!("/custom-fields/folder/{}", crate::services::encode(id));
        let query = params.to_query();
        self.client
            .send_versioned(
                reqwest::Method::DELETE,
                &path,
                &query,
                None::<&()>,
                Some("v3"),
            )
            .await
    }

    /// Update Custom Field Folder Name
    ///
    /// Create Custom Field Folder :::info Only supports Custom Objects and Company
    /// (Business) today. Will be extended to other Standard Objects in the future. :::
    ///
    /// `PUT /custom-fields/folder/{id}`
    ///
    /// Requires scope: `locations/customFields.write`.
    pub async fn update_custom_field_folder_name(
        &self,
        id: &str,
        body: &models::UpdateFolder,
    ) -> Result<models::ICustomFieldFolder> {
        let path = format!("/custom-fields/folder/{}", crate::services::encode(id));
        let query = Vec::new();
        self.client
            .send_versioned(reqwest::Method::PUT, &path, &query, Some(body), Some("v3"))
            .await
    }

    /// Get Custom Fields By Object Key
    ///
    /// Get Custom Fields By Object Key :::info Only supports Custom Objects and Company
    /// (Business) today. Will be extended to other Standard Objects in the future. :::
    ///
    /// `GET /custom-fields/object-key/{objectKey}`
    ///
    /// Requires scope: `locations/customFields.readonly`.
    pub async fn get_custom_fields_by_object_key(
        &self,
        object_key: &str,
        params: &GetCustomFieldsByObjectKeyParams,
    ) -> Result<models::CustomFieldsResponseDTO> {
        let path = format!(
            "/custom-fields/object-key/{}",
            crate::services::encode(object_key)
        );
        let query = params.to_query();
        self.client
            .send_versioned(reqwest::Method::GET, &path, &query, None::<&()>, Some("v3"))
            .await
    }

    /// Delete Custom Field By Id
    ///
    /// Delete Custom Field By Id :::info Only supports Custom Objects and Company
    /// (Business) today. Will be extended to other Standard Objects in the future. :::
    ///
    /// `DELETE /custom-fields/{id}`
    ///
    /// Requires scope: `locations/customFields.write`.
    pub async fn delete_custom_field_by_id(
        &self,
        id: &str,
    ) -> Result<models::CustomFolderDeleteResponseDto> {
        let path = format!("/custom-fields/{}", crate::services::encode(id));
        let query = Vec::new();
        self.client
            .send_versioned(
                reqwest::Method::DELETE,
                &path,
                &query,
                None::<&()>,
                Some("v3"),
            )
            .await
    }

    /// Get Custom Field / Folder By Id
    ///
    /// Get Custom Field / Folder By Id. :::info Only supports Custom Objects and Company
    /// (Business) today. Will be extended to other Standard Objects in the future. :::
    ///
    /// `GET /custom-fields/{id}`
    ///
    /// Requires scope: `locations/customFields.readonly`.
    pub async fn get_custom_field_folder_by_id(
        &self,
        id: &str,
    ) -> Result<models::CustomFieldSuccessfulResponseDto> {
        let path = format!("/custom-fields/{}", crate::services::encode(id));
        let query = Vec::new();
        self.client
            .send_versioned(reqwest::Method::GET, &path, &query, None::<&()>, Some("v3"))
            .await
    }

    /// Update Custom Field By Id
    ///
    /// Update Custom Field By Id :::info Only supports Custom Objects and Company
    /// (Business) today. Will be extended to other Standard Objects in the future. :::
    ///
    /// `PUT /custom-fields/{id}`
    ///
    /// Requires scope: `locations/customFields.write`.
    pub async fn update_custom_field_by_id(
        &self,
        id: &str,
        body: &models::UpdateCustomFieldsDTO,
    ) -> Result<models::CustomFieldSuccessfulResponseDto> {
        let path = format!("/custom-fields/{}", crate::services::encode(id));
        let query = Vec::new();
        self.client
            .send_versioned(reqwest::Method::PUT, &path, &query, Some(body), Some("v3"))
            .await
    }
}