<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.0.1" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>Pluit Solutions</title>
	<link>http://www.pluitsolutions.com</link>
	<description>Web Developer, Web Designer, Ruby on Rails Developer, a Curious Man based in Singapore</description>
	<pubDate>Thu, 14 Jul 2011 02:03:29 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.1</generator>
	<language>en</language>
			<item>
		<title>Ruby Amazon Product Advertising API</title>
		<link>http://www.pluitsolutions.com/projects/amazon-ecs/</link>
		<comments>http://www.pluitsolutions.com/projects/amazon-ecs/#comments</comments>
		<pubDate>Thu, 07 Dec 2006 05:37:15 +0000</pubDate>
		<dc:creator>Herryanto Siatono</dc:creator>
		
	<category>General</category>
		<guid isPermaLink="false">http://www.pluitsolutions.com/amazon-ecs/</guid>
		<description><![CDATA[What is amazon-ecs?
A generic Ruby Amazon Product Advertising API (previously known as E-commerce REST API) using Hpricot. It uses Response and Element wrapper classes for easy access to the REST API XML output.
It is generic, so you can extend Amazon::Ecs to support the other not-implemented operations easily; and the response object just wraps around Hpricot [...]]]></description>
			<content:encoded><![CDATA[<h4>What is amazon-ecs?</h4>
<p>A generic Ruby Amazon Product Advertising API (previously known as E-commerce REST API) using Hpricot. It uses Response and Element wrapper classes for easy access to the REST API XML output.</p>
<p>It is generic, so you can extend <code>Amazon::Ecs</code> to support the other not-implemented operations easily; and the response object just wraps around Hpricot element object, instead of providing one-to-one object/attributes to XML elements map.</p>
<p>With that, if in the future, there is a change in REST XML output structure, no changes will be required on <code>amazon-ecs</code>, instead you just need to change your element path. </p>
<p>And four years after it still works like magic supporting the latest version of the API. As a prove, <a href="http://www.pluitsolutions.com/2006/12/07/ruby-amazon-e-commerce-rest-services-api-amazon-ecs/">please read this post</a>. </p>
<h4>Links</h4>
<ul>
<li><a href="http://github.com/jugend/amazon-ecs/tree/master">GitHub Repository</a></li>
<li><a href="http://rubygems.org/gems/amazon-ecs">Ruby Gems</a></li>
</ul>
<h4>Installation</h4>
<p><pre>$ gem install amazon-ecs</pre></p>
<h4>Example</h4>
<p><pre>
require "amazon/ecs"

# set the default options; options will be camelized and converted to REST request parameters.
Amazon::Ecs.options = {:aWS_access_key_id =&gt; "[your access key]"}

# to generate signed requests include your secret key:
Amazon::Ecs.options = {:aWS_access_key_id =&gt; "[your developer token]", :aWS_secret_key =&gt; "[your secret access key]"}

# alternatively,
Amazon::Ecs.configure do |options|
    options[:aWS_access_key_id] = "[your access key]"
    options[:aWS_secret_key] = "[you secret key]"
end

# options provided on method call will merge with the default options
res = Amazon::Ecs.item_search("ruby", {:response_group =&gt; "Medium", :sort =&gt; "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")

  # return Amazon::Element instance
  item_attributes = item.get_element("itemattributes")
  item_attributes.get("title")

  # return first author or a string array of authors
  item_attributes.get("author")          # "Author 1"
  item_attributes.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 =&gt; ..., :width =&gt; ..., :height =&gt; ...}

  # return the first matching path as Amazon::Element
  item_height = item.get_element("itemdimensions/height")
  
  # retrieve attributes from Amazon::Element
  item_height.attributes["units"]   # "hundredths-inches"
  
  # return an array of Amazon::Element
  authors = item.get_elements("author")

  # return Hpricot::Elements object or 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 =&gt; ..., :content ==&gt; ...]

    # 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
end

# Extend Amazon::Ecs, replace 'other_operation' with the appropriate name
module Amazon
  class Ecs
    def self.other_operation(item_id, options)
      opts[:operation] = '[other valid operation supported by Product Advertising API]'
      
      # setting default option value
      opts[:item_id] = item_id
    
      self.send_request(opts)
    end
  end
end

Amazon::Ecs.other_operation("[item_id]", :param1 =&gt; "abc", :param2 =&gt; "xyz")
</pre></p>
<h4>Tip</h4>
<p>If you are on <code>irb</code> console, this trick helps to print a nicely formatted xml result:<br />
<pre>
require 'pp'
pp res = Amazon::Ecs.item_search('ruby').doc
</pre></p>
<h4>More Information</h4>
<p>Refer to <a href="http://docs.amazonwebservices.com/AWSEcommerceService/2005-10-05/index.html">Amazon ECS documentation</a> for more information on Amazon REST request parameters and XML output structure. </p>
<p>Or you can also get a sample of Amazon REST XML output from <a href="http://www.awszone.com/scratchpads/aws/ecs.us/index.aws">AWSZone.com</a>.
</p>
]]></content:encoded>
			<wfw:commentRSS>http://www.pluitsolutions.com/projects/amazon-ecs/feed/</wfw:commentRSS>
		</item>
	</channel>
</rss>

