Search code examples
ruby-on-railsebay-apinet-http

get ebay time in rails


I've been looking around a bit for how to get the time off of ebay.. I don't want to use SAVON because... well it didn't work..

So I'm trying to use net/http, just to get the time. (for now)

Here's what I got so far.

 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

Solution

  • APIs wrappers are developed to help :)

    Please use eBay4r and same on 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}"