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

#![allow(clippy::too_many_arguments)]

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

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

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

/// Query parameters for [`LinksService::get_links`].
#[derive(Debug, Clone, Default)]
pub struct GetLinksParams {
    /// Location ID of the business profile
    /// Required by the API.
    pub location_id: String,
}

impl GetLinksParams {
    /// 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 [`LinksService::get_link_by_id`].
#[derive(Debug, Clone, Default)]
pub struct GetLinkByIdParams {
    /// Location Id
    /// Required by the API.
    pub location_id: String,
}

impl GetLinkByIdParams {
    /// 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 [`LinksService::search_trigger_links`].
#[derive(Debug, Clone, Default)]
pub struct SearchTriggerLinksParams {
    /// Location Id
    /// Required by the API.
    pub location_id: String,
    /// Search query as a string
    pub query: Option<String>,
    /// Numbers of query results to skip
    pub skip: Option<f64>,
    /// Limit on number of search results
    pub limit: Option<f64>,
}

impl SearchTriggerLinksParams {
    /// Start from the parameters the API requires.
    pub fn new(location_id: impl Into<String>) -> Self {
        Self {
            location_id: location_id.into(),
            ..Default::default()
        }
    }

    /// Search query as a string
    pub fn query(mut self, v: impl Into<String>) -> Self {
        self.query = Some(v.into());
        self
    }

    /// Numbers of query results to skip
    pub fn skip(mut self, v: f64) -> Self {
        self.skip = Some(v);
        self
    }

    /// Limit on number of search results
    pub fn limit(mut self, v: f64) -> Self {
        self.limit = Some(v);
        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.query {
            q.push(("query".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()));
        }
        q
    }
}

impl LinksService {
    /// Get Links
    ///
    /// `GET /links/`
    ///
    /// Requires scope: `links.readonly`.
    pub async fn get_links(
        &self,
        params: &GetLinksParams,
    ) -> Result<models::GetLinksSuccessfulResponseDto> {
        let query = params.to_query();
        self.client
            .send_versioned(
                reqwest::Method::GET,
                "/links/",
                &query,
                None::<&()>,
                Some("v3"),
            )
            .await
    }

    /// Create Link
    ///
    /// `POST /links/`
    ///
    /// Requires scope: `links.write`.
    pub async fn create_link(
        &self,
        body: &models::LinksDto,
    ) -> Result<models::GetLinkSuccessfulResponseDto> {
        let query = Vec::new();
        self.client
            .send_versioned(
                reqwest::Method::POST,
                "/links/",
                &query,
                Some(body),
                Some("v3"),
            )
            .await
    }

    /// Get Link by ID
    ///
    /// Get a single link by its ID
    ///
    /// `GET /links/id/{linkId}`
    ///
    /// Requires scope: `links.readonly`.
    pub async fn get_link_by_id(
        &self,
        link_id: &str,
        params: &GetLinkByIdParams,
    ) -> Result<models::GetLinkSuccessfulResponseDto> {
        let path = format!("/links/id/{}", crate::services::encode(link_id));
        let query = params.to_query();
        self.client
            .send_versioned(reqwest::Method::GET, &path, &query, None::<&()>, Some("v3"))
            .await
    }

    /// Search Trigger Links
    ///
    /// Get list of links by searching
    ///
    /// `GET /links/search`
    ///
    /// Requires scope: `links.readonly`.
    pub async fn search_trigger_links(
        &self,
        params: &SearchTriggerLinksParams,
    ) -> Result<models::GetLinksSuccessfulResponseDto> {
        let query = params.to_query();
        self.client
            .send_versioned(
                reqwest::Method::GET,
                "/links/search",
                &query,
                None::<&()>,
                Some("v3"),
            )
            .await
    }

    /// Delete Link
    ///
    /// `DELETE /links/{linkId}`
    ///
    /// Requires scope: `links.write`.
    pub async fn delete_link(
        &self,
        link_id: &str,
    ) -> Result<models::DeleteLinksSuccessfulResponseDto> {
        let path = format!("/links/{}", crate::services::encode(link_id));
        let query = Vec::new();
        self.client
            .send_versioned(
                reqwest::Method::DELETE,
                &path,
                &query,
                None::<&()>,
                Some("v3"),
            )
            .await
    }

    /// Update Link
    ///
    /// `PUT /links/{linkId}`
    ///
    /// Requires scope: `links.write`.
    pub async fn update_link(
        &self,
        link_id: &str,
        body: &models::LinkUpdateDto,
    ) -> Result<models::GetLinkSuccessfulResponseDto> {
        let path = format!("/links/{}", crate::services::encode(link_id));
        let query = Vec::new();
        self.client
            .send_versioned(reqwest::Method::PUT, &path, &query, Some(body), Some("v3"))
            .await
    }
}