Class: SoapResponseDecoder

Inherits:
Object
  • Object
show all
Defined in:
lib/config/savon_config.rb

Overview

Decode multi-ref soap references.

Class Method Summary collapse

Class Method Details

.convert_hash_keys(value) ⇒ Object



45
46
47
48
49
50
51
52
53
54
# File 'lib/config/savon_config.rb', line 45

def self.convert_hash_keys(value)
  case value
    when Array
      value.map { |v| convert_hash_keys(v) }
    when Hash
      Hash[value.map { |k, v| [underscore_key(k), convert_hash_keys(v)] if k != 'xsi:type' }]
    else
      value
   end
end

.decode(xml_doc) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/config/savon_config.rb', line 28

def self.decode( xml_doc )
  doc = Nokogiri::XML xml_doc

  while( el = doc.xpath('//soapenv:Body//*[@href]').first )
    id = el.attribute('href').value.gsub('#', '')
    el.children = doc.xpath("//soapenv:Body//multiRef[@id='#{id}']").children()
    el.remove_attribute('href')
  end

  hash = convert_hash_keys( Hash.from_xml( doc.to_s ) )[:envelope][:body]
end

.underscore_key(k) ⇒ Object



41
42
43
# File 'lib/config/savon_config.rb', line 41

def self.underscore_key(k)
  k.to_s.underscore.to_sym
end