Module: Booker::BusinessREST

Includes:
CommonREST
Included in:
BusinessClient
Defined in:
lib/booker/business_rest.rb

Constant Summary

Constants included from CommonREST

CommonREST::DEFAULT_PAGINATION_PARAMS

Instance Method Summary collapse

Methods included from CommonREST

#confirm_appointment, #get_location, #get_online_booking_settings

Instance Method Details

#add_cash_payment(order_id, amount, params: {}) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/booker/business_rest.rb', line 140

def add_cash_payment(order_id, amount, params: {})
  post "/order/#{order_id}/add_payment", build_params({
    "PaymentItem" => {
      "Cash" => {},
      "Method" => {
        "ID" => 4
      },
      "CustomPaymentMethodID" => 67922,
      "CustomPaymentMethodIDSpecified" => true,
      "Amount" => amount
    }
  }, params)
end

#cancel_appointment(appointment_id) ⇒ Object



120
121
122
123
124
# File 'lib/booker/business_rest.rb', line 120

def cancel_appointment(appointment_id)
  put "/appointment/cancel", build_params({
    'ID' => appointment_id
  })
end

#create_special(booker_location_id:, start_date:, end_date:, coupon_code:, name:, params: {}) ⇒ Object



84
85
86
87
88
89
90
91
92
# File 'lib/booker/business_rest.rb', line 84

def create_special(booker_location_id:, start_date:, end_date:, coupon_code:, name:, params: {})
  post('/special', build_params({
        'LocationID' => booker_location_id,
        'ApplicableStartDate' => start_date.in_time_zone,
        'ApplicableEndDate' => end_date.in_time_zone,
        'CouponCode' => coupon_code,
        'Name' => name
      }, params))
end

#find_appointments(booker_location_id:, start_date:, end_date:, fetch_all: true, params: {}) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/booker/business_rest.rb', line 68

def find_appointments(booker_location_id:, start_date:, end_date:, fetch_all: true, params: {})
  additional_params = {
      'LocationID' => booker_location_id,
      'FromStartDate' => start_date.to_date,
      'ToStartDate' => end_date.to_date
  }

  paginated_request(
      method: :post,
      path: '/appointments',
      params: build_params(additional_params, params, true),
      model: Booker::Models::Appointment,
      fetch_all: fetch_all
  )
end

#find_customers(booker_location_id:, fetch_all: true, params: {}) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/booker/business_rest.rb', line 52

def find_customers(booker_location_id:, fetch_all: true, params: {})
  additional_params = {
      'FilterByExactLocationID' => true,
      'LocationID' => booker_location_id,
      'CustomerRecordType' => 1,
  }

  paginated_request(
      method: :post,
      path: '/customers',
      params: build_params(additional_params, params, true),
      model: Booker::Models::Customer,
      fetch_all: fetch_all
  )
end

#find_employees(booker_location_id:, fetch_all: true, params: {}) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/booker/business_rest.rb', line 32

def find_employees(booker_location_id:, fetch_all: true, params: {})
  paginated_request(
      method: :post,
      path: '/employees',
      params: build_params({'LocationID' => booker_location_id}, params, true),
      model: Booker::Models::Employee,
      fetch_all: fetch_all
  )
end

#find_locations(params: {}) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/booker/business_rest.rb', line 23

def find_locations(params: {})
  paginated_request(
      method: :post,
      path: '/locations',
      params: build_params({}, params, true),
      model: Booker::Models::Location
  )
end

#find_treatments(booker_location_id:, fetch_all: true, params: {}) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/booker/business_rest.rb', line 42

def find_treatments(booker_location_id:, fetch_all: true, params: {})
  paginated_request(
      method: :post,
      path: '/treatments',
      params: build_params({'LocationID' => booker_location_id}, params, true),
      model: Booker::Models::Treatment,
      fetch_all: fetch_all
  )
end

#get_appointment(appointment_id) ⇒ Object



116
117
118
# File 'lib/booker/business_rest.rb', line 116

def get_appointment(appointment_id)
  get "/appointment/#{appointment_id}", build_params
end

#get_location_day_schedules(booker_location_id:, params: {}) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/booker/business_rest.rb', line 13

def get_location_day_schedules(booker_location_id:, params: {})
  # Booker requires fromDate and toDate for JSON API, but does not use them when getDefaultDaySchedule is true
  # So datetime used for these fields does not matter
  random_datetime = Booker::Models::Model.time_to_booker_datetime(Time.now)

  additional_params = {'getDefaultDaySchedule' => true, 'fromDate' => random_datetime, 'toDate' => random_datetime}
  response = get("/location/#{booker_location_id}/schedule", build_params(additional_params, params))
  response['LocationDaySchedules'].map { |sched| Booker::Models::LocationDaySchedule.from_hash(sched) }
end

#get_location_feature_settings(booker_location_id:) ⇒ Object



107
108
109
110
# File 'lib/booker/business_rest.rb', line 107

def get_location_feature_settings(booker_location_id:)
  response = get "/location/#{booker_location_id}/feature_settings", build_params
  Booker::Models::FeatureSettings.from_hash response['FeatureSettings']
end

#get_location_notification_settings(booker_location_id:) ⇒ Object



94
95
96
97
# File 'lib/booker/business_rest.rb', line 94

def get_location_notification_settings(booker_location_id:)
  response = get "/location/#{booker_location_id}/notification_settings", build_params
  Booker::Models::NotificationSettings.from_hash response['NotificationSettings']
end

#get_location_payment_settings(booker_location_id) ⇒ Object



112
113
114
# File 'lib/booker/business_rest.rb', line 112

def get_location_payment_settings(booker_location_id)
  get "/location/#{booker_location_id}/payment_settings", build_params
end

#get_logged_in_userObject



5
6
7
8
9
10
11
# File 'lib/booker/business_rest.rb', line 5

def get_logged_in_user
  response = get('/user', build_params)
  result = Booker::Models::User.from_hash(response['User'])
  result.LocationID = response['LocationID']
  result.BrandID = response['BrandID']
  result
end

#place_order(order_id, amount) ⇒ Object



126
127
128
# File 'lib/booker/business_rest.rb', line 126

def place_order(order_id, amount)
  post "/order/#{order_id}/place_order", build_params
end

#remove_payment(order_id, payment_id, params: {}) ⇒ Object



154
155
156
157
158
159
# File 'lib/booker/business_rest.rb', line 154

def remove_payment(order_id, payment_id, params: {})
  post "/order/#{order_id}/remove_payment", build_params({
    "PaymentItemIDs" => [payment_id],
    "ID" => 4
  }, params)
end

#take_deposit(order_id, params: {}) ⇒ Object



130
131
132
133
134
135
136
137
138
# File 'lib/booker/business_rest.rb', line 130

def take_deposit(order_id, params: {})
  post "/order/#{order_id}/deposit", build_params({
    "PaymentItem" => {
      "Method" => {
        "ID" => 4
      }
    }
  }, params)
end

#update_location_notification_settings(booker_location_id:, send_appointment_reminders:) ⇒ Object



99
100
101
102
103
104
105
# File 'lib/booker/business_rest.rb', line 99

def update_location_notification_settings(booker_location_id:, send_appointment_reminders:)
  put "/location/#{booker_location_id}/notification_settings", build_params({
    NotificationSettings: {
      SendAppointmentReminders: send_appointment_reminders
    }
  })
end