Class: IHub::Appointments::Response

Inherits:
Common::Base show all
Includes:
Common::Client::Concerns::ServiceStatus
Defined in:
lib/ihub/appointments/response.rb

Constant Summary

Constants included from Common::Client::Concerns::ServiceStatus

Common::Client::Concerns::ServiceStatus::RESPONSE_STATUS

Instance Attribute Summary

Attributes inherited from Common::Base

#errors_hash

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Common::Base

#changed, #changed?, #changes, default_sort, filterable_attributes, max_per_page, per_page, sortable_attributes

Constructor Details

#initialize(attributes = nil) ⇒ Response

Returns a new instance of Response.



15
16
17
18
# File 'lib/ihub/appointments/response.rb', line 15

def initialize(attributes = nil)
  super(attributes) if attributes
  self.status = attributes[:status]
end

Class Method Details

.from(response) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/ihub/appointments/response.rb', line 20

def self.from(response)
  all_appointments = response.body&.fetch('data', [])

  new(
    status: response.status,
    appointments: IHub::Models::Appointment.build_all(all_appointments)
  )
end

Instance Method Details

#cache?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/ihub/appointments/response.rb', line 33

def cache?
  ok?
end

#metadataObject



37
38
39
# File 'lib/ihub/appointments/response.rb', line 37

def 
  { status: response_status }
end

#ok?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/ihub/appointments/response.rb', line 29

def ok?
  status == 200
end

#response_statusObject



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/ihub/appointments/response.rb', line 41

def response_status
  case status
  when 200
    RESPONSE_STATUS[:ok]
  when 403
    RESPONSE_STATUS[:not_authorized]
  when 404
    RESPONSE_STATUS[:not_found]
  else
    RESPONSE_STATUS[:server_error]
  end
end