Class: Trufina::Response

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

Class Method Summary collapse

Class Method Details

.parse(raw_xml) ⇒ Object

Given returned Trufina XML, instantiate the proper HappyMapper wrapper.

(Note that this does not perform any error checking beyond unknown root node name – the higher level error checking is handled in the Trufina.parseFromTrufina method)



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/responses.rb', line 10

def self.parse(raw_xml)
  xml = LibXML::XML::Parser.string(raw_xml).parse
  
  puts "Received XML:\n\n#{xml}\n\n" if Trufina::Config.debug?
  
  # Try to find an appropriate local happymapper class
  begin
    klass = "Trufina::Responses::#{xml.root.name.gsub('Trufina', '')}".constantize
    return klass.parse(xml)
  rescue
    raise Exceptions::UnknownResponseType.new("Raw XML: \n\n#{xml}")
  end
end