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

#![allow(clippy::too_many_arguments)]

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

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

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

/// Query parameters for [`ProposalsService::list_documents`].
#[derive(Debug, Clone, Default)]
pub struct ListDocumentsParams {
    /// Location Id
    /// Required by the API.
    pub location_id: String,
    /// Document status, pass as comma separated values
    /// Allowed values: `draft`, `sent`, `viewed`, `completed`, `accepted`.
    pub status: Option<String>,
    /// Payment status, pass as comma separated values
    /// Allowed values: `waiting_for_payment`, `paid`, `no_payment`.
    pub payment_status: Option<String>,
    /// Limit to fetch number of records
    pub limit: Option<f64>,
    /// Skip number of records
    pub skip: Option<f64>,
    /// Search string
    pub query: Option<String>,
    /// Date start from (ISO 8601), dateFrom & DateTo must be provided together
    pub date_from: Option<String>,
    /// Date to (ISO 8601), dateFrom & DateTo must be provided together
    pub date_to: Option<String>,
}

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

    /// Document status, pass as comma separated values
    pub fn status(mut self, v: impl Into<String>) -> Self {
        self.status = Some(v.into());
        self
    }

    /// Payment status, pass as comma separated values
    pub fn payment_status(mut self, v: impl Into<String>) -> Self {
        self.payment_status = Some(v.into());
        self
    }

    /// Limit to fetch number of records
    pub fn limit(mut self, v: f64) -> Self {
        self.limit = Some(v);
        self
    }

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

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

    /// Date start from (ISO 8601), dateFrom & DateTo must be provided together
    pub fn date_from(mut self, v: impl Into<String>) -> Self {
        self.date_from = Some(v.into());
        self
    }

    /// Date to (ISO 8601), dateFrom & DateTo must be provided together
    pub fn date_to(mut self, v: impl Into<String>) -> Self {
        self.date_to = Some(v.into());
        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.status {
            q.push(("status".into(), v.to_string()));
        }
        if let Some(v) = &self.payment_status {
            q.push(("paymentStatus".into(), v.to_string()));
        }
        if let Some(v) = &self.limit {
            q.push(("limit".into(), v.to_string()));
        }
        if let Some(v) = &self.skip {
            q.push(("skip".into(), v.to_string()));
        }
        if let Some(v) = &self.query {
            q.push(("query".into(), v.to_string()));
        }
        if let Some(v) = &self.date_from {
            q.push(("dateFrom".into(), v.to_string()));
        }
        if let Some(v) = &self.date_to {
            q.push(("dateTo".into(), v.to_string()));
        }
        q
    }
}

/// Query parameters for [`ProposalsService::list_templates`].
#[derive(Debug, Clone, Default)]
pub struct ListTemplatesParams {
    /// Location Id
    /// Required by the API.
    pub location_id: String,
    /// Date start from (ISO 8601)
    pub date_from: Option<String>,
    /// Date to (ISO 8601)
    pub date_to: Option<String>,
    /// Comma-separated template types. Valid values: proposal, estimate, contentLibrary
    pub type_: Option<String>,
    /// Template Name
    pub name: Option<String>,
    /// If the docForm is a DocForm
    pub is_public_document: Option<bool>,
    /// User Id, required when isPublicDocument is true
    pub user_id: Option<String>,
    /// Limit
    pub limit: Option<String>,
    /// Skip
    pub skip: Option<String>,
}

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

    /// Date start from (ISO 8601)
    pub fn date_from(mut self, v: impl Into<String>) -> Self {
        self.date_from = Some(v.into());
        self
    }

    /// Date to (ISO 8601)
    pub fn date_to(mut self, v: impl Into<String>) -> Self {
        self.date_to = Some(v.into());
        self
    }

    /// Comma-separated template types. Valid values: proposal, estimate, contentLibrary
    pub fn type_(mut self, v: impl Into<String>) -> Self {
        self.type_ = Some(v.into());
        self
    }

    /// Template Name
    pub fn name(mut self, v: impl Into<String>) -> Self {
        self.name = Some(v.into());
        self
    }

    /// If the docForm is a DocForm
    pub fn is_public_document(mut self, v: bool) -> Self {
        self.is_public_document = Some(v);
        self
    }

    /// User Id, required when isPublicDocument is true
    pub fn user_id(mut self, v: impl Into<String>) -> Self {
        self.user_id = Some(v.into());
        self
    }

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

    /// Skip
    pub fn skip(mut self, v: impl Into<String>) -> Self {
        self.skip = Some(v.into());
        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.date_from {
            q.push(("dateFrom".into(), v.to_string()));
        }
        if let Some(v) = &self.date_to {
            q.push(("dateTo".into(), v.to_string()));
        }
        if let Some(v) = &self.type_ {
            q.push(("type".into(), v.to_string()));
        }
        if let Some(v) = &self.name {
            q.push(("name".into(), v.to_string()));
        }
        if let Some(v) = &self.is_public_document {
            q.push(("isPublicDocument".into(), v.to_string()));
        }
        if let Some(v) = &self.user_id {
            q.push(("userId".into(), v.to_string()));
        }
        if let Some(v) = &self.limit {
            q.push(("limit".into(), v.to_string()));
        }
        if let Some(v) = &self.skip {
            q.push(("skip".into(), v.to_string()));
        }
        q
    }
}

impl ProposalsService {
    /// List documents
    ///
    /// List documents for a location
    ///
    /// `GET /proposals/document`
    pub async fn list_documents(
        &self,
        params: &ListDocumentsParams,
    ) -> Result<models::DocumentListResponseDto> {
        let query = params.to_query();
        self.client
            .send_versioned(
                reqwest::Method::GET,
                "/proposals/document",
                &query,
                None::<&()>,
                Some("v3"),
            )
            .await
    }

    /// Send document
    ///
    /// Send document to a client
    ///
    /// `POST /proposals/document/send`
    pub async fn send_document(
        &self,
        body: &models::SendDocumentDto,
    ) -> Result<models::SendDocumentResponseDto> {
        let query = Vec::new();
        self.client
            .send_versioned(
                reqwest::Method::POST,
                "/proposals/document/send",
                &query,
                Some(body),
                Some("v3"),
            )
            .await
    }

    /// List templates
    ///
    /// List document contract templates for a location
    ///
    /// `GET /proposals/templates`
    pub async fn list_templates(
        &self,
        params: &ListTemplatesParams,
    ) -> Result<models::TemplateListPaginationResponseDTO> {
        let query = params.to_query();
        self.client
            .send_versioned(
                reqwest::Method::GET,
                "/proposals/templates",
                &query,
                None::<&()>,
                Some("v3"),
            )
            .await
    }

    /// Send template
    ///
    /// Send template to a client
    ///
    /// `POST /proposals/templates/send`
    pub async fn send_template(
        &self,
        body: &models::SendDocumentFromPublicApiBodyDto,
    ) -> Result<models::SendTemplateResponseDto> {
        let query = Vec::new();
        self.client
            .send_versioned(
                reqwest::Method::POST,
                "/proposals/templates/send",
                &query,
                Some(body),
                Some("v3"),
            )
            .await
    }
}