class Cb::Responses::Errors
Attributes
parsed[R]
response[R]
should_raise[R]
Public Class Methods
new(raw_response_hash, raise_on_error = true)
click to toggle source
# File lib/cb/responses/errors.rb, line 16 def initialize(raw_response_hash, raise_on_error = true) @response = raw_response_hash @should_raise = raise_on_error @parsed = parsed_errors end
Private Instance Methods
error_array?(key, value)
click to toggle source
# File lib/cb/responses/errors.rb, line 47 def error_array?(key, value) (key.downcase == 'error' || key.downcase == 'errors') && value.is_a?(Array) end
hashy_errors?(key, value)
click to toggle source
# File lib/cb/responses/errors.rb, line 43 def hashy_errors?(key, value) key.downcase == 'errors' && value.is_a?(Hash) end
method_missing(method, *args, &block)
click to toggle source
# File lib/cb/responses/errors.rb, line 51 def method_missing(method, *args, &block) parsed.send(method, *args, &block) end
parsed_error(key, value)
click to toggle source
# File lib/cb/responses/errors.rb, line 33 def parsed_error(key, value) if hashy_errors?(key, value) value.values elsif error_array?(key, value) value else [] end end
parsed_errors()
click to toggle source
# File lib/cb/responses/errors.rb, line 26 def parsed_errors return [] unless response.respond_to?(:map) errors = response.map { |key, value| parsed_error(key, value) }.flatten fail ApiResponseError.new(errors.join(',')) if errors.any? && should_raise errors end