Class: Supersaas::Appointments

Inherits:
BaseApi
  • Object
show all
Defined in:
lib/supersaas-api-client/api/appointments.rb

Overview

Constant Summary

Constants inherited from BaseApi

BaseApi::DATETIME_REGEX, BaseApi::INTEGER_REGEX, BaseApi::PROMOTION_REGEX

Instance Attribute Summary

Attributes inherited from BaseApi

#client

Instance Method Summary collapse

Methods inherited from BaseApi

#initialize

Constructor Details

This class inherits a constructor from Supersaas::BaseApi

Instance Method Details

#agenda(schedule_id, user_id, from_time = nil, slot = false) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/supersaas-api-client/api/appointments.rb', line 6

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

#agenda_slots(schedule_id, user_id, from_time = nil) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/supersaas-api-client/api/appointments.rb', line 17

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

#available(schedule_id, from_time, length_minutes = nil, resource = nil, full = nil, limit = nil) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/supersaas-api-client/api/appointments.rb', line 28

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,
    full: full ? true : nil
  }
  params.merge!(maxresults: validate_number(limit)) if limit
  res = client.get(path, params)
  map_slots_or_bookings(res)
end

#changes(schedule_id, from_time = nil, to = nil, slot = false, user = nil, limit = nil, offset = nil) ⇒ Object



126
127
128
129
130
131
# File 'lib/supersaas-api-client/api/appointments.rb', line 126

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, user, limit, offset)
  res = client.get(path, params)
  map_slots_or_bookings(res)
end

#create(schedule_id, user_id, attributes, form = nil, webhook = nil) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/supersaas-api-client/api/appointments.rb', line 60

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,
    booking: {
      start: attributes[:start],
      finish: attributes[:finish],
      name: attributes[:name],
      email: attributes[:email],
      full_name: attributes[:full_name],
      address: attributes[:address],
      mobile: attributes[:mobile],
      phone: attributes[:phone],
      country: attributes[:country],
      field_1: attributes[:field_1],
      field_2: attributes[:field_2],
      field_1_r: attributes[:field_1_r],
      field_2_r: attributes[:field_2_r],
      super_field: attributes[:super_field],
      resource_id: attributes[:resource_id],
      slot_id: attributes[:slot_id]
    }
  }
  params[:booking].compact!
  client.post(path, params)
end

#delete(schedule_id, appointment_id) ⇒ Object



120
121
122
123
124
# File 'lib/supersaas-api-client/api/appointments.rb', line 120

def delete(schedule_id, appointment_id)
  path = "/bookings/#{validate_id(appointment_id)}"
  params = { schedule_id: validate_id(schedule_id) }
  client.delete(path, nil, params)
end

#get(schedule_id, appointment_id) ⇒ Object



53
54
55
56
57
58
# File 'lib/supersaas-api-client/api/appointments.rb', line 53

def get(schedule_id, appointment_id)
  params = { schedule_id: validate_id(schedule_id) }
  path = "/bookings/#{validate_id(appointment_id)}"
  res = client.get(path, params)
  Supersaas::Appointment.new(res)
end

#list(schedule_id, form = nil, start_time = nil, limit = nil) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/supersaas-api-client/api/appointments.rb', line 41

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
  }
  params.merge!(limit: validate_number(limit)) if limit
  res = client.get(path, params)
  map_slots_or_bookings(res)
end

#range(schedule_id, today = false, from_time = nil, to = nil, slot = false, user = nil, resource_id = nil, service_id = nil, limit = nil, offset = nil) ⇒ Object



133
134
135
136
137
138
139
140
141
# File 'lib/supersaas-api-client/api/appointments.rb', line 133

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 = build_param(params, from_time, to, slot, user, limit, offset, resource_id, service_id)
  params.merge!(today: true) if today
  res = client.get(path, params)
  map_slots_or_bookings(res)
end

#update(schedule_id, appointment_id, attributes, form = nil, webhook = nil) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/supersaas-api-client/api/appointments.rb', line 90

def update(schedule_id, appointment_id, attributes, form = nil, webhook = nil)
  path = "/bookings/#{validate_id(appointment_id)}"
  params = {
    schedule_id: schedule_id,
    booking: {
      start: attributes[:start],
      finish: attributes[:finish],
      name: attributes[:name],
      email: attributes[:email],
      full_name: attributes[:full_name],
      address: attributes[:address],
      mobile: attributes[:mobile],
      phone: attributes[:phone],
      country: attributes[:country],
      field_1: attributes[:field_1],
      field_2: attributes[:field_2],
      field_1_r: attributes[:field_1_r],
      field_2_r: attributes[:field_2_r],
      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