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 v2 operations
//! in this module.
//!
//! Access via [`Ghl::phone_system`](crate::Ghl::phone_system).
//!
//! Request and response types come from [`ghl_models::v2::phone_system`](https://docs.rs/ghl-models/latest/ghl_models/v2/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::v2::phone_system as models;

/// Typed access to the `phone-system` API v2 surface (4 operations). Obtained via
/// [`Ghl::phone_system`](crate::Ghl::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 filter pools
    pub location_id: Option<String>,
}

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

    /// Location ID to filter pools
    pub fn location_id(mut self, v: impl Into<String>) -> Self {
        self.location_id = Some(v.into());
        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()));
        }
        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 for pagination. The default is 0.
    pub page: Option<f64>,
    /// Filter numbers by phone number pattern. Supports partial matching (e.g., "+91" to
    /// find all Indian numbers).
    pub search_filter: Option<String>,
    /// Whether to exclude numbers that are assigned to number pools. Default is true.
    pub skip_number_pool: 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 for pagination. The default is 0.
    pub fn page(mut self, v: f64) -> Self {
        self.page = Some(v);
        self
    }

    /// Filter numbers by phone number pattern. Supports partial matching (e.g., "+91" to
    /// find all Indian numbers).
    pub fn search_filter(mut self, v: impl Into<String>) -> Self {
        self.search_filter = Some(v.into());
        self
    }

    /// Whether to exclude numbers that are assigned to number pools. Default is true.
    pub fn skip_number_pool(mut self, v: bool) -> Self {
        self.skip_number_pool = 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()));
        }
        q
    }
}

/// Query parameters for [`PhoneSystemService::list_available_phone_numbers`].
#[derive(Debug, Clone, Default)]
pub struct ListAvailablePhoneNumbersParams {
    /// ISO 3166-1 alpha-2 country code for which to search available numbers
    /// Required by the API.
    pub country_code: String,
    /// Comma-separated list of phone number types to search for (e.g. local, tollFree,
    /// mobile)
    pub number_types: Option<String>,
    /// Filter numbers that begin with this digit pattern
    pub first_part: Option<String>,
    /// Filter numbers that end with this digit pattern
    pub last_part: Option<String>,
    /// Filter numbers that contain this digit pattern anywhere
    pub anywhere: Option<String>,
    /// Filter for numbers with SMS capability
    pub sms_enabled: Option<bool>,
    /// Filter for numbers with MMS capability
    pub mms_enabled: Option<bool>,
    /// Filter for numbers with voice capability
    pub voice_enabled: Option<bool>,
}

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

    /// Comma-separated list of phone number types to search for (e.g. local, tollFree,
    /// mobile)
    pub fn number_types(mut self, v: impl Into<String>) -> Self {
        self.number_types = Some(v.into());
        self
    }

    /// Filter numbers that begin with this digit pattern
    pub fn first_part(mut self, v: impl Into<String>) -> Self {
        self.first_part = Some(v.into());
        self
    }

    /// Filter numbers that end with this digit pattern
    pub fn last_part(mut self, v: impl Into<String>) -> Self {
        self.last_part = Some(v.into());
        self
    }

    /// Filter numbers that contain this digit pattern anywhere
    pub fn anywhere(mut self, v: impl Into<String>) -> Self {
        self.anywhere = Some(v.into());
        self
    }

    /// Filter for numbers with SMS capability
    pub fn sms_enabled(mut self, v: bool) -> Self {
        self.sms_enabled = Some(v);
        self
    }

    /// Filter for numbers with MMS capability
    pub fn mms_enabled(mut self, v: bool) -> Self {
        self.mms_enabled = Some(v);
        self
    }

    /// Filter for numbers with voice capability
    pub fn voice_enabled(mut self, v: bool) -> Self {
        self.voice_enabled = Some(v);
        self
    }

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

impl PhoneSystemService {
    /// List Number Pools
    ///
    /// Get list of number pools
    ///
    /// `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("2021-07-28"),
            )
            .await
    }

    /// List active numbers
    ///
    /// Retrieve a paginated list of active phone numbers for a specific location. Supports
    /// filtering, pagination, and optional exclusion of number pool assignments.
    ///
    /// `GET /phone-system/numbers/location/{locationId}`
    ///
    /// Requires scope: `phonenumbers.read`.
    pub async fn list_active_numbers(
        &self,
        location_id: &str,
        params: &ListActiveNumbersParams,
    ) -> Result<serde_json::Value> {
        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("2021-07-28"),
            )
            .await
    }

    /// List available phone numbers
    ///
    /// Search for available phone numbers to purchase for a specific location. Supports
    /// filtering by number pattern, type, and capabilities.
    ///
    /// `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<models::AvailableNumbersResponseDto> {
        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("2021-07-28"),
            )
            .await
    }

    /// Purchase a phone number
    ///
    /// Purchase a phone number for a specific location.
    ///
    /// `POST /phone-system/numbers/location/{locationId}/purchase`
    ///
    /// Requires scope: `phonenumbers.write`.
    pub async fn purchase_a_phone_number(
        &self,
        location_id: &str,
        body: &models::PurchasePhoneNumberBodyDto,
    ) -> Result<models::TwilioAccountResponseDto> {
        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("2021-07-28"),
            )
            .await
    }
}