|
41134082
»
|
jnunemaker |
2008-12-06 |
Fixed weird uri normalizing... |
1 |
require 'rubygems' |
| |
2 |
require 'activesupport' |
| |
3 |
|
|
fe18cff2
»
|
jnunemaker |
2008-07-28 |
Added amazon web services b... |
4 |
dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')) |
| |
5 |
require File.join(dir, 'httparty') |
| |
6 |
require 'pp' |
| |
7 |
config = YAML::load(File.read(File.join(ENV['HOME'], '.aaws'))) |
| |
8 |
|
| |
9 |
module AAWS |
| |
10 |
class Book |
| |
11 |
include HTTParty |
| |
12 |
base_uri 'http://ecs.amazonaws.com' |
| |
13 |
default_params :Service => 'AWSECommerceService', :Operation => 'ItemSearch', :SearchIndex => 'Books' |
| |
14 |
|
| |
15 |
def initialize(key) |
| |
16 |
self.class.default_params :AWSAccessKeyId => key |
| |
17 |
end |
| |
18 |
|
| |
19 |
def search(options={}) |
| |
20 |
raise ArgumentError, 'You must search for something' if options[:query].blank? |
|
aafde867
»
|
jnunemaker |
2008-07-28 |
Documented and tweaked the ... |
21 |
|
|
06c04631
»
|
jnunemaker |
2008-07-28 |
removed comments that weren... |
22 |
# amazon uses nasty camelized query params |
|
fe18cff2
»
|
jnunemaker |
2008-07-28 |
Added amazon web services b... |
23 |
options[:query] = options[:query].inject({}) { |h, q| h[q[0].to_s.camelize] = q[1]; h } |
|
aafde867
»
|
jnunemaker |
2008-07-28 |
Documented and tweaked the ... |
24 |
|
| |
25 |
# make a request and return the items (NOTE: this doesn't handle errors at this point) |
|
fe18cff2
»
|
jnunemaker |
2008-07-28 |
Added amazon web services b... |
26 |
self.class.get('/onca/xml', options)['ItemSearchResponse']['Items'] |
| |
27 |
end |
| |
28 |
end |
| |
29 |
end |
| |
30 |
|
| |
31 |
aaws = AAWS::Book.new(config[:access_key]) |
| |
32 |
pp aaws.search(:query => {:title => 'Ruby On Rails'}) |