ghl-sdk 0.5.1

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

#![allow(clippy::too_many_arguments)]

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

/// Typed access to the `custom-menus` API v2 surface (5 operations). Obtained via
/// [`Ghl::custom_menus`](crate::Ghl::custom_menus).
#[derive(Debug, Clone)]
pub struct CustomMenusService {
    pub(crate) client: Ghl,
}

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

/// Query parameters for [`CustomMenusService::get_custom_menu_links`].
#[derive(Debug, Clone, Default)]
pub struct GetCustomMenuLinksParams {
    /// Unique identifier of the location
    pub location_id: Option<String>,
    /// Number of items to skip for pagination
    pub skip: Option<f64>,
    /// Maximum number of items to return
    pub limit: Option<f64>,
    /// Search query to filter custom menus by name, supports partial || full names
    pub query: Option<String>,
    /// Filter to show only agency-level menu links. When omitted, fetches both agency and
    /// sub-account menu links. Ignored if locationId is provided
    pub show_on_company: Option<bool>,
}

impl GetCustomMenuLinksParams {
    /// Start from the parameters the API requires.
    pub fn new() -> Self {
        Self {
            ..Default::default()
        }
    }

    /// Unique identifier of the location
    pub fn location_id(mut self, v: impl Into<String>) -> Self {
        self.location_id = Some(v.into());
        self
    }

    /// Number of items to skip for pagination
    pub fn skip(mut self, v: f64) -> Self {
        self.skip = Some(v);
        self
    }

    /// Maximum number of items to return
    pub fn limit(mut self, v: f64) -> Self {
        self.limit = Some(v);
        self
    }

    /// Search query to filter custom menus by name, supports partial || full names
    pub fn query(mut self, v: impl Into<String>) -> Self {
        self.query = Some(v.into());
        self
    }

    /// Filter to show only agency-level menu links. When omitted, fetches both agency and
    /// sub-account menu links. Ignored if locationId is provided
    pub fn show_on_company(mut self, v: bool) -> Self {
        self.show_on_company = Some(v);
        self
    }

    fn to_query(&self) -> Vec<(String, String)> {
        let mut q: Vec<(String, String)> = Vec::new();
        if let Some(v) = &self.location_id {
            q.push(("locationId".into(), v.to_string()));
        }
        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.query {
            q.push(("query".into(), v.to_string()));
        }
        if let Some(v) = &self.show_on_company {
            q.push(("showOnCompany".into(), v.to_string()));
        }
        q
    }
}

impl CustomMenusService {
    /// Get Custom Menu Links
    ///
    /// Fetches a collection of custom menus based on specified criteria. This endpoint
    /// allows clients to retrieve custom menu configurations, which may include menu items,
    /// categories, and associated metadata. The response can be tailored using query
    /// parameters for filtering, sorting, and pagination.
    ///
    /// `GET /custom-menus/`
    ///
    /// Requires scope: `custom-menu-link.readonly`.
    pub async fn get_custom_menu_links(
        &self,
        params: &GetCustomMenuLinksParams,
    ) -> Result<models::GetCustomMenusResponseDTO> {
        let query = params.to_query();
        self.client
            .send_versioned(
                reqwest::Method::GET,
                "/custom-menus/",
                &query,
                None::<&()>,
                Some("2021-07-28"),
            )
            .await
    }

    /// Create Custom Menu Link
    ///
    /// Creates a new custom menu for a company. Requires authentication and proper
    /// permissions. For Icon Usage Details please refer to
    /// <https://doc.clickup.com/8631005/d/h/87cpx-243696/d60fa70db6b92b2>
    ///
    /// `POST /custom-menus/`
    ///
    /// Requires scope: `custom-menu-link.write`.
    pub async fn create_custom_menu_link(
        &self,
        body: &models::CreateCustomMenuDTO,
    ) -> Result<models::GetSingleCustomMenusSuccessfulResponseDTO> {
        let query = Vec::new();
        self.client
            .send_versioned(
                reqwest::Method::POST,
                "/custom-menus/",
                &query,
                Some(body),
                Some("2021-07-28"),
            )
            .await
    }

    /// Delete Custom Menu Link
    ///
    /// Removes a specific custom menu from the system. This operation requires
    /// authentication and proper permissions. The custom menu is identified by its unique
    /// ID, and the operation is performed within the context of a specific company.
    ///
    /// `DELETE /custom-menus/{customMenuId}`
    ///
    /// Requires scope: `custom-menu-link.write`.
    pub async fn delete_custom_menu_link(
        &self,
        custom_menu_id: &str,
    ) -> Result<models::DeleteCustomMenuSuccessfulResponseDTO> {
        let path = format!("/custom-menus/{}", crate::services::encode(custom_menu_id));
        let query = Vec::new();
        self.client
            .send_versioned(
                reqwest::Method::DELETE,
                &path,
                &query,
                None::<&()>,
                Some("2021-07-28"),
            )
            .await
    }

    /// Get Custom Menu Link
    ///
    /// Fetches a single custom menus based on id. This endpoint allows clients to retrieve
    /// custom menu configurations, which may include menu items, categories, and associated
    /// metadata
    ///
    /// `GET /custom-menus/{customMenuId}`
    ///
    /// Requires scope: `custom-menu-link.readonly`.
    pub async fn get_custom_menu_link(
        &self,
        custom_menu_id: &str,
    ) -> Result<models::GetSingleCustomMenusSuccessfulResponseDTO> {
        let path = format!("/custom-menus/{}", crate::services::encode(custom_menu_id));
        let query = Vec::new();
        self.client
            .send_versioned(
                reqwest::Method::GET,
                &path,
                &query,
                None::<&()>,
                Some("2021-07-28"),
            )
            .await
    }

    /// Update Custom Menu Link
    ///
    /// Updates an existing custom menu for a given company. Requires authentication and
    /// proper permissions.
    ///
    /// `PUT /custom-menus/{customMenuId}`
    ///
    /// Requires scope: `custom-menu-link.write`.
    pub async fn update_custom_menu_link(
        &self,
        custom_menu_id: &str,
        body: &models::UpdateCustomMenuDTO,
    ) -> Result<models::UpdateCustomMenuLinkResponseDTO> {
        let path = format!("/custom-menus/{}", crate::services::encode(custom_menu_id));
        let query = Vec::new();
        self.client
            .send_versioned(
                reqwest::Method::PUT,
                &path,
                &query,
                Some(body),
                Some("2021-07-28"),
            )
            .await
    }
}