LuisVM
LuisVM

Reputation: 2793

Savon: How can I specify a custom XML in a hash body for a SOAP request?

In a SOAP Request, I need to specify repeated keys with different values like this:

soap.body = {:query => {
    :fields => {
        :string => 'Email',
        :string => 'FirstName',
        :string => 'LastName'
    }
}

With this hash, the request will be formed with:

<query><fields><string>LastName</string></fields></query>

The last :string pair. So if I put:

soap.body = {:query => {
    :fields => "<string>Email</string>FirstName<string></string>LastName<string></string>"
}

This will result in:

<fields>&lt;string&gt;Email&lt;/string&gt;&lt;string&gt;FirstName&lt;/string&gt;&lt;string&gt;LastName&lt;/string&gt;</fields>

Is there a way to get this in a hash?:

<query><fields><string>Email</string><string>FirstName</string><string>LastName</string></fields></query>

Note: I'm using Ruby 1.8.7.

Upvotes: 1

Views: 889

Answers (1)

tokland
tokland

Reputation: 67880

Your first code cannot work and it's not Savon's fault, repeated keys in a hash are simply overriden. Did you try with an array?

soap.body = {
  :query => {
    :fields => {:string => ['Email', 'FirstName', 'LastName'],
  }
}

Check also this: https://github.com/rubiii/savon/issues/45

Upvotes: 1

Related Questions