class Nova::API::Response
Public Class Methods
build(response, object = nil)
click to toggle source
# 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
Private Class Methods
extract_error_from_response(field, response)
click to toggle source
# File lib/nova/api/response.rb, line 34 def self.extract_error_from_response(field, response) return unless response.has_key?(field) response[field].is_a?(Array) ? response[field] : [response[field]] end