1

I have this code:

client = Savon.client(wsdl: wsdl)

response = client.call(:post, message: {
  login: {
    userName: username,
    password: password
  },
  data: {
    parameters: {
      key: "firstName",
      value: "Joe"
    }
})

This works, but I need to send multiple parameters. If I have multiple parameters: {mydata} fields, it doesn't work because a hash must have unique keys...

How do I get Savon to send multiple parameter fields?

Mirror318
  • 11,875
  • 14
  • 64
  • 106

1 Answers1

0

I still don't know the proper way, but the message parameter can be an XML string, so I ended up with the following solution:

client = Savon.client(wsdl: wsdl)
response = client.call(:post, message: build_xml)

def build_xml
  "
  #{login_xml}
  <data>
    <code>CUSTOMER_DETAILS</code>
    " + test_data.map { |h| parameter_xml(h.first, h.last) }.join("") + "
  </data>
  "
end

def login_xml
  "
  <login>
    <userName>#{@xml_username}</userName>
    <password>#{@xml_password}</password>
  </login>
  "
end

def parameter_xml(key, val)
  "
  <parameters>
      <key>#{key}</key>
      <value>#{val}</value>
  </parameters>
  "
end
Mirror318
  • 11,875
  • 14
  • 64
  • 106