Class: Booker::V41::Booking

Inherits:
Client
  • Object
show all
Includes:
Booker::V4::RequestHelper
Defined in:
lib/booker/v4.1/booking.rb

Constant Summary collapse

API_METHODS =
{
  appointment: '/v4.1/booking/appointment'.freeze,
  cancel_appointment: '/v4.1/booking/appointment/cancel'.freeze,
  create_appointment: '/v4.1/booking/appointment/create'.freeze,
  appointment_hold: '/v4.1/booking/appointment/hold'.freeze,
  employees: '/v4.1/booking/employees'.freeze,
  services: '/v4.1/booking/services'.freeze,
  location: '/v4.1/booking/location'.freeze,
  locations: '/v4.1/booking/locations'.freeze
}.freeze

Constants included from Booker::V4::RequestHelper

Booker::V4::RequestHelper::DEFAULT_PAGINATION_PARAMS

Constants inherited from Client

Client::API_GATEWAY_ERRORS, Client::BOOKER_SERVER_TIMEZONE, Client::CLIENT_CREDENTIALS_GRANT_TYPE, Client::CREATE_TOKEN_CONTENT_TYPE, Client::CREATE_TOKEN_PATH, Client::DEFAULT_AUTH_BASE_URL, Client::DEFAULT_BASE_URL, Client::DEFAULT_CONTENT_TYPE, Client::ENV_BASE_URL_KEY, Client::REFRESH_TOKEN_GRANT_TYPE, Client::UPDATE_TOKEN_CONTEXT_PATH, Client::VALID_ACCESS_TOKEN_SCOPES

Instance Attribute Summary

Attributes inherited from Client

#access_token_scope, #api_subscription_key, #auth_base_url, #auth_with_client_credentials, #base_url, #client_id, #client_secret, #location_id, #refresh_token, #temp_access_token, #temp_access_token_expires_at, #token_store, #token_store_callback_method

Instance Method Summary collapse

Methods inherited from Client

#access_token, #access_token_response, #delete, #full_url, #get, #get_access_token, #get_base_url, #get_booker_resources, #get_location_access_token, #handle_errors!, #initialize, #paginated_request, #post, #put, #update_token_store

Constructor Details

This class inherits a constructor from Booker::Client

Instance Method Details

#appointment(id:) ⇒ Object



17
18
19
# File 'lib/booker/v4.1/booking.rb', line 17

def appointment(id:)
  get "#{API_METHODS[:appointment]}/#{id}", build_params, Booker::V4::Models::Appointment
end

#cancel_appointment(id:, options: {}) ⇒ Object



21
22
23
# File 'lib/booker/v4.1/booking.rb', line 21

def cancel_appointment(id:, options:{})
  put API_METHODS[:cancel_appointment], build_params({ID: id}, options), Booker::V4::Models::Appointment
end

#create_appointment(location_id:, available_time:, customer:, options: {}) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/booker/v4.1/booking.rb', line 25

def create_appointment(location_id:, available_time:, customer:, options: {})
  post API_METHODS[:create_appointment], build_params({
    LocationID: location_id,
    ItineraryTimeSlotList: [
      TreatmentTimeSlots: [available_time]
    ],
    Customer: customer
  }, options), Booker::V4::Models::Appointment
end

#create_appointment_hold(location_id:, available_time:, customer:, options: {}) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/booker/v4.1/booking.rb', line 35

def create_appointment_hold(location_id:, available_time:, customer:, options: {})
  post API_METHODS[:appointment_hold], build_params({
    LocationID: location_id,
    ItineraryTimeSlot: {
      TreatmentTimeSlots: [available_time]
    },
    Customer: customer
  }, options)
end

#delete_appointment_hold(location_id:, incomplete_appointment_id:) ⇒ Object



45
46
47
48
49
50
# File 'lib/booker/v4.1/booking.rb', line 45

def delete_appointment_hold(location_id:, incomplete_appointment_id:)
  delete API_METHODS[:appointment_hold], nil, build_params({
    LocationID: location_id,
    IncompleteAppointmentID: incomplete_appointment_id
  })
end

#employees(location_id:, fetch_all: true, options: {}) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'lib/booker/v4.1/booking.rb', line 52

def employees(location_id:, fetch_all: true, options: {})
  paginated_request(
    method: :post,
    path: API_METHODS[:employees],
    params: build_params({LocationID: location_id}, options, true),
    model: Booker::V4::Models::Employee,
    fetch_all: fetch_all
  )
end

#location(id:) ⇒ Object



62
63
64
65
# File 'lib/booker/v4.1/booking.rb', line 62

def location(id:)
  response = get("#{API_METHODS[:location]}/#{id}", build_params)
  Booker::V4::Models::Location.from_hash(response)
end

#locations(options: {}) ⇒ Object



67
68
69
70
71
72
73
74
# File 'lib/booker/v4.1/booking.rb', line 67

def locations(options: {})
  paginated_request(
    method: :post,
    path: API_METHODS[:locations],
    params: build_params({}, options, true),
    model: Booker::V4::Models::Location
  )
end

#services(location_id:, fetch_all: true, params: {}) ⇒ Object



76
77
78
79
80
81
82
83
84
# File 'lib/booker/v4.1/booking.rb', line 76

def services(location_id:, fetch_all: true, params: {})
  paginated_request(
    method: :post,
    path: API_METHODS[:services],
    params: build_params({LocationID: location_id}, params, true),
    model: Booker::V4::Models::Treatment,
    fetch_all: fetch_all
  )
end