Class: Square::BookingsApi

Inherits:
BaseApi
  • Object
show all
Defined in:
lib/square/api/bookings_api.rb

Overview

BookingsApi

Instance Attribute Summary

Attributes inherited from BaseApi

#config, #http_call_back

Instance Method Summary collapse

Methods inherited from BaseApi

#execute_request, #get_user_agent, #validate_parameters

Constructor Details

#initialize(config, http_call_back: nil) ⇒ BookingsApi

Returns a new instance of BookingsApi.



4
5
6
# File 'lib/square/api/bookings_api.rb', line 4

def initialize(config, http_call_back: nil)
  super(config, http_call_back: http_call_back)
end

Instance Method Details

#cancel_booking(booking_id:, body:) ⇒ CancelBookingResponse Hash

Cancels an existing booking. To call this endpoint with buyer-level permissions, set ‘APPOINTMENTS_WRITE` for the OAuth scope. To call this endpoint with seller-level permissions, set `APPOINTMENTS_ALL_WRITE` and `APPOINTMENTS_WRITE` for the OAuth scope. For calls to this endpoint with seller-level permissions to succeed, the seller must have subscribed to *Appointments Plus* or *Appointments Premium*. [Booking]($m/Booking) object representing the to-be-cancelled booking. containing the fields to POST for the request. See the corresponding object definition for field details.

Parameters:

  • booking_id (String)

    Required parameter: The ID of the

  • body (CancelBookingRequest)

    Required parameter: An object

Returns:

  • (CancelBookingResponse Hash)

    response from the API call



366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
# File 'lib/square/api/bookings_api.rb', line 366

def cancel_booking(booking_id:,
                   body:)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/bookings/{booking_id}/cancel'
  _query_builder = APIHelper.append_url_with_template_parameters(
    _query_builder,
    'booking_id' => { 'value' => booking_id, 'encode' => true }
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json',
    'Content-Type' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.post(
    _query_url,
    headers: _headers,
    parameters: body.to_json
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end

#create_booking(body:) ⇒ CreateBookingResponse Hash

Creates a booking. To call this endpoint with buyer-level permissions, set ‘APPOINTMENTS_WRITE` for the OAuth scope. To call this endpoint with seller-level permissions, set `APPOINTMENTS_ALL_WRITE` and `APPOINTMENTS_WRITE` for the OAuth scope. For calls to this endpoint with seller-level permissions to succeed, the seller must have subscribed to *Appointments Plus* or *Appointments Premium*. containing the fields to POST for the request. See the corresponding object definition for field details.

Parameters:

  • body (CreateBookingRequest)

    Required parameter: An object

Returns:

  • (CreateBookingResponse Hash)

    response from the API call



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/square/api/bookings_api.rb', line 84

