Module: Daylight::Errors::ClassMethods

Defined in:
lib/daylight/errors.rb

Instance Method Summary collapse

Instance Method Details

#from_json(json) ⇒ Object

Parse payload that is in JSON – Examples:

is the problem’ is problem one’,‘this is problem two’]



64
65
66
67
68
69
70
71
# File 'lib/daylight/errors.rb', line 64

def from_json(json)
  decoded = ActiveSupport::JSON.decode(json) || {} rescue {}
  if decoded.kind_of?(Hash) && decoded.has_key?('errors')
    Array.wrap(decoded['errors'])
  else
    []
  end
end

#from_xml(xml) ⇒ Object

Parse payload that is in XML – Examples: <errors>

<error>this is a Problem<error>

</errors> <errors>

<error>this is problem one<error>
<error>this is problem one<error>

</errors>



84
85
86
# File 'lib/daylight/errors.rb', line 84

def from_xml(xml)
  Array.wrap(Hash.from_xml(xml)['errors']['error']) rescue []
end