Search code examples
ruby

Amazon API and hardcover versus paperback


When searching Amazon using their API is there a way to separate out hardcover, paperback, kindle and pre-orderable books?

I'm using Ruby and Amazon Product gem and have been searching through their documentation looking for info on this and haven't managed to find anything yet.

I have come across some starting points that I am working through. There seems to a way to get this information via RrelatedItems ResponseGroup as described here. The KindleStore hierarchy seems relevant.

Binding is possibly the field I need to somehow look at and amazon's API provides a way of getting to AlternateVersions of an ASIN using the AlternativeVersion ResponseGroup type for books.


Solution

  • I will assume you know how to set up the Amazon Product gem request object correctly. from there, you can do...

    search = req.search( 'Ender\'s Game' )
    search.each('Item') do |item|
      asin = item["ASIN"]
      title = item['ItemAttributes']['Title']
      hash = {
        :response_group => ['ItemAttributes']
        }
      items = req.find( asin, hash )
      items.each('Item') do |ia|
        puts "[#{asin}]: #{title} => [#{ia['ItemAttributes']['Binding']}]"
      end
    end
    

    which produces output like

    [0812550706]: Ender's Game (Ender, Book 1) => [Mass Market Paperback]
    [0765362430]: The Ender Quartet Box Set: Ender's Game, Speaker for the Dead, Xenocide, Children of the Mind => [Mass Market Paperback]
    [0812550757]: Speaker for the Dead (Ender, Book 2) => [Mass Market Paperback]
    [0765342405]: Ender's Shadow (Ender, Book 5) => [Paperback]
    [B003G4W49C]: Ender's Game => [Kindle Edition]
    [0785135820]: Ender's Game: Command School => [Hardcover]
    [0785135804]: Ender's Game: Battle School (Ender's Game Gn) => [Hardcover]
    [0765362449]: The Ender's Shadow Series Box Set: Ender's Shadow, Shadow of the Hegemon, Shadow Puppets, Shadow of the Giant => [Paperback]
    [0785136096]: Ender's Game: Formic Wars: Burning Earth => [Hardcover]
    [0812565959]: Shadow of the Hegemon (Ender, Book 6) => [Mass Market Paperback]