highlevel-api 0.2.0

Unofficial Rust SDK for the GoHighLevel (HighLevel) API
Documentation
use super::types::*;
use crate::{error::Result, http::HttpClient};
use std::sync::Arc;

pub struct ObjectsApi {
    http: Arc<HttpClient>,
}

impl ObjectsApi {
    pub fn new(http: Arc<HttpClient>) -> Self {
        Self { http }
    }

    // ── Schemas ──────────────────────────────────────────────────────────────

    pub async fn list_schemas(&self, params: &ListSchemasParams) -> Result<ListSchemasResponse> {
        self.http.get_with_query("/objects/", params).await
    }

    pub async fn get_schema(&self, schema_key: &str) -> Result<GetSchemaResponse> {
        self.http.get(&format!("/objects/{schema_key}")).await
    }

    pub async fn create_schema(&self, params: &CreateSchemaParams) -> Result<GetSchemaResponse> {
        self.http.post("/objects/", params).await
    }

    pub async fn update_schema(
        &self,
        schema_key: &str,
        params: &UpdateSchemaParams,
    ) -> Result<GetSchemaResponse> {
        self.http
            .put(&format!("/objects/{schema_key}"), params)
            .await
    }

    // ── Records ──────────────────────────────────────────────────────────────

    pub async fn create_record(
        &self,
        schema_key: &str,
        params: &CreateRecordParams,
    ) -> Result<CreateRecordResponse> {
        self.http
            .post(&format!("/objects/{schema_key}/records"), params)
            .await
    }

    pub async fn get_record(&self, schema_key: &str, record_id: &str) -> Result<GetRecordResponse> {
        self.http
            .get(&format!("/objects/{schema_key}/records/{record_id}"))
            .await
    }

    pub async fn update_record(
        &self,
        schema_key: &str,
        record_id: &str,
        params: &UpdateRecordParams,
    ) -> Result<GetRecordResponse> {
        self.http
            .put(
                &format!("/objects/{schema_key}/records/{record_id}"),
                params,
            )
            .await
    }

    pub async fn delete_record(
        &self,
        schema_key: &str,
        record_id: &str,
    ) -> Result<DeleteRecordResponse> {
        self.http
            .delete(&format!("/objects/{schema_key}/records/{record_id}"))
            .await
    }

    pub async fn search_records(
        &self,
        schema_key: &str,
        params: &SearchRecordsParams,
    ) -> Result<SearchRecordsResponse> {
        self.http
            .post(&format!("/objects/{schema_key}/records/search"), params)
            .await
    }
}