github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

dpickett / amazon_associate

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 32
    • 6
  • Source
  • Commits
  • Network (6)
  • Issues (1)
  • Downloads (5)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (4)
    • caching
    • development
    • master ✓
    • work
  • Tags (5)
    • v0.7.0
    • v0.6.5
    • v0.6.3
    • help
    • 0.5.4
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Amazon Associates API Interface using hpricot — Read more

  cancel

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

gemspec 
dpickett (author)
Sat Aug 01 12:05:12 -0700 2009
commit  36a92590c321db65e92220c30b949d50a8bb4c28
tree    a07190059c8d910bef910bbac5b5fc226495e28f
parent  4532348a03de080a1310c9ff66b6a656bb8fcd16
amazon_associate /
name age
history
message
file .autotest Tue Nov 04 12:05:46 -0800 2008 autotest file [dpickett]
file .gitignore Sat Aug 01 11:59:56 -0700 2009 fix caching to properly cache unsigned url [dpickett]
file .project Wed Dec 06 18:56:49 -0800 2006 Initial release git-svn-id: http://amazon-ecs... [jugend]
file CHANGELOG Mon Nov 10 16:19:01 -0800 2008 major renaming [dpickett]
file MIT-LICENSE Mon Nov 10 15:20:28 -0800 2008 more attempts to fix gems [dpickett]
file README.rdoc Sat Aug 01 12:04:42 -0700 2009 update readme to reflect request signing change [dpickett]
file Rakefile Tue Jun 30 11:39:49 -0700 2009 modify rake and readme files [dpickett]
file VERSION.yml Sat Aug 01 12:04:51 -0700 2009 Version bump to 0.7.0 [dpickett]
file amazon_associate.gemspec Sat Aug 01 12:05:12 -0700 2009 gemspec [dpickett]
directory lib/ Sat Aug 01 12:01:32 -0700 2009 Merge branch 'signing' [dpickett]
directory test/ Sat Aug 01 11:59:56 -0700 2009 fix caching to properly cache unsigned url [dpickett]
README.rdoc

amazon-associate

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 AmazonAssociate::Request 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 amazon-ecs library, instead you just need to change the element path.

NOTE: You must now specify a secret key to support request signing as required by Amazon.

Version: 0.6.1

WANTS

  • instance based refactoring (singletons are not ideal here)

INSTALLATION

  $ gem install dpickett-amazon_associate

EXAMPLE

    require 'amazon_associate'

    # set the default options; options will be camelized and converted to REST request parameters.
    AmazonAssociate::Request.configure do |options|
      options[:aWS_access_key_id] = [your developer token]
      options[:secrety_key] = [your secret key]
    end

    # options provided on method call will merge with the default options
    res = AmazonAssociate::Request.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 (AmazonAssociate::Element)
    res.items.each do |item|
      # retrieve string value using XML path
      item.get('asin')
      item.get('itemattributes/title')

      # or return AmazonAssociate::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
        AmazonAssociate::Element.get_hash(review) # [:source => ..., :content ==> ...]

        # Or to get unescaped HTML values
        AmazonAssociate::Element.get_unescaped(review, 'source')
        AmazonAssociate::Element.get_unescaped(review, 'content')

        # Or this way
        el = AmazonAssociate::Element.new(review)
        el.get_unescaped('source')
        el.get_unescaped('content')
      end

      # returns AmazonAssociate::Element instead of string
      item.search_and_convert('itemattributes').
    end

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

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

CACHING

Filesystem caching is now available.

  AmazonAssociate::Request.configure do |options|
    options[:aWS_access_key_id] = [your developer token]
    options[:scret_key] = [your secret key]
    options[:caching_strategy] = :filesystem
    options[:caching_options] = {
      :disk_quota      => 200,
      :cache_path      => <path where you want to store requests>,
      :sweep_frequency => 4
    }
  end

The above command will cache up to 200MB of requests. It will purge the cache every 4 hours or when the disk quota has been exceeded.

Every request will be stored in the cache path. On every request, AmazonAssociate::Request will check for the presence of the cached file before querying Amazon directly.

LINKS

  • amazon-ecs.rubyforge.org

LICENSE

(The MIT License)

Copyright © 2008 Dan Pickett, Enlight Solutions, Inc.

Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server