Class: Nova::API::ListResponse

Inherits:
Utils::BaseStruct show all
Defined in:
lib/nova/api/list_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, klass) ⇒ Object



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

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

  parsed_response = response.parsed_response

  records = nil

  if parsed_response.is_a?(Array)
    records = build_records(klass, parsed_response)
  else
    parsed_response = parsed_response.to_h

    errors = extract_error_from_response('error', parsed_response)
    errors ||= extract_error_from_response('errors', parsed_response)
  end

  errors ||= []

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