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

前端之家收集整理的这篇文章主要介绍了ruby – 传递Savon 2(SOAP)的数组元素前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试使用从Apo api获取帐户信息的Savon gem(v2)编写 Ruby代码,但是我在传递Array时遇到问题.

CampaignIds应该是一个整数数组.

这是我的代码

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)

其产生以下请求:

<?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>

而如果我在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>

有任何想法吗?

解决方法

你可以尝试这种语法:
message = {
  ...
  "CampaignIds" => {"int" => [3,4]},...
}

这将产生此输出

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

希望这可以帮助.

猜你在找的Ruby相关文章