Class: Zuora::Response
- Inherits:
-
Object
- Object
- Zuora::Response
- Defined in:
- lib/zuora/response.rb
Constant Summary collapse
- ERROR_STRINGS =
['Missing required value', 'are required fields'].freeze
Instance Attribute Summary collapse
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
Instance Method Summary collapse
- #handle_errors(hash) ⇒ Object
- #initialize(response) ⇒ Zuora::Response constructor
-
#to_h ⇒ Hashie::Mash
Convert XML body to object-like nested hash.
Constructor Details
#initialize(response) ⇒ Zuora::Response
10 11 12 |
# File 'lib/zuora/response.rb', line 10 def initialize(response) @raw = response end |
Instance Attribute Details
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
6 7 8 |
# File 'lib/zuora/response.rb', line 6 def raw @raw end |
Instance Method Details
#handle_errors(hash) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/zuora/response.rb', line 23 def handle_errors(hash) errors = [] hash.each do |key, value| if value.is_a?(Hash) handle_errors(value) elsif value.is_a?(Array) value.each { |v| handle_errors(v) unless v.is_a?(String) } elsif error?(key, value) errors << value end end raise_errors(errors) if errors.present? end |
#to_h ⇒ Hashie::Mash
Convert XML body to object-like nested hash.
16 17 18 19 20 |
# File 'lib/zuora/response.rb', line 16 def to_h doc = Nokogiri::XML raw.body hash = Hash.from_xml doc.to_xml Hashie::Mash.new(symbolize_keys_deep(hash)) end |