Class: Booker::V41::Customer

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

Constant Summary collapse

V41_PREFIX =
'/v4.1/customer'
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,
  employees: "#{V41_PREFIX}/employees".freeze,
  treatments: "#{V41_PREFIX}/treatments".freeze,
  treatments_verified_bookable_online: "#{V41_PREFIX}/treatments/online".freeze,
  location: "#{V41_PREFIX}/location".freeze,
  locations: "#{V41_PREFIX}/locations".freeze,
  class_availability: "#{V41_PREFIX}/availability/class".freeze
}.freeze

Constants included from RequestHelper

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::DEFAULT_REQUEST_TIMEOUT, 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, #request_timeout, #temp_access_token, #temp_access_token_expires_at, #token_store, #token_store_callback_method

Instance Method Summary collapse

Methods included from RequestHelper

#build_params

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, #patch, #post, #put, #update_token_store

Constructor Details

This class inherits a constructor from Booker::Client

Instance Method Details

#appointment(id:) ⇒ Object



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

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

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



25
26
27
# File 'lib/booker/v4.1/customer.rb', line 25

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

#class_availability(location_id:, from_start_date_time:, to_start_date_time:, params: {}) ⇒ Object



91
92
93
94
95
96
97
98
99
# File 'lib/booker/v4.1/customer.rb', line 91

def class_availability(location_id:, from_start_date_time:, to_start_date_time:, params: {})
  post API_METHODS[:class_availability], build_params({
    FromStartDateTime: from_start_date_time,
    LocationID: location_id,
    OnlyIfAvailable: true,
    ToStartDateTime: to_start_date_time,
    ExcludeClosedDates: true
  }, params), Booker::V4::Models::ClassInstance
end

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



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

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_class_appointment(location_id:, class_instance_id:, customer:, params: {}) ⇒ Object



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

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

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



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

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



77
78
79
80
# File 'lib/booker/v4.1/customer.rb', line 77

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

#locations(params: {}) ⇒ Object



82
83
84
85
86
87
88
89
# File 'lib/booker/v4.1/customer.rb', line 82

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

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



57
58
59
60
61
62
63
64
65
# File 'lib/booker/v4.1/customer.rb', line 57

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

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



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

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