Skip to content
This repository

eBay API for Ruby

Introduction

  • Simple and easy to use Ruby implementation.
  • Ability to return a raw response for special handling of large responses
  • Up-to-date with the latest eBay API version 591.
  • Months of usage in a production environment.
  • Support for Platform Notifications baked right in.

Getting Started

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 authenticity 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:


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 gem.

Install the ebayapi gem by running:


> 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:


#!/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
Something went wrong with that request. Please try again.