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

#![allow(clippy::too_many_arguments)]

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

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

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

/// Query parameters for [`SnapshotsService::get_snapshots`].
#[derive(Debug, Clone, Default)]
pub struct GetSnapshotsParams {
    /// Company Id
    /// Required by the API.
    pub company_id: String,
}

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

    fn to_query(&self) -> Vec<(String, String)> {
        let q: Vec<(String, String)> = vec![("companyId".into(), self.company_id.clone())];
        q
    }
}

/// Query parameters for [`SnapshotsService::create_snapshot_share_link`].
#[derive(Debug, Clone, Default)]
pub struct CreateSnapshotShareLinkParams {
    /// `companyId` query parameter.
    /// Required by the API.
    pub company_id: String,
}

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

    fn to_query(&self) -> Vec<(String, String)> {
        let q: Vec<(String, String)> = vec![("companyId".into(), self.company_id.clone())];
        q
    }
}

/// Query parameters for [`SnapshotsService::get_snapshot_push_between_dates`].
#[derive(Debug, Clone, Default)]
pub struct GetSnapshotPushBetweenDatesParams {
    /// `companyId` query parameter.
    /// Required by the API.
    pub company_id: String,
    /// Only accepts ISO 8601 format
    /// Required by the API.
    pub from_: String,
    /// Only accepts ISO 8601 format
    /// Required by the API.
    pub to: String,
    /// Id for last document till what you want to skip
    /// Required by the API.
    pub last_doc: String,
    /// Limit of documents to return. Default is 20
    pub limit: Option<String>,
}

impl GetSnapshotPushBetweenDatesParams {
    /// Start from the parameters the API requires.
    pub fn new(
        company_id: impl Into<String>,
        from_: impl Into<String>,
        to: impl Into<String>,
        last_doc: impl Into<String>,
    ) -> Self {
        Self {
            company_id: company_id.into(),
            from_: from_.into(),
            to: to.into(),
            last_doc: last_doc.into(),
            ..Default::default()
        }
    }

    /// Limit of documents to return. Default is 20
    pub fn limit(mut self, v: impl Into<String>) -> Self {
        self.limit = Some(v.into());
        self
    }

    fn to_query(&self) -> Vec<(String, String)> {
        let mut q: Vec<(String, String)> = vec![
            ("companyId".into(), self.company_id.clone()),
            ("from".into(), self.from_.clone()),
            ("to".into(), self.to.clone()),
            ("lastDoc".into(), self.last_doc.clone()),
        ];
        if let Some(v) = &self.limit {
            q.push(("limit".into(), v.to_string()));
        }
        q
    }
}

/// Query parameters for [`SnapshotsService::get_last_snapshot_push`].
#[derive(Debug, Clone, Default)]
pub struct GetLastSnapshotPushParams {
    /// `companyId` query parameter.
    /// Required by the API.
    pub company_id: String,
}

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

    fn to_query(&self) -> Vec<(String, String)> {
        let q: Vec<(String, String)> = vec![("companyId".into(), self.company_id.clone())];
        q
    }
}

impl SnapshotsService {
    /// Get Snapshots
    ///
    /// Get a list of all own and imported Snapshots
    ///
    /// `GET /snapshots/`
    pub async fn get_snapshots(
        &self,
        params: &GetSnapshotsParams,
    ) -> Result<models::GetSnapshotsSuccessfulResponseDto> {
        let query = params.to_query();
        self.client
            .send_versioned(
                reqwest::Method::GET,
                "/snapshots/",
                &query,
                None::<&()>,
                Some("v3"),
            )
            .await
    }

    /// Create Snapshot Share Link
    ///
    /// Create a share link for snapshot
    ///
    /// `POST /snapshots/share/link`
    pub async fn create_snapshot_share_link(
        &self,
        params: &CreateSnapshotShareLinkParams,
        body: &models::CreateSnapshotShareLinkRequestDTO,
    ) -> Result<models::CreateSnapshotShareLinkSuccessfulResponseDTO> {
        let query = params.to_query();
        self.client
            .send_versioned(
                reqwest::Method::POST,
                "/snapshots/share/link",
                &query,
                Some(body),
                Some("v3"),
            )
            .await
    }

    /// Get Snapshot Push between Dates
    ///
    /// Get list of sub-accounts snapshot pushed in time period
    ///
    /// `GET /snapshots/snapshot-status/{snapshotId}`
    pub async fn get_snapshot_push_between_dates(
        &self,
        snapshot_id: &str,
        params: &GetSnapshotPushBetweenDatesParams,
    ) -> Result<models::GetSnapshotPushStatusSuccessfulResponseDTO> {
        let path = format!(
            "/snapshots/snapshot-status/{}",
            crate::services::encode(snapshot_id)
        );
        let query = params.to_query();
        self.client
            .send_versioned(reqwest::Method::GET, &path, &query, None::<&()>, Some("v3"))
            .await
    }

    /// Get Last Snapshot Push
    ///
    /// Get Latest Snapshot Push Status for a location id
    ///
    /// `GET /snapshots/snapshot-status/{snapshotId}/location/{locationId}`
    pub async fn get_last_snapshot_push(
        &self,
        snapshot_id: &str,
        location_id: &str,
        params: &GetLastSnapshotPushParams,
    ) -> Result<models::GetLatestSnapshotPushStatusSuccessfulResponseDTO> {
        let path = format!(
            "/snapshots/snapshot-status/{}/location/{}",
            crate::services::encode(snapshot_id),
            crate::services::encode(location_id)
        );
        let query = params.to_query();
        self.client
            .send_versioned(reqwest::Method::GET, &path, &query, None::<&()>, Some("v3"))
            .await
    }
}