2

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
Machavity
  • 30,841
  • 27
  • 92
  • 100
baash05
  • 4,394
  • 11
  • 59
  • 97

2 Answers2

2

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}"
zengr
  • 38,346
  • 37
  • 130
  • 192
  • sweet.. but they only help if I can find them :) New to ruby and I'm not sure how to find things. This helps a lot – baash05 Feb 24 '12 at 02:58
  • sure, I understand. When ever starting with an api. Go to a program which searches the web and search: " api " like: "ebay api python". You will get one for sure in the first 5 results. And if you do not find those operations implemented, implement them and send them a pull request. That will make you an open source contributer too :) – zengr Feb 24 '12 at 03:52
  • 1
    Yeah.. I'm already an open source contributor :) Just not ruby. – baash05 Feb 24 '12 at 09:52
  • The problem I have with using wrappers, is that often it means I don't understand how they work under the hood. (by design) Because I have a newly released API, if I had gone with the wrapper, I'd still have to dig in.. As the API has been released to only a few Australian companies, I suspect no-one but me would have to extend the wrapper.. – baash05 Feb 29 '12 at 22:17
1

it didn't take me as long to find this as I thought.

in the bottom bit, I added SSL handling

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = 0
res = http.start do |http_runner|
  http_runner.request(req)
end
return res.body
baash05
  • 4,394
  • 11
  • 59
  • 97