Class: Antaeus::Resources::Appointment

Inherits:
Antaeus::Resource show all
Defined in:
lib/antaeus-sdk/resources/appointment.rb

Instance Attribute Summary

Attributes inherited from Antaeus::Resource

#client, #errors

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Antaeus::Resource

#<=>, all, delayed_property, #destroy, #fresh?, gen_property_methods, get, human, i18n_key, #id, immutable, #immutable?, immutable?, #initialize, #model_name, #new?, param_key, path, path_for, #path_for, paths, #paths, #persisted?, properties, property, #reload, route_key, #save, search, singular_route_key, #tainted?, #to_key, #to_model, #to_param, #update, where

Constructor Details

This class inherits a constructor from Antaeus::Resource

Class Method Details

.report(options = {}) ⇒ Object

Generate a report of appointments based on some criteria



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/antaeus-sdk/resources/appointment.rb', line 38

def self.report(options = {})
  validate_options(options)
  ResourceCollection.new(
    options[:client].post("/reports/generate", q: options[:criteria])['appointments'].collect do |record|
      self.new(
        entity: record,
        lazy: false,
        tainted: false,
        client: options[:client]
      )
    end,
    type: self,
    client: options[:client]
  )
end

.upcoming(options = {}) ⇒ Object

A collection of all upcoming appointments



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/antaeus-sdk/resources/appointment.rb', line 21

def self.upcoming(options = {})
  validate_options(options)
  ResourceCollection.new(
    options[:client].get("#{path_for(:all)}/upcoming")['appointments'].collect do |record|
      self.new(
        entity: record,
        lazy: true,
        tainted: false,
        client: options[:client]
      )
    end,
    type: self,
    client: options[:client]
  )
end

Instance Method Details

#approveObject

Approve an Appointment



55
56
57
58
59
60
61
62
63
# File 'lib/antaeus-sdk/resources/appointment.rb', line 55

def approve
  if @client.patch("#{path_for(:all)}/#{id}/approve", approve: true)
    true
  else
    fail Exceptions::ApprovalChangeFailed
  end
  reload
  return true
end

#checkinObject

Checkin a Guest



66
67
68
69
70
71
72
73
74
# File 'lib/antaeus-sdk/resources/appointment.rb', line 66

def checkin
  if @client.patch("#{path_for(:all)}/#{id}/checkin", email: guest.email)
    true
  else
    raise Exceptions::CheckinChangeFailed
  end
  reload
  return true
end

#checkoutObject

Checkout a Guest



77
78
79
80
81
82
83
84
85
# File 'lib/antaeus-sdk/resources/appointment.rb', line 77

def checkout
  if @client.patch("#{path_for(:all)}/#{id}/checkout", email: guest.email)
    true
  else
    raise Exceptions::CheckoutChangeFailed
  end
  reload
  return true
end

#guestObject

Hidden property used to lookup related resource



88
89
90
# File 'lib/antaeus-sdk/resources/appointment.rb', line 88

def guest
  Guest.get(@entity['guest_id'], client: @client)
end

#guest=(guest_or_guest_id) ⇒ Object

Set the guest associated with this appointment



93
94
95
96
97
98
99
100
# File 'lib/antaeus-sdk/resources/appointment.rb', line 93

def guest=(guest_or_guest_id)
  @entity['guest_id'] = if guest_or_guest_id.is_a?(Guest)
    guest_or_guest_id.id
  else
    guest_or_guest_id
  end
  @tainted = true
end

#locationObject

Hidden property used to lookup related resource



103
104
105
# File 'lib/antaeus-sdk/resources/appointment.rb', line 103

def location
  Location.get(@entity['location_id'], client: @client)
end

#location=(location_or_location_id) ⇒ Object

Set the location associated with this appointment



108
109
110
111
112
113
114
115
# File 'lib/antaeus-sdk/resources/appointment.rb', line 108

def location=(location_or_location_id)
  @entity['location_id'] = if location_or_location_id.is_a?(Location)
    location_or_location_id.id
  else
    location_or_location_id
  end
  @tainted = true
end

#unapproveObject

Unapprove an Appointment



118
119
120
121
122
123
124
125
126
# File 'lib/antaeus-sdk/resources/appointment.rb', line 118

def unapprove
  if @client.patch("#{path_for(:all)}/#{id}/approve", approve: false)
    true
  else
    fail Exceptions::ApprovalChangeFailed
  end
  reload
  return true
end

#undo_checkinObject

Checkin a Guest



129
130
131
132
133
134
135
136
137
# File 'lib/antaeus-sdk/resources/appointment.rb', line 129

def undo_checkin
  if @client.delete("#{path_for(:all)}/#{id}/checkin")
    true
  else
    raise Exceptions::CheckinChangeFailed
  end
  reload
  return true
end

#undo_checkoutObject

Checkout a Guest



140
141
142
143
144
145
146
147
148
# File 'lib/antaeus-sdk/resources/appointment.rb', line 140

def undo_checkout
  if @client.delete("#{path_for(:all)}/#{id}/checkout")
    true
  else
    raise Exceptions::CheckoutChangeFailed
  end
  reload
  return true
end

#userObject

User related to an appointment



151
152
153
# File 'lib/antaeus-sdk/resources/appointment.rb', line 151

def user
  User.get(contact, client: @client)
end

#user=(username) ⇒ Object

Set the user related to an appointment



156
157
158
159
160
161
162
163
# File 'lib/antaeus-sdk/resources/appointment.rb', line 156

def user=(username)
  contact = if username.is_a?(User)
    username.id
  else
    username
  end
  @tainted = true
end