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

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

    // ── Calendars ─────────────────────────────────────────────────────────────

    pub async fn list(&self, location_id: &str) -> Result<GetCalendarsResponse> {
        #[derive(serde::Serialize)]
        struct Q<'a> {
            #[serde(rename = "locationId")]
            location_id: &'a str,
        }
        self.http
            .get_with_query("/calendars", &Q { location_id })
            .await
    }

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

    pub async fn create(&self, params: &CreateCalendarParams) -> Result<GetCalendarResponse> {
        self.http.post("/calendars", params).await
    }

    pub async fn update(
        &self,
        calendar_id: &str,
        params: &UpdateCalendarParams,
    ) -> Result<GetCalendarResponse> {
        self.http
            .put(&format!("/calendars/{calendar_id}"), params)
            .await
    }

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

    pub async fn get_free_slots(
        &self,
        calendar_id: &str,
        params: &GetFreeSlotsParams,
    ) -> Result<FreeSlotsResponse> {
        self.http
            .get_with_query(&format!("/calendars/{calendar_id}/free-slots"), params)
            .await
    }

    // ── Events / Appointments ────────────────────────────────────────────────

    pub async fn get_events(&self, params: &GetEventsParams) -> Result<GetEventsResponse> {
        self.http.get_with_query("/calendars/events", params).await
    }

    pub async fn get_event(&self, event_id: &str) -> Result<GetEventResponse> {
        self.http
            .get(&format!("/calendars/events/{event_id}"))
            .await
    }

    pub async fn create_event(&self, params: &CreateEventParams) -> Result<GetEventResponse> {
        self.http
            .post("/calendars/events/appointments", params)
            .await
    }

    pub async fn update_event(
        &self,
        event_id: &str,
        params: &UpdateEventParams,
    ) -> Result<GetEventResponse> {
        self.http
            .put(
                &format!("/calendars/events/appointments/{event_id}"),
                params,
            )
            .await
    }

    pub async fn delete_event(&self, event_id: &str) -> Result<DeleteEventResponse> {
        self.http
            .delete(&format!("/calendars/events/{event_id}"))
            .await
    }
}