mirror of
https://github.com/jnunemaker/httparty
synced 2023-03-27 23:23:07 -04:00
Added amazon web services book search example.
This commit is contained in:
parent
236b3ad4e0
commit
fe18cff257
1 changed files with 26 additions and 0 deletions
26
examples/aaws.rb
Normal file
26
examples/aaws.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
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'
|
||||
format :xml
|
||||
|
||||
def initialize(key)
|
||||
self.class.default_params :AWSAccessKeyId => key
|
||||
end
|
||||
|
||||
def search(options={})
|
||||
raise ArgumentError, 'You must search for something' if options[:query].blank?
|
||||
options[:query] = options[:query].inject({}) { |h, q| h[q[0].to_s.camelize] = q[1]; h }
|
||||
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'})
|
Loading…
Add table
Reference in a new issue