I recently released my Ruby client for the eBay XML API. The source code can be found on Google Code. Benefits of this implementation include:
Enough talking about why you should use this library, let's get started with the eBay equivalent to 'Hello World', which is the GeteBayOfficialTime call.
Firstly you'll need to sign up for an eBay developer account. You can sign up at the eBay Developer Center. Once you have signed up you need to follow the directions in the confirmation email to get your Developer ID, Application ID, and Certificate ID. Record this information, as you'll need it when setting up the eBay client.
Now you need to setup a sandbox user to make API calls on behalf of.
Next you'll need to generate your Authentication Token. Simply enter the information you previously recorded into the form, select the sandbox environment from the dropdown menu and click the "Continue to generate token" link. Then sign in as the sandbox user you just created above and agree to allow your developer account to make API calls on behalf of the sandbox user. Record the Authentication Token that is now displayed.
The Authentication Token is your means of sending requests for different users. All you have to do to send a request for a different eBay user is change the Authentication Token that pass into the API call you are making. Of course, you'll need permission to make API calls on their behalf.
Now that we have all of the information needed for authenticating the API calls we can setup the configuration file that we'll use for the following example.
Start by creating a file config.rb and place the following code into it:
1 2 3 4 5 6 7 8 9 10 11 |
Ebay::Api.configure do |ebay| ebay.auth_token = 'YOUR AUTH TOKEN HERE' ebay.dev_id = 'YOUR DEVELOPER ID HERE' ebay.app_id = 'YOUR APPLICATION ID HERE' ebay.cert = 'YOUR CERTIFICATE HERE' # The default environment is the production environment # Override by setting use_sandbox to true ebay.use_sandbox = true end |
Obviously you'll want to place your own IDs and tokens into the configuration.
After you've signed up for the Developer Program and you have the API configuration ready to go you can get started installing the Ruby ebayapi gem. Install this gem as by running:
1 2 |
> sudo gem install ebayapi -y |
The -y flag tells gems to install all the dependencies that the the gem requires.
Now that you've got the API client installed we can finally go ahead and get the official eBay time from eBay's servers.
Create a file named official_time.rb, in the same directory as the config.rb file we created earlier, and place the following code in it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
#!/usr/bin/env ruby require 'rubygems' require 'ebay' # Include the API configuration require 'config' # Create the eBay client ebay = Ebay::Api.new # Get the official eBay time response = ebay.get_ebay_official_time # Display the time to the user puts response.timestamp |
Now you can run this simple application:
> ruby official_time.rb
# => Wed Nov 22 06:03:35 UTC 2006
That was easy. Once we got all of the IDs and tokens that eBay requires, that is. Next time I'll go into some more depth and background the client.
In the meantime you can checkout the examples I've provided in the source. Happy coding.
Sorry, comments are closed for this article.
January 2nd, 2007 at 02:04 AM Thanks for this awesome gem Cody! I have already started using it in my Rails app. This will make it so easy to integrate with eBay. It is exactly what I was looking for.
January 14th, 2007 at 04:25 AM
where should I put those files in? config.rb and official_time.rb
January 17th, 2007 at 03:55 AM
Truly great work Cody - what a timesaver! One small point: I think you need to require 'ebayapi', not 'ebay'. Thanks for all your efforts.
January 17th, 2007 at 04:52 PM
Alfred: the easiest to try out the example is to put config.rb and officialtime.rb in the same directory and then run officialtime.rb from that directory.
Mike: You can do one of two things:
This is because the Gem is named ebayapi, but the actual project is really just using a file ebay.rb.
January 17th, 2007 at 08:06 PM
I've tried and I got a lot of these:
warning: already initialized constant XXX warning: already initialized constant YYY
am I missing any gem?
January 17th, 2007 at 11:39 PM
now it is working after I added this: require_gem 'ebayapi'
January 18th, 2007 at 11:05 PM
I already had some working Java code (my own) for this but your Ruby code is much more flexible (method_missing supports that very well). Great work and thanks, Cody! :-)
Being a Ruby newbie (really!) I'm a bit confused about function parameters. Example: For the GetSellerTransactions call I use detaillevel, modtimefrom and modtimeto. But that's not enough. Is the additional parameter activelist (which you used for getitemsselling) the return value? I really have to learn more about Ruby to understand all this stuff.
There isn't a mailing list, is it?
Christian
January 21st, 2007 at 09:23 PM
Aaah ... Sorry for the stupid question. I already found out how it works.
Thanks again! Great work! :-)
Christian
February 11th, 2007 at 10:57 PM
Thanks!.. That's all I want to say :)