ghl-sdk 0.5.0

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

#![allow(clippy::too_many_arguments)]

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

/// Typed access to the `phone-system` API v3 surface (4 operations). Obtained via
/// [`Ghl::v3`](crate::Ghl::v3)`().phone_system()`.
#[derive(Debug, Clone)]
pub struct PhoneSystemService {
    pub(crate) client: Ghl,
}

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

/// Query parameters for [`PhoneSystemService::list_number_pools`].
#[derive(Debug, Clone, Default)]
pub struct ListNumberPoolsParams {
    /// Location ID to scope the number pool list
    /// Required by the API.
    pub location_id: String,
}

impl ListNumberPoolsParams {
    /// 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 [`PhoneSystemService::list_active_numbers`].
#[derive(Debug, Clone, Default)]
pub struct ListActiveNumbersParams {
    /// How many resources to return in each list page. The default is 50, and the maximum
    /// is 1000.
    pub page_size: Option<f64>,
    /// The page index. The default is 0.
    pub page: Option<f64>,
    /// Number search Filter
    pub search_filter: Option<String>,
    /// When true, exclude numbers assigned to number pools from the list.
    pub skip_number_pool: Option<bool>,
    /// Include RCS Sender IDs
    pub include_rcs_sender_ids: Option<bool>,
}

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

    /// How many resources to return in each list page. The default is 50, and the maximum
    /// is 1000.
    pub fn page_size(mut self, v: f64) -> Self {
        self.page_size = Some(v);
        self
    }

    /// The page index. The default is 0.
    pub fn page(mut self, v: f64) -> Self {
        self.page = Some(v);
        self
    }

    /// Number search Filter
    pub fn search_filter(mut self, v: impl Into<String>) -> Self {
        self.search_filter = Some(v.into());
        self
    }

    /// When true, exclude numbers assigned to number pools from the list.
    pub fn skip_number_pool(mut self, v: bool) -> Self {
        self.skip_number_pool = Some(v);
        self
    }

    /// Include RCS Sender IDs
    pub fn include_rcs_sender_ids(mut self, v: bool) -> Self {
        self.include_rcs_sender_ids = Some(v);
        self
    }

    fn to_query(&self) -> Vec<(String, String)> {
        let mut q: Vec<(String, String)> = Vec::new();
        if let Some(v) = &self.page_size {
            q.push(("pageSize".into(), v.to_string()));
        }
        if let Some(v) = &self.page {
            q.push(("page".into(), v.to_string()));
        }
        if let Some(v) = &self.search_filter {
            q.push(("searchFilter".into(), v.to_string()));
        }
        if let Some(v) = &self.skip_number_pool {
            q.push(("skipNumberPool".into(), v.to_string()));
        }
        if let Some(v) = &self.include_rcs_sender_ids {
            q.push(("includeRcsSenderIds".into(), v.to_string()));
        }
        q
    }
}

/// Query parameters for [`PhoneSystemService::list_available_phone_numbers`].
#[derive(Debug, Clone, Default)]
pub struct ListAvailablePhoneNumbersParams {
    /// firstPart is the beginning of the phone number
    /// Required by the API.
    pub first_part: String,
    /// lastPart is the ending of the phone number
    /// Required by the API.
    pub last_part: String,
    /// anywhere are the numbers required anywhere in phone number
    /// Required by the API.
    pub anywhere: String,
    /// comma separated types of phone number required
    /// Required by the API.
    pub number_types: String,
    /// requested phone numbers should have sms functionality
    /// Required by the API.
    pub sms_enabled: bool,
    /// requested phone numbers should have mms functionality
    /// Required by the API.
    pub mms_enabled: bool,
    /// requested phone numbers should have voice functionality
    /// Required by the API.
    pub voice_enabled: bool,
    /// country for which the phone numbers are being requested
    /// Required by the API.
    pub country_code: String,
}

