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 LocationsApi {
    http: Arc<HttpClient>,
}

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

    pub async fn get(&self, location_id: &str) -> Result<GetLocationResponse> {
        self.http.get(&format!("/locations/{location_id}")).await
    }

    pub async fn search(&self, params: &SearchLocationsParams) -> Result<SearchLocationsResponse> {
        self.http.get_with_query("/locations/search", params).await
    }

    pub async fn create(&self, params: &CreateLocationParams) -> Result<GetLocationResponse> {
        self.http.post("/locations", params).await
    }

    pub async fn update(
        &self,
        location_id: &str,
        params: &UpdateLocationParams,
    ) -> Result<GetLocationResponse> {
        self.http
            .put(&format!("/locations/{location_id}"), params)
            .await
    }

    pub async fn delete(&self, location_id: &str) -> Result<DeleteLocationResponse> {
        self.http.delete(&format!("/locations/{location_id}")).await
    }

    // ── Custom Fields ─────────────────────────────────────────────────────────

    pub async fn get_custom_fields(&self, location_id: &str) -> Result<GetCustomFieldsResponse> {
        self.http
            .get(&format!("/locations/{location_id}/customFields"))
            .await
    }

    pub async fn get_custom_field(
        &self,
        location_id: &str,
        field_id: &str,
    ) -> Result<GetCustomFieldResponse> {
        self.http
            .get(&format!("/locations/{location_id}/customFields/{field_id}"))
            .await
    }

    pub async fn create_custom_field(
        &self,
        location_id: &str,
        params: &CreateCustomFieldParams,
    ) -> Result<GetCustomFieldResponse> {
        self.http
            .post(&format!("/locations/{location_id}/customFields"), params)
            .await
    }

    pub async fn update_custom_field(
        &self,
        location_id: &str,
        field_id: &str,
        params: &CreateCustomFieldParams,
    ) -> Result<GetCustomFieldResponse> {
        self.http
            .put(
                &format!("/locations/{location_id}/customFields/{field_id}"),
                params,
            )
            .await
    }

    pub async fn delete_custom_field(&self, location_id: &str, field_id: &str) -> Result<()> {
        self.http
            .delete_no_content(&format!("/locations/{location_id}/customFields/{field_id}"))
            .await
    }

    // ── Tags ─────────────────────────────────────────────────────────────────

    pub async fn get_tags(&self, location_id: &str) -> Result<GetTagsResponse> {
        self.http
            .get(&format!("/locations/{location_id}/tags"))
            .await
    }

    pub async fn get_tag(&self, location_id: &str, tag_id: &str) -> Result<GetTagResponse> {
        self.http
            .get(&format!("/locations/{location_id}/tags/{tag_id}"))
            .await
    }

    pub async fn create_tag(
        &self,
        location_id: &str,
        params: &CreateTagParams,
    ) -> Result<GetTagResponse> {
        self.http
            .post(&format!("/locations/{location_id}/tags"), params)
            .await
    }

    pub async fn update_tag(
        &self,
        location_id: &str,
        tag_id: &str,
        params: &CreateTagParams,
    ) -> Result<GetTagResponse> {
        self.http
            .put(&format!("/locations/{location_id}/tags/{tag_id}"), params)
            .await
    }

    pub async fn delete_tag(&self, location_id: &str, tag_id: &str) -> Result<()> {
        self.http
            .delete_no_content(&format!("/locations/{location_id}/tags/{tag_id}"))
            .await
    }
}