2

I'm using Savon in my RoR app.

This is my call to the service:

client = Savon::Client.new(MY_SOAP_CLIENT)

response = client.request :wsdl, :get_history do
    soap.body = "<startDate>2011-09-23</startDate><endDate>2011-09-24</endDate><userId>3</userId>"
end

And I'm getting the next response in XML:

<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">
<soapenv:Body xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">
<resMessage xmlns=\"http://xxx-xxx.xxx.edu/xxx/\">
    <result>date=2011-09-23?amount=13.00?time=08:50:38?user=a00123?type=transfer</result>
    <result>date=2011-09-23?amount=3.00?time=08:51:27?user=a00123456?type=transfer</result>
    <result>date=2011-09-23?amount=20.00?time=09:49:00?user=a00123456?type=transfer</result>
</resMessage></soapenv:Body></soapenv:Envelope>

But, the main problem is when I call response.to_hash I only get the Date objects part:

=> [Fri, 23 Sep 2011, Fri, 23 Sep 2011, Fri, 23 Sep 2011]

This is great for the date, but the other part of the results are missing: amount, time, user and type. Also if I call response.body I keep getting the same results:

=> {:res_message=>{:result=>[Fri, 23 Sep 2011, Fri, 23 Sep 2011, Fri, 23 Sep 2011, Fri, 23 Sep 2011, Fri, 23 Sep 2011], :@xmlns=>"http://xxx-xxx.xxx.edu/xxx/"}, :"@xmlns:soapenv"=>"http://schemas.xmlsoap.org/soap/envelope/"}

I didn't find the solution for this here nor Savon Issues

Thanks in advance

juanpabloe
  • 23
  • 5

1 Answers1

1

You could use:

h = Hash.from_xml(response.to_xml)

and that would give you a correct hash.

Ruby (RoR) XML to hash and then show in views

Community
  • 1
  • 1
ElHacker
  • 1,687
  • 17
  • 18