lib/sem4r/services/soap_message_v13.rb in sem4r-0.1.1 vs lib/sem4r/services/soap_message_v13.rb in sem4r-0.1.2
- old
+ new
@@ -41,26 +41,31 @@
def send(service_url, soap_action)
soap_message = build_soap_message
response_xml = @connector.send(service_url, soap_action, soap_message)
# erase namespace 'nsX'so it more simple parsing the xml
- response_xml = response_xml.gsub(/ns\d:/, "")
- @response = REXML::Document.new(response_xml)
+ # response_xml = response_xml.gsub(/ns\d:/, "")
+ # @response = REXML::Document.new(response_xml)
+ response_xml.gsub!(/\b(ns\d:|xsi:|s:|soapenv:|env:|soap:)/, "")
+ response_xml.gsub!(/xmlns=["'].*?['"]/, '')
+ @response = Nokogiri::XML::Document.parse(response_xml)
+
# extract information from header
# <soapenv:Header>
# <responseTime soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next" soapenv:mustUnderstand="0" xmlns="https://adwords.google.com/api/adwords/v13">16</responseTime>
# <operations soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next" soapenv:mustUnderstand="0" xmlns="https://adwords.google.com/api/adwords/v13">5</operations>
# <units soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next" soapenv:mustUnderstand="0" xmlns="https://adwords.google.com/api/adwords/v13">5</units>
# <requestId soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next" soapenv:mustUnderstand="0" xmlns="https://adwords.google.com/api/adwords/v13">abade53d3dbecd45600e7d14563f10f1</requestId>
# </soapenv:Header>
- header = REXML::XPath.first(@response, "//soapenv:Header")
+
+ header = @response.xpath("//Header").first
if header
@counters = {
- :response_time => header.elements['responseTime'].text.to_i,
- :operations => header.elements['operations'].text.to_i,
- :units => header.elements['units'].text.to_i
+ :response_time => header.at_xpath('responseTime').text.to_i,
+ :operations => header.at_xpath('operations').text.to_i,
+ :units => header.at_xpath('units').text.to_i
}
end
# check soap fault
#<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
@@ -75,13 +80,14 @@
# </fault>
# </detail>
# </soapenv:Fault>
# </soapenv:Body>
#</soapenv:Envelope>
- fault_el = REXML::XPath.first(@response, "//soapenv:Fault")
+ #=======
+ fault_el = @response.xpath("//Fault").first
if fault_el
- fault_code = fault_el.elements['faultcode'].text
- fault_string = fault_el.elements['faultstring'].text
+ fault_code = fault_el.at_xpath('faultcode').text
+ fault_string = fault_el.at_xpath('faultstring').text
raise SoapError, "#{fault_code}: '#{fault_string}'"
end
self
end
\ No newline at end of file