At the Forge - eBay Web Services
Once you have gotten through the registration nightmare, you can make queries. The REST API is well documented and is quite straightforward to use. First, let's look at a simple program that sees how many matches we can find to a particular text string. The program, shown in Listing 1, is written in Ruby and is similar to some of the Amazon- and Google-searching programs presented during the past few months.
Listing 1. ebay-lookup.rb
#!/usr/bin/ruby
require 'net/http'
require 'rexml/document'
if ARGV.length == 0
puts "#{$0}: You must enter at least one argument."
exit
end
output = ""
# Iterate through each of our arguments
ARGV.each do |query_string|
output << "Searching for: #{query_string}\n"
# Put together an eBay parameter string
ebay_params = {'CallName' => 'GetSearchResults',
'RequestToken' => 'XXX',
'RequestUserId' => 'YYY',
'Schema' => 1,
'ItemTypeFilter' => 3,
'SearchInDescription' => 1,
'StoreSearch' => 3,
'DetailLevel' => 3,
'Query' => query_string}.map {|key,value|
"#{key}=#{value}"}.join("&")
# Ask eBay what it knows about our query_string
ebay_response = Net::HTTP.get_response('rest.api.ebay.com',
'/restapi?' << ebay_params)
xml = REXML::Document.new(ebay_response.body)
# Get basic information
how_many_matches =
xml.root.elements["PaginationResult/TotalNumberOfEntries"].text
output << "Number of matches: #{how_many_matches}\n"
end
# Show everyone what we've learned
puts output
The program begins by retrieving our search parameters, automatically placed in the ARGV variable. We iterate over each element of ARGV, calling each individual argument query_string. We then use a hash to create an easily understood set of name-value pairs, in which the hash keys are the parameter names and the hash values are the parameter values. We then use a bit of Ruby magic to combine them, first turning them into pairs with map, and then using join to connect the pairs together with &. In the end, we have a string we can pass to eBay's server.
In this particular example, we're using the Query method in the REST API. Query allows us to enter a text string, for which eBay will then search. The way that eBay has grown somewhat organically over the years becomes apparent when you use its Web services. You must explicitly indicate if you want to search in stores as well as auctions. We also must indicate whether we want auction items, fixed-price items or both. Thus, our example searches through all stores (because StoreSearch = 3), auctions and fixed-price items (ItemTypeFilter = 3), in descriptions as well as item titles (SearchInDescription = 1), and with a fair amount of detail returned (DetailLevel = 3).
We also indicate we want Schema = 1. This tells eBay we want to receive a response using eBay's new XML schema, rather than the older one that is now being deprecated.
We then take ebay_params, a string created from our name-value pairs, and pass it to Net::HTTP.get_response. This sends an HTTP request to eBay's server (rest.api.ebay.com), using the appropriate path (/restapi), followed by our name-value pairs.
When we get a response—and our sample code here assumes that we do receive a response—we expect that it is formatted in XML and parse it using Ruby's built-in REXML library. We grab the total number of entries in eBay's database containing this search string and use the text method to extract the text from between the <TotalNumberOfEntries> tags. Finally, the program displays its output, showing us how many items on eBay contain this text string.
The API is relatively fast, allowing us to perform lookups for a particular string in relatively short time. That said, popular search strings can take far longer than rare words. A search for an ISBN took 1–2 seconds on my computer and indicated how many sellers were offering that ISBN for sale. A search for the term auction, not surprisingly, took more than 30 seconds to return a result and indicated that 29,458,603 sellers mentioned that term in the title or description. Obviously, the choice of search term, as well as the number of sellers and the quantity of text searched for that term, will have a significant effect on the performance of your application.
eBay's API makes it possible to perform Boolean searches of various types. Putting two words together within quotation marks (URL-encoded, of course) allows you to search for a phrase. You can search for two words in the same auction by linking them with commas.
You also can include and exclude particular sellers. If you are a seller on eBay, you might want to look at all of your items—or all of your competitors' items, ignoring yours. These functions make it easier to navigate through the complex world of eBay, which sells a staggering variety of goods from all over the world.
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Designing Electronics with Linux | May 22, 2013 |
| Dynamic DNS—an Object Lesson in Problem Solving | May 21, 2013 |
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
- RSS Feeds
- Dynamic DNS—an Object Lesson in Problem Solving
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Designing Electronics with Linux
- Using Salt Stack and Vagrant for Drupal Development
- New Products
- A Topic for Discussion - Open Source Feature-Richness?
- Drupal Is a Framework: Why Everyone Needs to Understand This
- Validate an E-Mail Address with PHP, the Right Way
- What's the tweeting protocol?
Enter to Win an Adafruit Pi Cobbler Breakout Kit for Raspberry Pi

It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Pi Cobbler Breakout Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- 5-21-13, Prototyping Pi Plate Kit: Philip Kirby
- Next winner announced on 5-27-13!
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?




6 hours 24 min ago
10 hours 51 min ago
14 hours 27 min ago
15 hours 2 sec ago
17 hours 23 min ago
17 hours 26 min ago
17 hours 28 min ago
21 hours 52 min ago
23 hours 43 min ago
1 day 4 hours ago