2014-01-07 70 views
11

我試圖用Savon gem(v2)從SOAP api獲取帳戶信息的Ruby中編寫代碼,但我遇到傳遞數組的問題。傳遞數組元素爲薩翁2(SOAP)

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> 

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

任何想法?

回答

18

你可以試試這個語法:

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

這會產生這樣的輸出:

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

希望這有助於。

+2

謝謝,我能夠做 ' 「CampaignIds」=>弄明白{ 「ins0:INT」=> 3}' –

+0

我累ins0:INT,我試着INT,既有我得到:的SOAPFault :嘗試寫入結束元素時,沒有打開的開始元素。然後,我嘗試在肥皂用戶界面中添加type =「int」和xsi:type =「xsd:int」作爲元素中的屬性,我需要一個int。使用我得到的屬性:422 Unprocessable Entity:服務器遇到錯誤。所有這些我嘗試了文字和編碼。請指教 – KacieHouser