Class: Zuora::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/zuora/response.rb

Constant Summary collapse

ERROR_STRINGS =
['Missing required value', 'are required fields'].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Zuora::Response

Parameters:

  • (Faraday::Response)


10
11
12
# File 'lib/zuora/response.rb', line 10

def initialize(response)
  @raw = response
end

Instance Attribute Details

#rawObject (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

Parameters:

  • hash (Hash)


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_hHashie::Mash

Convert XML body to object-like nested hash.

Returns:

  • (Hashie::Mash)

    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