Map XML arguments to ruby class while using wash-out gem for SOAP request

194 Views Asked by At

I'm using wash-out gem (https://github.com/inossidabile/wash_out) for exposing a SOAP service.

Sample usage of wash-out documentation goes something like this:

# Params from XML attributes;
  # e.g. for a request to the 'AddCircle' action:
  #   <soapenv:Envelope>
  #     <soapenv:Body>
  #       <AddCircle>
  #         <Circle radius="5.0">
  #           <Center x="10" y="12" />
  #         </Circle>
  #       </AddCircle>
  #     </soapenv:Body>
  #   </soapenv:Envelope>
  soap_action "AddCircle",
              :args   => { :circle => { :center => { :@x => :integer,
                                                     :@y => :integer },
                                        :@radius => :double } },
              :return => nil, # [] for wash_out below 0.3.0
              :to     => :add_circle
  def add_circle
    circle = params[:circle]
    Circle.new(circle[:center][:x], circle[:center][:y], circle[:radius])

    render :soap => nil
  end

But my XML request has many nested arguments and I don't want to define mappings (:args) for each XML attribute. Is there any way to map the XML request (XSD) to a ruby hash into a form which is required as :args for the soap action.

1

There are 1 best solutions below

1
Sebastian Estrada On

I dont know any way to do that without mapping every nested attribute one by one to a ruby object, but you can try to use the xml-mapping gem and try to test what you want.