This library provides a wrapper to the eBay APIs.
You can instantiate API requests using shorthand class methods defined on Ebay
.
Ebay.finding # returns a new Ebay::Finding instance
eBay APIs require developer keys.
You can provide these globally with the environment variables EBAY_APP_ID
, EBAY_DEV_ID
, and EBAY_CERT_ID
.
If you prefer not to use environment variables, you can provide your keys globally with:
Ebay.configure do |config|
config.app_id = 'YOUR APP ID'
config.dev_id = 'YOUR DEV ID'
config.cert_id = 'YOUR CERT ID'
end
Finally, you can provide your keys individually to the request when instantiating it. This is what you will want to do if you are using multiple sets of credentials.
Please note that each API names keys differently.
request = Ebay.finding(security_appname: 'YOUR APP ID')
In the examples below, we will assume we are providing our keys with environment variables.
The eBay APIs return responses in XML or JSON format.
You can override the default format of an API when instantiating the request.
require 'json'
### the Finding API returns XML by default
request = Ebay.finding(response_data_format: 'JSON')
response = request.find_items_by_keywords('iphone')
JSON.parse(response)
The Browse API allows your buyers to search eBay items by keyword and category. It also allows them to view and add items to their eBay shopping cart. The Browse API defaults to the eBay US marketplace but may be set during initialisation. The list of available marketplaces is here.
Note The marketplace value needs to use an underscore between EBAY and the country code. The Finding and Merchandising APIs use a hyphen.
require 'ebay/browse'
require 'ebay/oauth/client_credentials_grant'
access_token = Oauth::ClientCredentialsGrant.new.mint_access_token
request = Ebay.browse(access_token: access_token, campaign_id: '123')
response = request.search(q: 'iphone')
The Finding API lets you search and browse for items listed on eBay and provides useful metadata to refine searches.
require 'ebay/finding'
request = Ebay.finding
response = request.find_items_by_keywords('iphone')
The Merchandising API retrieves information about products or item listings on eBay to help you sell more merchandise to eBay buyers.
require 'ebay/merchandising'
request = Ebay::Merchandising.new
response = request.get_most_watched_items
The eBay Shopping API makes it easy to search for things on eBay.
require 'ebay/shopping'
request = Ebay::Shopping.new
response = request.find_products('QueryKeywords' => 'tolkien')
eBay has country bsaed marketplaces ( listed here ). By default, the eBay gem queries the US Marketplace. To change the marketplace, set the marketplace on the request object.
Note For the Browse API, the marketplace value needs to use an underscore between EBAY and the country code (EBAY_AU). The Finding and Merchandising APIs require a hyphen between EBAY and the country code ( EBAY-AU )
You can point to the sandbox environment instead of production when developing.
require 'ebay/browse'
require 'ebay/oauth/client_credentials_grant'
access_token = Oauth::ClientCredentialsGrant.new.sandbox.mint_access_token
request = Ebay.browse(access_token: access_token, campaign_id: '123').sandbox
response = request.search(q: 'iphone')
To write requests and responses to a logger, use the logging feature:
require 'logger'
request = request.use(logging: {logger: Logger.new(STDOUT)})