lib/supersaas-api-client/api/appointments.rb in supersaas-api-client-1.1.1 vs lib/supersaas-api-client/api/appointments.rb in supersaas-api-client-2.0.0
- old
+ new
@@ -1,30 +1,33 @@
+# frozen_string_literal: true
+
module Supersaas
# REF: https://www.supersaas.com/info/dev/appointment_api
class Appointments < BaseApi
- def agenda(schedule_id, user_id, from_time=nil)
+ def agenda(schedule_id, user_id, from_time = nil, slot = false)
path = "/agenda/#{validate_id(schedule_id)}"
params = {
user: validate_present(user_id),
from: from_time && validate_datetime(from_time)
}
+ params.merge!(slot: true) if slot
res = client.get(path, params)
map_slots_or_bookings(res)
end
- def agenda_slots(schedule_id, user_id, from_time=nil)
+ def agenda_slots(schedule_id, user_id, from_time = nil)
path = "/agenda/#{validate_id(schedule_id)}"
params = {
user: validate_present(user_id),
from: from_time && validate_datetime(from_time),
slot: true
}
res = client.get(path, params)
map_slots_or_bookings(res, true)
end
- def available(schedule_id, from_time, length_minutes=nil, resource=nil, full=nil, limit=nil)
+ def available(schedule_id, from_time, length_minutes = nil, resource = nil, full = nil, limit = nil)
path = "/free/#{validate_id(schedule_id)}"
params = {
length: length_minutes && validate_number(length_minutes),
from: validate_datetime(from_time),
resource: resource,
@@ -33,31 +36,31 @@
}
res = client.get(path, params)
map_slots_or_bookings(res)
end
- def list(schedule_id, form=nil, start_time=nil, limit=nil)
- path = "/bookings"
+ def list(schedule_id, form = nil, start_time = nil, limit = nil)
+ path = '/bookings'
params = {
- schedule_id: validate_id(schedule_id),
- form: form ? true : nil,
- start: start_time ? validate_datetime(start_time) : nil,
- limit: limit && validate_number(limit)
+ schedule_id: validate_id(schedule_id),
+ form: form ? true : nil,
+ start: start_time ? validate_datetime(start_time) : nil,
+ limit: limit && validate_number(limit)
}
res = client.get(path, params)
map_slots_or_bookings(res)
end
def get(schedule_id, appointment_id)
- params = {schedule_id: validate_id(schedule_id)}
+ params = { schedule_id: validate_id(schedule_id) }
path = "/bookings/#{validate_id(appointment_id)}"
res = client.get(path, params)
Supersaas::Appointment.new(res)
end
- def create(schedule_id, user_id, attributes, form=nil, webhook=nil)
- path = "/bookings"
+ def create(schedule_id, user_id, attributes, form = nil, webhook = nil)
+ path = '/bookings'
params = {
schedule_id: schedule_id,
webhook: webhook,
user_id: validate_id(user_id),
form: form ? true : nil,
@@ -81,20 +84,18 @@
}
}
client.post(path, params)
end
- def update(schedule_id, appointment_id, attributes, form=nil, webhook=nil)
+ def update(schedule_id, appointment_id, attributes, form = nil, webhook = nil)
path = "/bookings/#{validate_id(appointment_id)}"
params = {
schedule_id: schedule_id,
- webhook: webhook,
- form: form,
booking: {
start: attributes[:start],
finish: attributes[:finish],
- name: validate_present(attributes[:name]),
+ name: attributes[:name],
email: attributes[:email],
full_name: attributes[:full_name],
address: attributes[:address],
mobile: attributes[:mobile],
phone: attributes[:phone],
@@ -106,37 +107,43 @@
super_field: attributes[:super_field],
resource_id: attributes[:resource_id],
slot_id: attributes[:slot_id]
}
}
+
+ params.merge!(form: form) if form
+ params.merge!(webhook: webhook) if webhook
+ params[:booking].compact!
client.put(path, params)
end
def delete(schedule_id, appointment_id)
path = "/bookings/#{validate_id(appointment_id)}"
- params = {schedule_id: validate_id(schedule_id)}
+ params = { schedule_id: validate_id(schedule_id) }
client.delete(path, nil, params)
end
- def changes(schedule_id, from_time=nil, to=nil, slot=false)
+ def changes(schedule_id, from_time = nil, to = nil, slot = false, user = nil, limit = nil, offset = nil)
path = "/changes/#{validate_id(schedule_id)}"
- params = build_param({}, from_time, to, slot)
+ params = build_param({}, from_time, to, slot, user, limit, offset)
res = client.get(path, params)
map_slots_or_bookings(res)
end
- def range(schedule_id, today=false, from_time=nil, to=nil, slot=false)
+ def range(schedule_id, today = false, from_time = nil, to = nil, slot = false, user = nil, resource_id = nil, service_id = nil,
+ limit = nil, offset = nil)
path = "/range/#{validate_id(schedule_id)}"
- params = {}; params.merge!(today: true) if today
- params = build_param(params, from_time, to, slot)
+ params = {}
+ params.merge!(today: true) if today
+ params = build_param(params, from_time, to, slot, user, limit, offset, resource_id, service_id)
res = client.get(path, params)
map_slots_or_bookings(res)
end
private
- def map_slots_or_bookings(obj, slot=false)
+ def map_slots_or_bookings(obj, slot = false)
if obj.is_a?(Array) && slot
obj.map { |attributes| Supersaas::Slot.new(attributes) }
elsif obj.is_a?(Array)
obj.map { |attributes| Supersaas::Appointment.new(attributes) }
elsif obj['slots']
@@ -146,13 +153,18 @@
else
[]
end
end
- def build_param(params, from_time, to, slot)
+ def build_param(params, from_time, to, slot, user, limit, offset, resource_id = nil, service_id = nil)
params.merge!(from: validate_datetime(from_time)) if from_time
params.merge!(to: validate_datetime(to)) if to
params.merge!(slot: true) if slot
+ params.merge!(user: validate_user(user)) if user
+ params.merge!(limit: validate_number(limit)) if limit
+ params.merge!(offset: validate_number(offset)) if offset
+ params.merge!(resource_id: validate_id(resource_id)) if resource_id
+ params.merge!(service_id: validate_id(service_id)) if service_id
params
end
end
-end
\ No newline at end of file
+end