传递Savon 2的数组元素(SOAP)

时间:2022-04-03 21:30:55

I'm trying to write code in Ruby with the Savon gem (v2) that fetches account information from a SOAP api, but I'm having an issue with passing an Array.

我正在尝试使用从SOAP api获取帐户信息的Savon gem(v2)在Ruby中编写代码,但是我遇到了传递数组的问题。

CampaignIds is supposed to be an array of integers.

CampaignIds应该是一个整数数组。

Here is my code:

这是我的代码:

client = Savon.client(wsdl: "https://api7secure.publicaster.com/Pub7APIV1/Campaign.svc?singleWsdl")

message = {
  "EncryptedAccountID" => api_key,
  "APIPassword" => api_password,
  "CampaignIds" => [3,4],
  "StartDate" => yesterday,
  "EndDate" => yesterday,
  "IncludeTests" => false
}

client.call(:get_comparative_report_details_data, message: message)

which produces the following request:

产生以下要求:

<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ins0="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:tns="http://BlueSkyFactory.Publicaster7.Public.API" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <env:Body>
      <tns:GetComparativeReportDetailsData>
         <tns:EncryptedAccountID>*****</tns:EncryptedAccountID>
         <tns:APIPassword>*****</tns:APIPassword>
         <tns:CampaignIds>3</tns:CampaignIds>
         <tns:CampaignIds>4</tns:CampaignIds>
         <tns:StartDate>2014-01-06</tns:StartDate>
         <tns:EndDate>2014-01-06</tns:EndDate>
         <tns:IncludeTests>false</tns:IncludeTests>
      </tns:GetComparativeReportDetailsData>
   </env:Body>
</env:Envelope>

whereas, if I play around in SOUP UI, the request should look like:

然而,如果我在SOUP UI中玩游戏,请求应如下所示:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:blu="http://BlueSkyFactory.Publicaster7.Public.API" xmlns:arr="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
   <soapenv:Header/>
   <soapenv:Body>
      <blu:GetComparativeReportData>
         <blu:EncryptedAccountID>*****</blu:EncryptedAccountID>
         <blu:APIPassword>*****</blu:APIPassword>
         <blu:CampaignIds>
            <arr:int>3</arr:int>
            <arr:int>4</arr:int>
         </blu:CampaignIds>
         <blu:StartDate>2014-01-06T16:21:47-05:00</blu:StartDate>
         <blu:EndDate>2014-01-07T16:21:47-05:00</blu:EndDate>
         <blu:IncludeTests>false</blu:IncludeTests>
      </blu:GetComparativeReportData>
   </soapenv:Body>
</soapenv:Envelope>

Any Ideas?

有任何想法吗?

1 个解决方案

#1


19  

You can try this syntax :

您可以尝试以下语法:

message = {
  ...
  "CampaignIds" => {"int" => [3,4]},
  ...
}

That'll produce this output :

这将产生这个输出:

<CampaignIds>
  <int>3</int>
  <int>4</int>
</CampaignIds>

Hope this helps.

希望这可以帮助。

#1


19  

You can try this syntax :

您可以尝试以下语法:

message = {
  ...
  "CampaignIds" => {"int" => [3,4]},
  ...
}

That'll produce this output :

这将产生这个输出:

<CampaignIds>
  <int>3</int>
  <int>4</int>
</CampaignIds>

Hope this helps.

希望这可以帮助。