lib/savon/soap/xml.rb in savon-0.8.3 vs lib/savon/soap/xml.rb in savon-0.8.4

- old
+ new

@@ -18,26 +18,32 @@ SchemaTypes = { "xmlns:xsd" => "http://www.w3.org/2001/XMLSchema", "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance" } - # Converts the given SOAP response +xml+ into a Hash. - def self.to_hash(xml) - (Crack::XML.parse(xml) rescue {}).find_soap_body + # Converts the given SOAP response +value+ (XML or Hash) into a normalized Hash. + def self.to_hash(value) + value = parse value unless value.kind_of? Hash + value.find_soap_body end + # Converts a given SOAP response +xml+ to a Hash. + def self.parse(xml) + Crack::XML.parse(xml) rescue {} + end + # Expects a SOAP response XML or Hash, traverses it for a given +path+ of Hash keys # and returns the value as an Array. Defaults to return an empty Array in case the # path does not exist or returns nil. def self.to_array(object, *path) hash = object.kind_of?(Hash) ? object : to_hash(object) - + result = path.inject hash do |memo, key| return [] unless memo[key] memo[key] end - + result.kind_of?(Array) ? result.compact : [result].compact end # Accepts an +endpoint+, an +input+ tag and a SOAP +body+. def initialize(endpoint = nil, input = nil, body = nil) @@ -96,10 +102,19 @@ # Returns the default namespace identifier. def namespace_identifier @namespace_identifier ||= :wsdl end + # Returns whether all local elements should be namespaced. Might be set to :qualified, + # but defaults to :unqualified. + def element_form_default + @element_form_default ||= :unqualified + end + + # Sets whether all local elements should be namespaced. + attr_writer :element_form_default + # Accessor for the default namespace URI. attr_accessor :namespace # Accessor for the <tt>Savon::WSSE</tt> object. attr_accessor :wsse @@ -157,10 +172,11 @@ wsse.respond_to?(:to_xml) ? wsse.to_xml : "" end # Returns the SOAP body as an XML String. def body_to_xml - body.kind_of?(Hash) ? Gyoku.xml(body) : body.to_s + return body.to_s unless body.kind_of? Hash + Gyoku.xml body, :element_form_default => element_form_default, :namespace => namespace_identifier end end end end