dpickett / amazon_associate

Amazon Associates API Interface using hpricot

This URL has Read+Write access

dpickett (author)
Tue Oct 28 13:17:44 -0700 2008
commit  273aadca570cc5d5138d5da77d3c39bc5dabaa4c
tree    351e10c4d1e452fca6aa8e87429bcc9c29aab53f
parent  3e439d0878bd7f5edf7265bec715ec1c1481803a
name age message
file .project Wed Dec 06 18:56:49 -0800 2006 Initial release git-svn-id: http://amazon-ecs... [jugend]
file CHANGELOG Loading commit data...
file MIT-LICENSE
file README
file Rakefile
directory lib/
file ruby_amazon_associates.gemspec
directory test/
README
== amazon-ecs

Generic Amazon E-commerce REST API using Hpricot with configurable 
default options and method call options. Uses Response and 
Element wrapper classes for easy access to REST XML output. It supports ECS 4.0.

It is generic, so you can easily extend <tt>Amazon::Ecs</tt> to support 
other not implemented REST operations; and it is also generic because it just wraps around
Hpricot element object, instead of providing one-to-one object/attributes to XML elements map.

If in the future, there is a change in REST XML output structure, 
no changes will be required on <tt>amazon-ecs</tt> library, 
instead you just need to change the element path.

Version: 0.5.4

== INSTALLATION

  $ gem install amazon-ecs

== EXAMPLE

    require 'amazon/ecs'
  
    # set the default options; options will be camelized and converted to REST request parameters.
    Amazon::Ecs.options = {:aWS_access_key_id => [your developer token]}

    # options provided on method call will merge with the default options
    res = Amazon::Ecs.item_search('ruby', {:response_group => 'Medium', :sort => 'salesrank'})

    # some common response object methods
    res.is_valid_request?     # return true if request is valid
    res.has_error?            # return true if there is an error
    res.error                 # return error message if there is any
    res.total_pages           # return total pages
    res.total_results         # return total results
    res.item_page             # return current page no if :item_page option is provided

    # traverse through each item (Amazon::Element)
    res.items.each do |item|
      # retrieve string value using XML path
      item.get('asin')
      item.get('itemattributes/title')

      # or return Amazon::Element instance
      atts = item.search_and_convert('itemattributes')
      atts.get('title')
  
      # return first author or a string array of authors
      atts.get('author')          # 'Author 1'
      atts.get_array('author')    # ['Author 1', 'Author 2', ...]
  
      # return an hash of children text values with the element names as the keys
      item.get_hash('smallimage') # {:url => ..., :width => ..., :height => ...}
  
      # note that '/' returns Hpricot::Elements array object, nil if not found
      reviews = item/'editorialreview'
  
      # traverse through Hpricot elements
      reviews.each do |review|
        # Getting hash value out of Hpricot element
        Amazon::Element.get_hash(review) # [:source => ..., :content ==> ...]
    
        # Or to get unescaped HTML values
        Amazon::Element.get_unescaped(review, 'source')
        Amazon::Element.get_unescaped(review, 'content')
        
        # Or this way
        el = Amazon::Element.new(review)
        el.get_unescaped('source')
        el.get_unescaped('content')
      end
      
      # returns Amazon::Element instead of string
      item.search_and_convert('itemattributes').
    end

Refer to Amazon ECS documentation for more information on Amazon REST request parameters and XML output:
http://docs.amazonwebservices.com/AWSEcommerceService/2006-09-13/

To get a sample of Amazon REST response XML output, use AWSZone.com scratch pad:
http://www.awszone.com/scratchpads/aws/ecs.us/index.aws

== LINKS

* http://amazon-ecs.rubyforge.org
* http://www.pluitsolutions.com/amazon-ecs

== LICENSE

(The MIT License)

Copyright (c) 2006 Herryanto Siatono, Pluit Solutions