1use crate::models::{
9 BulkRetrieveBookingsRequest, BulkRetrieveBookingsResponse,
10 BulkRetrieveTeamMemberBookingProfilesRequest, BulkRetrieveTeamMemberBookingProfilesResponse,
11 CancelBookingRequest, CancelBookingResponse, CreateBookingRequest, CreateBookingResponse,
12 ListBookingsParameters, ListBookingsResponse, ListLocationBookingProfilesParameters,
13 ListLocationBookingProfilesResponse, ListTeamMemberBookingProfilesParameters,
14 ListTeamMemberBookingProfilesResponse, RetrieveBookingResponse,
15 RetrieveBusinessBookingProfileResponse, RetrieveLocationBookingProfileResponse,
16 RetrieveTeamMemberBookingProfileResponse, SearchAvailabilityRequest,
17 SearchAvailabilityResponse, UpdateBookingRequest, UpdateBookingResponse,
18};
19use crate::{
20 SquareClient, config::Configuration, http::client::HttpClient, models::errors::SquareApiError,
21};
22
23const DEFAULT_URI: &str = "/bookings";
24
25pub struct BookingsApi {
27 config: Configuration,
29 http_client: HttpClient,
31}
32
33impl BookingsApi {
34 pub fn new(square_client: SquareClient) -> BookingsApi {
36 BookingsApi {
37 config: square_client.config,
38 http_client: square_client.http_client,
39 }
40 }
41
42 pub async fn list_bookings(
48 &self,
49 params: &ListBookingsParameters,
50 ) -> Result<ListBookingsResponse, SquareApiError> {
51 let url = format!("{}{}", &self.url(), params.to_query_string());
52 let response = self.http_client.get(&url).await?;
53
54 response.deserialize().await
55 }
56
57 pub async fn create_booking(
74 &self,
75 body: &CreateBookingRequest,
76 ) -> Result<CreateBookingResponse, SquareApiError> {
77 let url = &self.url();
78 let response = self.http_client.post(url, body).await?;
79
80 response.deserialize().await
81 }
82
83 pub async fn search_availability(
90 &self,
91 body: &SearchAvailabilityRequest,
92 ) -> Result<SearchAvailabilityResponse, SquareApiError> {
93 let url = format!("{}/availability/search", &self.url());
94 let response = self.http_client.post(&url, body).await?;
95
96 response.deserialize().await
97 }
98
99 pub async fn bulk_retrieve_bookings(
107 &self,
108 body: &BulkRetrieveBookingsRequest,
109 ) -> Result<BulkRetrieveBookingsResponse, SquareApiError> {
110 let url = format!("{}/bulk-retrieve", &self.url());
111 let response = self.http_client.post(&url, body).await?;
112
113 response.deserialize().await
114 }
115
116 pub async fn retrieve_business_booking_profile(
119 &self,
120 ) -> Result<RetrieveBusinessBookingProfileResponse, SquareApiError> {
121 let url = format!("{}/business-booking-profile", &self.url());
122 let response = self.http_client.get(&url).await?;
123
124 response.deserialize().await
125 }
126
127 pub async fn list_location_booking_profiles(
130 &self,
131 params: &ListLocationBookingProfilesParameters,
132 ) -> Result<ListLocationBookingProfilesResponse, SquareApiError> {
133 let url = format!(
134 "{}/location-booking-profiles{}",
135 &self.url(),
136 params.to_query_string()
137 );
138 let response = self.http_client.get(&url).await?;
139
140 response.deserialize().await
141 }
142
143 pub async fn retrieve_location_booking_profile(
146 &self,
147 location_id: impl AsRef<str>,
148 ) -> Result<RetrieveLocationBookingProfileResponse, SquareApiError> {
149 let url = format!(
150 "{}/location-booking-profiles/{}",
151 &self.url(),
152 location_id.as_ref()
153 );
154 let response = self.http_client.get(&url).await?;
155
156 response.deserialize().await
157 }
158
159 pub async fn list_team_member_booking_profiles(
162 &self,
163 params: &ListTeamMemberBookingProfilesParameters,
164 ) -> Result<ListTeamMemberBookingProfilesResponse, SquareApiError> {
165 let url = format!(
166 "{}/team-member-booking-profiles{}",
167 &self.url(),
168 params.to_query_string()
169 );
170 let response = self.http_client.get(&url).await?;
171
172 response.deserialize().await
173 }
174
175 pub async fn bulk_retrieve_team_member_booking_profiles(
178 &self,
179 body: &BulkRetrieveTeamMemberBookingProfilesRequest,
180 ) -> Result<BulkRetrieveTeamMemberBookingProfilesResponse, SquareApiError> {
181 let url = format!("{}/team-member-booking-profiles/bulk-retrieve", &self.url());
182 let response = self.http_client.post(&url, body).await?;
183
184 response.deserialize().await
185 }
186
187 pub async fn retrieve_team_member_booking_profile(
190 &self,
191 team_member_id: impl AsRef<str>,
192 ) -> Result<RetrieveTeamMemberBookingProfileResponse, SquareApiError> {
193 let url = format!(
194 "{}/team-member-booking-profiles/{}",
195 &self.url(),
196 team_member_id.as_ref()
197 );
198 let response = self.http_client.get(&url).await?;
199
200 response.deserialize().await
201 }
202
203 pub async fn retrieve_booking(
210 &self,
211 booking_id: impl AsRef<str>,
212 ) -> Result<RetrieveBookingResponse, SquareApiError> {
213 let url = format!("{}/{}", &self.url(), booking_id.as_ref());
214 let response = self.http_client.get(&url).await?;
215
216 response.deserialize().await
217 }
218
219 pub async fn update_booking(
229 &self,
230 booking_id: impl AsRef<str>,
231 body: &UpdateBookingRequest,
232 ) -> Result<UpdateBookingResponse, SquareApiError> {
233 let url = format!("{}/{}", &self.url(), booking_id.as_ref());
234 let response = self.http_client.put(&url, body).await?;
235
236 response.deserialize().await
237 }
238
239 pub async fn cancel_booking(
249 &self,
250 booking_id: impl AsRef<str>,
251 body: &CancelBookingRequest,
252 ) -> Result<CancelBookingResponse, SquareApiError> {
253 let url = format!("{}/{}/cancel", &self.url(), booking_id.as_ref());
254 let response = self.http_client.post(&url, body).await?;
255
256 response.deserialize().await
257 }
258
259 fn url(&self) -> String {
262 format!("{}{}", &self.config.get_base_url(), DEFAULT_URI)
263 }
264}