Search code examples
ruby-on-railsrubysoapsavonsoap4r

How to deal with Savon Responses?


I do not understand the people who prefer Savon to Soap4r.

How can I get the attributes of the returned object in a Savon response? With soap4r it's as clean as invoking a getter!

Apparently, in Savon I need to explicitly parse the response and walk the response_hash. This is way worse than the soap4r approach. Am I getting something wrong, or is Savon just a worse-quality soap4r?

edit: this question was due to savon not properly supporting multi_ref responses, as stated in an answer comment.


Solution

  • From https://github.com/raldred/savon/blob/master/lib/savon/response.rb

      # You can also let Savon translate the SOAP response body to a Hash.
      #
      #   response.to_hash
      #   => { :findUserByIdResponse => {
      #   =>   :id => "123",
      #   =>   :username => "eve"
      #   =>   :active => true
      #   => }
    

    So you should be able to call hash[:object] which would return attribute.

    You dont need to walk the response object just call to_hash.