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

#![allow(clippy::too_many_arguments)]

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

/// Typed access to the `marketplace` API v2 surface (9 operations). Obtained via
/// [`Ghl::marketplace`](crate::Ghl::marketplace).
#[derive(Debug, Clone)]
pub struct MarketplaceService {
    pub(crate) client: Ghl,
}

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

/// Query parameters for [`MarketplaceService::get_all_wallet_charges`].
#[derive(Debug, Clone, Default)]
pub struct GetAllWalletChargesParams {
    /// Billing Meter ID (you can find this on your app's pricing page on the developer
    /// portal)
    pub meter_id: Option<String>,
    /// Event ID / Transaction ID
    pub event_id: Option<String>,
    /// Filter results by User ID that your server passed via API when the charge was
    /// created
    pub user_id: Option<String>,
    /// Filter results AFTER a specific date. Use this in combination with endDate to filter
    /// results in a specific time window.
    pub start_date: Option<String>,
    /// Filter results BEFORE a specific date. Use this in combination with startDate to
    /// filter results in a specific time window.
    pub end_date: Option<String>,
    /// Number of records to skip
    pub skip: Option<f64>,
    /// Maximum number of records to return
    pub limit: Option<f64>,
}

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

    /// Billing Meter ID (you can find this on your app's pricing page on the developer
    /// portal)
    pub fn meter_id(mut self, v: impl Into<String>) -> Self {
        self.meter_id = Some(v.into());
        self
    }

    /// Event ID / Transaction ID
    pub fn event_id(mut self, v: impl Into<String>) -> Self {
        self.event_id = Some(v.into());
        self
    }

    /// Filter results by User ID that your server passed via API when the charge was
    /// created
    pub fn user_id(mut self, v: impl Into<String>) -> Self {
        self.user_id = Some(v.into());
        self
    }

    /// Filter results AFTER a specific date. Use this in combination with endDate to filter
    /// results in a specific time window.
    pub fn start_date(mut self, v: impl Into<String>) -> Self {
        self.start_date = Some(v.into());
        self
    }

    /// Filter results BEFORE a specific date. Use this in combination with startDate to
    /// filter results in a specific time window.
    pub fn end_date(mut self, v: impl Into<String>) -> Self {
        self.end_date = Some(v.into());
        self
    }

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

    /// Maximum number of records to return
    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::new();
        if let Some(v) = &self.meter_id {
            q.push(("meterId".into(), v.to_string()));
        }
        if let Some(v) = &self.event_id {
            q.push(("eventId".into(), v.to_string()));
        }
        if let Some(v) = &self.user_id {
            q.push(("userId".into(), v.to_string()));
        }
        if let Some(v) = &self.start_date {
            q.push(("startDate".into(), v.to_string()));
        }
        if let Some(v) = &self.end_date {
            q.push(("endDate".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 MarketplaceService {
    /// Uninstall an application
    ///
    /// Uninstalls an application from your company or a specific location. This will remove
    /// the application`s access and stop all its functionalities
    ///
    /// `DELETE /marketplace/app/{appId}/installations`
    ///
    /// Requires scope: `oauth.write`.
    pub async fn uninstall_an_application(
        &self,
        app_id: &str,
        body: &models::DeleteIntegrationBodyDto,
    ) -> Result<models::DeleteIntegrationResponse> {
        let path = format!(
            "/marketplace/app/{}/installations",
            crate::services::encode(app_id)
        );
        let query = Vec::new();
        self.client
            .send_versioned(
                reqwest::Method::DELETE,
                &path,
                &query,
                Some(body),
                Some("2021-07-28"),
            )
            .await
    }

    /// Get Installer Details
    ///
    /// Fetches installer details for the authenticated user. This endpoint returns
    /// information about the company, location, user, and installation details associated
    /// with the current OAuth token.
    ///
    /// `GET /marketplace/app/{appId}/installations`
    ///
    /// Requires scope: `marketplace-installer-details.readonly`.
    pub async fn get_installer_details(
        &self,
        app_id: &str,
    ) -> Result<models::GetInstallerDetailsResponseDTO> {
        let path = format!(
            "/marketplace/app/{}/installations",
            crate::services::encode(app_id)
        );
        let query = Vec::new();
        self.client
            .send_versioned(
                reqwest::Method::GET,
                &path,
                &query,
                None::<&()>,
                Some("2021-07-28"),
            )
            .await
    }

    /// Get rebilling config for an app subscription and usage plans
    ///
    /// Get rebilling config for an app subscription and usage plans for the authenticated
    /// sub-account. This endpoint returns the subscription and usage plans for an app.
    ///
    /// `GET /marketplace/app/{appId}/rebilling-config/location/{locationId}`
    ///
    /// Requires scope: `oauth.readonly`.
    pub async fn get_rebilling_config_for_an_app_subscription_and_usage_plans(
        &self,
        app_id: &str,
        location_id: &str,
    ) -> Result<models::GetRebillingConfigResponseDTO> {
        let path = format!(
            "/marketplace/app/{}/rebilling-config/location/{}",
            crate::services::encode(app_id),
            crate::services::encode(location_id)
        );
        let query = Vec::new();
        self.client
            .send_versioned(
                reqwest::Method::GET,
                &path,
                &query,
                None::<&()>,
                Some("2021-07-28"),
            )
            .await
    }

    /// Get all wallet charges
    ///
    /// `GET /marketplace/billing/charges`
    ///
    /// Requires scope: `charges.readonly`.
    pub async fn get_all_wallet_charges(
        &self,
        params: &GetAllWalletChargesParams,
    ) -> Result<serde_json::Value> {
        let query = params.to_query();
        self.client
            .send_versioned(
                reqwest::Method::GET,
                "/marketplace/billing/charges",
                &query,
                None::<&()>,
                None,
            )
            .await
    }

    /// Create a new wallet charge
    ///
    /// `POST /marketplace/billing/charges`
    ///
    /// Requires scope: `charges.write`.
    pub async fn create_a_new_wallet_charge(
        &self,
        body: &models::RaiseChargeBodyDTO,
    ) -> Result<serde_json::Value> {
        let query = Vec::new();
        self.client
            .send_versioned(
                reqwest::Method::POST,
                "/marketplace/billing/charges",
                &query,
                Some(body),
                None,
            )
            .await
    }

    /// Check if account has sufficient funds
    ///
    /// `GET /marketplace/billing/charges/has-funds`
    ///
    /// Requires scope: `charges.readonly`.
    pub async fn check_if_account_has_sufficient_funds(&self) -> Result<serde_json::Value> {
        let query = Vec::new();
        self.client
            .send_versioned(
                reqwest::Method::GET,
                "/marketplace/billing/charges/has-funds",
                &query,
                None::<&()>,
                None,
            )
            .await
    }

    /// Delete a wallet charge
    ///
    /// `DELETE /marketplace/billing/charges/{chargeId}`
    ///
    /// Requires scope: `charges.write`.
    pub async fn delete_a_wallet_charge(&self, charge_id: &str) -> Result<serde_json::Value> {
        let path = format!(
            "/marketplace/billing/charges/{}",
            crate::services::encode(charge_id)
        );
        let query = Vec::new();
        self.client
            .send_versioned(reqwest::Method::DELETE, &path, &query, None::<&()>, None)
            .await
    }

    /// Get specific wallet charge details
    ///
    /// `GET /marketplace/billing/charges/{chargeId}`
    ///
    /// Requires scope: `charges.readonly`.
    pub async fn get_specific_wallet_charge_details(
        &self,
        charge_id: &str,
    ) -> Result<serde_json::Value> {
        let path = format!(
            "/marketplace/billing/charges/{}",
            crate::services::encode(charge_id)
        );
        let query = Vec::new();
        self.client
            .send_versioned(reqwest::Method::GET, &path, &query, None::<&()>, None)
            .await
    }

    /// Migrate external authentication connection
    ///
    /// Migrates an external authentication connection credentials (basic or oauth2) for a
    /// specific app and location. This endpoint validates the app configuration, stores
    /// credentials safely in CRM's native encrypted storage. With this the lifecycle of the
    /// token is managed by CRM.
    ///
    /// `POST /marketplace/external-auth/migration`
    ///
    /// Requires scope: `marketplace-external-auth-migration.write`.
    pub async fn migrate_external_authentication_connection(
        &self,
        body: &models::MigrateConnectionDto,
    ) -> Result<models::MigrateConnectionResponseDto> {
        let query = Vec::new();
        self.client
            .send_versioned(
                reqwest::Method::POST,
                "/marketplace/external-auth/migration",
                &query,
                Some(body),
                Some("2021-07-28"),
            )
            .await
    }
}