Skip to main content

highlevel_api/apis/calendars/
client.rs

1use std::sync::Arc;
2use crate::{error::Result, http::HttpClient};
3use super::types::*;
4
5pub struct CalendarsApi {
6    http: Arc<HttpClient>,
7}
8
9impl CalendarsApi {
10    pub fn new(http: Arc<HttpClient>) -> Self {
11        Self { http }
12    }
13
14    // ── Calendars ─────────────────────────────────────────────────────────────
15
16    pub async fn list(&self, location_id: &str) -> Result<GetCalendarsResponse> {
17        #[derive(serde::Serialize)]
18        struct Q<'a> {
19            #[serde(rename = "locationId")]
20            location_id: &'a str,
21        }
22        self.http.get_with_query("/calendars", &Q { location_id }).await
23    }
24
25    pub async fn get(&self, calendar_id: &str) -> Result<GetCalendarResponse> {
26        self.http.get(&format!("/calendars/{calendar_id}")).await
27    }
28
29    pub async fn create(&self, params: &CreateCalendarParams) -> Result<GetCalendarResponse> {
30        self.http.post("/calendars", params).await
31    }
32
33    pub async fn update(
34        &self,
35        calendar_id: &str,
36        params: &UpdateCalendarParams,
37    ) -> Result<GetCalendarResponse> {
38        self.http.put(&format!("/calendars/{calendar_id}"), params).await
39    }
40
41    pub async fn delete(&self, calendar_id: &str) -> Result<DeleteCalendarResponse> {
42        self.http.delete(&format!("/calendars/{calendar_id}")).await
43    }
44
45    pub async fn get_free_slots(
46        &self,
47        calendar_id: &str,
48        params: &GetFreeSlotsParams,
49    ) -> Result<FreeSlotsResponse> {
50        self.http
51            .get_with_query(&format!("/calendars/{calendar_id}/free-slots"), params)
52            .await
53    }
54
55    // ── Events / Appointments ────────────────────────────────────────────────
56
57    pub async fn get_events(&self, params: &GetEventsParams) -> Result<GetEventsResponse> {
58        self.http.get_with_query("/calendars/events", params).await
59    }
60
61    pub async fn get_event(&self, event_id: &str) -> Result<GetEventResponse> {
62        self.http.get(&format!("/calendars/events/{event_id}")).await
63    }
64
65    pub async fn create_event(&self, params: &CreateEventParams) -> Result<GetEventResponse> {
66        self.http.post("/calendars/events/appointments", params).await
67    }
68
69    pub async fn update_event(
70        &self,
71        event_id: &str,
72        params: &UpdateEventParams,
73    ) -> Result<GetEventResponse> {
74        self.http
75            .put(&format!("/calendars/events/appointments/{event_id}"), params)
76            .await
77    }
78
79    pub async fn delete_event(&self, event_id: &str) -> Result<DeleteEventResponse> {
80        self.http.delete(&format!("/calendars/events/{event_id}")).await
81    }
82}