Class: Booker::V41::Booking

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

Constant Summary collapse

V41_PREFIX =
'/v4.1/booking'
V41_APPOINTMENTS_PREFIX =
"#{V41_PREFIX}/appointment"
API_METHODS =
{
  appointment: "#{V41_APPOINTMENTS_PREFIX}".freeze,
  cancel_appointment: "#{V41_APPOINTMENTS_PREFIX}/cancel".freeze,
  create_appointment: "#{V41_APPOINTMENTS_PREFIX}/create".freeze,
  create_class_appointment: "#{V41_PREFIX}/class_appointment/create".freeze,
  appointment_hold: "#{V41_APPOINTMENTS_PREFIX}/hold".freeze,
  employees: "#{V41_PREFIX}/employees".freeze,
  services: "#{V41_PREFIX}/services".freeze,
  location: "#{V41_PREFIX}/location".freeze,
  locations: "#{V41_PREFIX}/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



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

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

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



24
25
26
# File 'lib/booker/v4.1/booking.rb', line 24

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

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



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

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

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



46
47
48
49
50
51
52
53
54
# File 'lib/booker/v4.1/booking.rb', line 46

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

#create_class_appointment(location_id:, class_instance_id:, customer:, params: {}) ⇒ Object



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

def create_class_appointment(location_id:, class_instance_id:, customer:, params: {})
  post API_METHODS[:create_class_appointment], build_params({
                                                   LocationID: location_id,
                                                   ClassInstanceID: class_instance_id,
                                                   Customer: customer
                                                 }, params), Booker::V4::Models::Appointment
end

#delete_appointment_hold(location_id:, incomplete_appointment_id:) ⇒ Object



56
57
58
59
60
61
# File 'lib/booker/v4.1/booking.rb', line 56

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, params: {}) ⇒ Object



63
64
65
66
67
68
69
70
71
# File 'lib/booker/v4.1/booking.rb', line 63

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

#location(id:) ⇒ Object



73
74
75
76
# File 'lib/booker/v4.1/booking.rb', line 73

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

#locations(params: {}) ⇒ Object



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

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

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



87
88
89
90
91
92
93
94
95
# File 'lib/booker/v4.1/booking.rb', line 87

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