Class: Nova::API::Response

Inherits:
Utils::BaseStruct show all
Defined in:
lib/nova/api/response.rb

Constant Summary

Constants inherited from Utils::BaseStruct

Utils::BaseStruct::DATE_REGEX

Class Method Summary collapse

Methods inherited from Utils::BaseStruct

#allowed_attributes

Class Method Details

.build(response, object = nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/nova/api/response.rb', line 13

def self.build(response, object = nil)
  success = response.success?
  status = response.code

  parsed_response = response.parsed_response.to_h

  record = nil

  errors = extract_error_from_response('error', parsed_response)
  errors ||= extract_error_from_response('errors', parsed_response)
  errors ||= []

  if object
    record = object.class.new(object.attributes.merge(parsed_response))
  end

  new(success: success, errors: errors, record: record, status: status)
end