impl ListAvailablePhoneNumbersParams {
    /// Start from the parameters the API requires.
    pub fn new(
        first_part: impl Into<String>,
        last_part: impl Into<String>,
        anywhere: impl Into<String>,
        number_types: impl Into<String>,
        sms_enabled: bool,
        mms_enabled: bool,
        voice_enabled: bool,
        country_code: impl Into<String>,
    ) -> Self {
        Self {
            first_part: first_part.into(),
            last_part: last_part.into(),
            anywhere: anywhere.into(),
            number_types: number_types.into(),
            sms_enabled,
            mms_enabled,
            voice_enabled,
            country_code: country_code.into(),
        }
    }

    fn to_query(&self) -> Vec<(String, String)> {
        let q: Vec<(String, String)> = vec![
            ("firstPart".into(), self.first_part.clone()),
            ("lastPart".into(), self.last_part.clone()),
            ("anywhere".into(), self.anywhere.clone()),
            ("numberTypes".into(), self.number_types.clone()),
            ("smsEnabled".into(), self.sms_enabled.to_string()),
            ("mmsEnabled".into(), self.mms_enabled.to_string()),
            ("voiceEnabled".into(), self.voice_enabled.to_string()),
            ("countryCode".into(), self.country_code.clone()),
        ];
        q
    }
}

impl PhoneSystemService {
    /// List number pools
    ///
    /// Returns number pools for the location. Requires locationId as a query parameter.
    ///
    /// `GET /phone-system/number-pools`
    ///
    /// Requires scope: `numberpools.read`.
    pub async fn list_number_pools(
        &self,
        params: &ListNumberPoolsParams,
    ) -> Result<serde_json::Value> {
        let query = params.to_query();
        self.client
            .send_versioned(
                reqwest::Method::GET,
                "/phone-system/number-pools",
                &query,
                None::<&()>,
                Some("v3"),
            )
            .await
    }

    /// List active numbers
    ///
    /// List active numbers. With `version: v3`, the HTTP 200 body is the standard success
    /// envelope (`status`, `data`, `message`, `statusCode`). The v3 list payload is under
    /// `data`; `isUnderGhl` is renamed to `isUnderLc` per AIP naming convention.
    ///
    /// `GET /phone-system/numbers/location/{locationId}`
    ///
    /// Requires scope: `phonenumbers.read`.
    pub async fn list_active_numbers(
        &self,
        location_id: &str,
        params: &ListActiveNumbersParams,
    ) -> Result<models::ListNumbersV3Http200ResponseDto> {
        let path = format!(
            "/phone-system/numbers/location/{}",
            crate::services::encode(location_id)
        );
        let query = params.to_query();
        self.client
            .send_versioned(reqwest::Method::GET, &path, &query, None::<&()>, Some("v3"))
            .await
    }

    /// List available phone numbers
    ///
    /// Search Twilio inventory for purchasable phone numbers in a country for the given
    /// location.
    ///
    /// `GET /phone-system/numbers/location/{locationId}/available`
    ///
    /// Requires scope: `phonenumbers.read`.
    pub async fn list_available_phone_numbers(
        &self,
        location_id: &str,
        params: &ListAvailablePhoneNumbersParams,
    ) -> Result<serde_json::Value> {
        let path = format!(
            "/phone-system/numbers/location/{}/available",
            crate::services::encode(location_id)
        );
        let query = params.to_query();
        self.client
            .send_versioned(reqwest::Method::GET, &path, &query, None::<&()>, Some("v3"))
            .await
    }

    /// Purchase number for location
    ///
    /// Purchase number for location. With `version: v3`, the HTTP 201 body is the standard
    /// success envelope (`status`, `data`, `message`, `statusCode`). The v3 purchase fields
    /// live under `data`: `number`, `locationId`, `id`, and `underLcAccount` (renamed from
    /// under_ghl_account).
    ///
    /// `POST /phone-system/numbers/location/{locationId}/purchase`
    ///
    /// Requires scope: `phonenumbers.write`.
    pub async fn purchase_number_for_location(
        &self,
        location_id: &str,
        body: &models::PurchasePhoneNumberBodyDto,
    ) -> Result<models::PurchaseNumberForLocationV3Http201ResponseDto> {
        let path = format!(
            "/phone-system/numbers/location/{}/purchase",
            crate::services::encode(location_id)
        );
        let query = Vec::new();
        self.client
            .send_versioned(reqwest::Method::POST, &path, &query, Some(body), Some("v3"))
            .await
    }
}