使用rest-client从eBay下载zip文件

时间:2017-09-12 07:49:13

标签: ruby-on-rails rest-client ebay-api

我想从eBay下载zip文件。使用downloadfile api。

response = RestClient.post(url,xml,headers)

这个调用返回了我认为在xml中不可行的zip文件的内容。所以我想从eBay下载zip文件。

我的代码是:

headers = { 
 "X-EBAY-SOA-OPERATION-NAME"=>"downloadFile",
 "X-EBAY-SOA-SECURITY-TOKEN" => access_token_lister,
 "X-EBAY-API-SITEID"=>"0",
 "Content-Type"=>"application/zip"
}
url = 'https://storage.ebay.com/FileTransferService' 

xml = '<?xml version="1.0" 
encoding="utf-8"?> <downloadFileRequest xmlns="ebay.com/marketplace/services">; <fileReferenceId>6637191637</fileReferenceId> <taskReferenceId>6474385857</taskReferenceId> </downloadFileRequest>'

上面提到的API文档可以在这里找到:http://developer.ebay.com/devzone/file-transfer/CallRef/downloadFile.html

1 个答案:

答案 0 :(得分:0)

您必须将响应内容传递给rubyzip等库。然后使用它从压缩文件中提取文件。您可以先将文件写入磁盘,然后使用rubyzip读取它。

具体看一下rubyzip文档的这一部分 - Reading a Zip file来完成你想要实现的目标。