def create_booking(body:)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/bookings'
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json',
    'Content-Type' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.post(
    _query_url,
    headers: _headers,
    parameters: body.to_json
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end

#list_bookings(limit: nil, cursor: nil, team_member_id: nil, location_id: nil, start_at_min: nil, start_at_max: nil) ⇒ ListBookingsResponse Hash

Retrieve a collection of bookings. To call this endpoint with buyer-level permissions, set ‘APPOINTMENTS_READ` for the OAuth scope. To call this endpoint with seller-level permissions, set `APPOINTMENTS_ALL_READ` and `APPOINTMENTS_READ` for the OAuth scope. per page to return in a paged response. preceding response to return the next page of the results. Do not set this when retrieving the first page of the results. whom to retrieve bookings. If this is not set, bookings of all members are retrieved. retrieve bookings. If this is not set, all locations’ bookings are retrieved. specifying the earliest of the start time. If this is not set, the current time is used. specifying the latest of the start time. If this is not set, the time of 31 days after ‘start_at_min` is used.

Parameters:

  • limit (Integer) (defaults to: nil)

    Optional parameter: The maximum number of results

  • cursor (String) (defaults to: nil)

    Optional parameter: The pagination cursor from the

  • team_member_id (String) (defaults to: nil)

    Optional parameter: The team member for

  • location_id (String) (defaults to: nil)

    Optional parameter: The location for which to

  • start_at_min (String) (defaults to: nil)

    Optional parameter: The RFC 3339 timestamp

  • start_at_max (String) (defaults to: nil)

    Optional parameter: The RFC 3339 timestamp

Returns:

  • (ListBookingsResponse Hash)

    response from the API call



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/square/api/bookings_api.rb', line 31

def list_bookings(limit: nil,
                  cursor: nil,
                  team_member_id: nil,
                  location_id: nil,
                  start_at_min: nil,
                  start_at_max: nil)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/bookings'
  _query_builder = APIHelper.append_url_with_query_parameters(
    _query_builder,
    'limit' => limit,
    'cursor' => cursor,
    'team_member_id' => team_member_id,
    'location_id' => location_id,
    'start_at_min' => start_at_min,
    'start_at_max' => start_at_max
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.get(
    _query_url,
    headers: _headers
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end

#list_team_member_booking_profiles(bookable_only: false, limit: nil, cursor: nil, location_id: nil) ⇒ ListTeamMemberBookingProfilesResponse Hash

Lists booking profiles for team members. include only bookable team members in the returned result (‘true`) or not (`false`). to return in a paged response. preceding response to return the next page of the results. Do not set this when retrieving the first page of the results. include only team members enabled at the given location in the returned result.

Parameters:

  • bookable_only (Boolean) (defaults to: false)

    Optional parameter: Indicates whether to

  • limit (Integer) (defaults to: nil)

    Optional parameter: The maximum number of results

  • cursor (String) (defaults to: nil)

    Optional parameter: The pagination cursor from the

  • location_id (String) (defaults to: nil)

    Optional parameter: Indicates whether to

Returns:

  • (ListTeamMemberBookingProfilesResponse Hash)

    response from the API call



193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/square/api/bookings_api.rb', line 193

def list_team_member_booking_profiles(bookable_only: false,
                                      limit: nil,
                                      cursor: nil,
                                      location_id: nil)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/bookings/team-member-booking-profiles'
  _query_builder = APIHelper.append_url_with_query_parameters(
    _query_builder,
    'bookable_only' => bookable_only,
    'limit' => limit,
    'cursor' => cursor,
    'location_id' => location_id
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.get(
    _query_url,
    headers: _headers
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end

#retrieve_booking(booking_id:) ⇒ RetrieveBookingResponse Hash

Retrieves a booking. To call this endpoint with buyer-level permissions, set ‘APPOINTMENTS_READ` for the OAuth scope. To call this endpoint with seller-level permissions, set `APPOINTMENTS_ALL_READ` and `APPOINTMENTS_READ` for the OAuth scope. [Booking]($m/Booking) object representing the to-be-retrieved booking.

Parameters:

  • booking_id (String)

    Required parameter: The ID of the

Returns:

  • (RetrieveBookingResponse Hash)

    response from the API call



273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
# File 'lib/square/api/bookings_api.rb', line 273

def retrieve_booking(booking_id:)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/bookings/{booking_id}'
  _query_builder = APIHelper.append_url_with_template_parameters(
    _query_builder,
    'booking_id' => { 'value' => booking_id, 'encode' => true }
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.get(
    _query_url,
    headers: _headers
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end

#retrieve_business_booking_profileRetrieveBusinessBookingProfileResponse Hash

Retrieves a seller’s booking profile.

Returns:

  • (RetrieveBusinessBookingProfileResponse Hash)

    response from the API call



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/square/api/bookings_api.rb', line 153

def retrieve_business_booking_profile
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/bookings/business-booking-profile'
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.get(
    _query_url,
    headers: _headers
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end

#retrieve_team_member_booking_profile(team_member_id:) ⇒ RetrieveTeamMemberBookingProfileResponse Hash

Retrieves a team member’s booking profile. member to retrieve.

Parameters:

  • team_member_id (String)

    Required parameter: The ID of the team

Returns:

  • (RetrieveTeamMemberBookingProfileResponse Hash)

    response from the API call



234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'lib/square/api/bookings_api.rb', line 234

def retrieve_team_member_booking_profile(team_member_id:)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/bookings/team-member-booking-profiles/{team_member_id}'
  _query_builder = APIHelper.append_url_with_template_parameters(
    _query_builder,
    'team_member_id' => { 'value' => team_member_id, 'encode' => true }
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.get(
    _query_url,
    headers: _headers
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end

#search_availability(body:) ⇒ SearchAvailabilityResponse Hash

Searches for availabilities for booking. To call this endpoint with buyer-level permissions, set ‘APPOINTMENTS_READ` for the OAuth scope. To call this endpoint with seller-level permissions, set `APPOINTMENTS_ALL_READ` and `APPOINTMENTS_READ` for the OAuth scope. containing the fields to POST for the request. See the corresponding object definition for field details.

Parameters:

  • body (SearchAvailabilityRequest)

    Required parameter: An object

Returns:

  • (SearchAvailabilityResponse Hash)

    response from the API call



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/square/api/bookings_api.rb', line 122

def search_availability(body:)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/bookings/availability/search'
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json',
    'Content-Type' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.post(
    _query_url,
    headers: _headers,
    parameters: body.to_json
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end

#update_booking(booking_id:, body:) ⇒ UpdateBookingResponse Hash

Updates a booking. To call this endpoint with buyer-level permissions, set ‘APPOINTMENTS_WRITE` for the OAuth scope. To call this endpoint with seller-level permissions, set `APPOINTMENTS_ALL_WRITE` and `APPOINTMENTS_WRITE` for the OAuth scope. For calls to this endpoint with seller-level permissions to succeed, the seller must have subscribed to *Appointments Plus* or *Appointments Premium*. [Booking]($m/Booking) object representing the to-be-updated booking. containing the fields to POST for the request. See the corresponding object definition for field details.

Parameters:

  • booking_id (String)

    Required parameter: The ID of the

  • body (UpdateBookingRequest)

    Required parameter: An object

Returns:

  • (UpdateBookingResponse Hash)

    response from the API call



318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
# File 'lib/square/api/bookings_api.rb', line 318

def update_booking(booking_id:,
                   body:)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/bookings/{booking_id}'
  _query_builder = APIHelper.append_url_with_template_parameters(
    _query_builder,
    'booking_id' => { 'value' => booking_id, 'encode' => true }
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json',
    'Content-Type' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.put(
    _query_url,
    headers: _headers,
    parameters: body.to_json
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end