ruby-on-rails - 在 Rails 中获取 eBay 时间

标签 ruby-on-rails ebay-api net-http

我一直在寻找如何从 eBay 上打发时间.. 我不想使用 SAVON 因为...它不起作用..

所以我尝试使用 net/http,只是为了获得时间。 (暂时)

这是我到目前为止所得到的。

 def get_ebay_time
require "net/http"
require "uri"

devName = 000000000
appName = 000000000
certName = 000000000
authToken = 0000000000

url = URI.parse("https://api.ebay.com/ws/api.dll")

req = Net::HTTP::Post.new(url.path)
req.add_field("X-EBAY-API-COMPATIBILITY-LEVEL", "759")
req.add_field("X-EBAY-API-DEV-NAME", devName)
req.add_field("X-EBAY-API-APP-NAME", appName)
req.add_field("X-EBAY-API-CERT-NAME", certName)
req.add_field("X-EBAY-API-SITEID", "0")
req.add_field("X-EBAY-API-CALL-NAME", "GeteBayOfficialTime")

req.body = '<?xml version="1.0" encoding="utf-8"?>'+
            '<GeteBayOfficialTimeRequest xmlns="urn:ebay:apis:eBLBaseComponents">'+
            '<RequesterCredentials>'+
            "<eBayAuthToken>#{authToken}</eBayAuthToken>"+
            '</RequesterCredentials>'+
            '</GeteBayOfficialTimeRequest>?'

http = Net::HTTP.new(url.host, url.port)
res = http.start do |http_runner|
  http_runner.request(req)
end
return res.body
end

最佳答案

API 包装器的开发是为了提供帮助:)

请使用eBay4r和 github 上的一样:up_the_irons/ebay4r

  require 'rubygems'
  gem 'ebay'

  # Put your credentials in this file
  load('myCredentials.rb')

  # Create new eBay caller object.  Omit last argument to use live platform.
  eBay = EBay::API.new($authToken, $devId, $appId, $certId, :sandbox => true)

  resp = eBay.GeteBayOfficialTime

  puts "Hello, World!"
  puts "The eBay time is now: #{resp.timestamp}"

关于ruby-on-rails - 在 Rails 中获取 eBay 时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9423168/

相关文章:

ruby-on-rails - Ruby on Rails - 货币 : commas causing an issue

ruby-on-rails - Rails 3 的路由问题

javascript - 使用 eBay api 查找单词的所有变体

perl - 如何将 ItemFilters 与 eBay::API::Simple::Finding 结合使用?

ruby - 尝试通过 https 发出发布请求时获取 OpenSSL::SSL::SSLError: SSL_set_tlsext_host_name

Ruby Net::HTTP POST 发送数据 gzip 压缩

javascript - 你能在 Ruby 中使用 Case 语句进行无限计数吗?

ebay-api - eBay API 及说明

http - Go Web 服务器的进程管理

ruby-on-rails - 评估日期是否不是模型中的过去日期之一——Ruby on Rails