Class: BadgevilleBerlin::Errors
- Inherits:
-
ActiveResource::Errors
- Object
- ActiveResource::Errors
- BadgevilleBerlin::Errors
- Defined in:
- lib/badgeville_berlin/errors.rb
Overview
Subclasses ActiveResource::Errors to be used by BaseResource as BadgevilleBerlin::Errors.
Instance Method Summary collapse
-
#from_badgeville_berlin_json(json, save_cache = false) ⇒ Object
Grabs errors from the :badgeville_berlin_json response remote model originating from teh remote class.
Instance Method Details
#from_badgeville_berlin_json(json, save_cache = false) ⇒ Object
Grabs errors from the :badgeville_berlin_json response remote model originating from teh remote class. The custom JSON error response format may not have a root key :errors.
BadgevilleBerlinJsonFormat cleared by default
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/badgeville_berlin/errors.rb', line 13 def from_badgeville_berlin_json(json, save_cache = false) formatted_json_decoded = Array.new json_decoded = (ActiveSupport::JSON.decode(json))['errors'] || ActiveSupport::JSON.decode(json) rescue [] json_decoded.each do |attribute_name, err_msgs| if err_msgs.is_a? Array err_msgs.each do |err_msg| formatted_json_decoded.push(attribute_name.humanize + " #{err_msg}") end elsif err_msgs.is_a? String formatted_json_decoded.push(attribute_name, err_msgs) end end from_array formatted_json_decoded, save_cache end |