highlevel_api/apis/calendars/
client.rs1use super::types::*;
2use crate::{error::Result, http::HttpClient};
3use std::sync::Arc;
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 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
23 .get_with_query("/calendars", &Q { location_id })
24 .await
25 }
26
27 pub async fn get(&self, calendar_id: &str) -> Result<GetCalendarResponse> {
28 self.http.get(&format!("/calendars/{calendar_id}")).await
29 }
30
31 pub async fn create(&self, params: &CreateCalendarParams) -> Result<GetCalendarResponse> {
32 self.http.post("/calendars", params).await
33 }
34
35 pub async fn update(
36 &self,
37 calendar_id: &str,
38 params: &UpdateCalendarParams,
39 ) -> Result<GetCalendarResponse> {
40 self.http
41 .put(&format!("/calendars/{calendar_id}"), params)
42 .await
43 }
44
45 pub async fn delete(&self, calendar_id: &str) -> Result<DeleteCalendarResponse> {
46 self.http.delete(&format!("/calendars/{calendar_id}")).await
47 }
48
49 pub async fn get_free_slots(
50 &self,
51 calendar_id: &str,
52 params: &GetFreeSlotsParams,
53 ) -> Result<FreeSlotsResponse> {
54 self.http
55 .get_with_query(&format!("/calendars/{calendar_id}/free-slots"), params)
56 .await
57 }
58
59 pub async fn get_events(&self, params: &GetEventsParams) -> Result<GetEventsResponse> {
62 self.http.get_with_query("/calendars/events", params).await
63 }
64
65 pub async fn get_event(&self, event_id: &str) -> Result<GetEventResponse> {
66 self.http
67 .get(&format!("/calendars/events/{event_id}"))
68 .await
69 }
70
71 pub async fn create_event(&self, params: &CreateEventParams) -> Result<GetEventResponse> {
72 self.http
73 .post("/calendars/events/appointments", params)
74 .await
75 }
76
77 pub async fn update_event(
78 &self,
79 event_id: &str,
80 params: &UpdateEventParams,
81 ) -> Result<GetEventResponse> {
82 self.http
83 .put(
84 &format!("/calendars/events/appointments/{event_id}"),
85 params,
86 )
87 .await
88 }
89
90 pub async fn delete_event(&self, event_id: &str) -> Result<DeleteEventResponse> {
91 self.http
92 .delete(&format!("/calendars/events/{event_id}"))
93 .await
94 }
95}