2008-12-06 23:41:28 -05:00
|
|
|
require 'rubygems'
|
|
|
|
require 'activesupport'
|
|
|
|
|
2008-07-28 12:45:06 -04:00
|
|
|
dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
|
|
require File.join(dir, 'httparty')
|
|
|
|
require 'pp'
|
|
|
|
config = YAML::load(File.read(File.join(ENV['HOME'], '.aaws')))
|
|
|
|
|
|
|
|
module AAWS
|
|
|
|
class Book
|
|
|
|
include HTTParty
|
|
|
|
base_uri 'http://ecs.amazonaws.com'
|
|
|
|
default_params :Service => 'AWSECommerceService', :Operation => 'ItemSearch', :SearchIndex => 'Books'
|
|
|
|
|
|
|
|
def initialize(key)
|
|
|
|
self.class.default_params :AWSAccessKeyId => key
|
|
|
|
end
|
|
|
|
|
|
|
|
def search(options={})
|
|
|
|
raise ArgumentError, 'You must search for something' if options[:query].blank?
|
2008-07-28 12:58:40 -04:00
|
|
|
|
2008-07-28 17:03:14 -04:00
|
|
|
# amazon uses nasty camelized query params
|
2008-07-28 12:45:06 -04:00
|
|
|
options[:query] = options[:query].inject({}) { |h, q| h[q[0].to_s.camelize] = q[1]; h }
|
2008-07-28 12:58:40 -04:00
|
|
|
|
|
|
|
# make a request and return the items (NOTE: this doesn't handle errors at this point)
|
2008-07-28 12:45:06 -04:00
|
|
|
self.class.get('/onca/xml', options)['ItemSearchResponse']['Items']
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
aaws = AAWS::Book.new(config[:access_key])
|
|
|
|
pp aaws.search(:query => {:title => 'Ruby On Rails'})
|