How to pass Array as parameter to SOAP in Ruby

后端 未结 1 1607
鱼传尺愫
鱼传尺愫 2021-02-11 05:38

Currently I\'m using Savon to work with WebService in ruby. It works pretty well but I have difficulty to pass parameter for argument of SOAP array type. Following code doesn\'t

相关标签:
1条回答
  • 2021-02-11 06:13

    I just stumbled on the same problem and the temporary workaround that worked for me is as follows:

    ids = [0,1,2]
    client.do_get_items { |soap| soap.body = {
      'item-list' => {
        'item1' => 0,
        'item2' => 1,
        'item3' => 2
      }  
    }
    

    The names "item1", "item2" shouldn't matter at all.

    I use the following helper method to convert regular arrays into SOAP mess:

    def soap_array(array)
      returning({}) do |hash|
        array.each_with_index do |e, i|
          hash["item-#{i}"] = e
        end
      end
    end
    
    0 讨论(0)
提交回复
热议问题