1
0
Fork 0
mirror of https://github.com/jnunemaker/httparty synced 2023-03-27 23:23:07 -04:00
httparty/examples/aaws.rb

33 lines
1 KiB
Ruby
Raw Normal View History

require 'rubygems'
2010-06-08 17:15:55 -04:00
require 'active_support'
dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.join(dir, 'httparty')
require 'pp'
2015-04-18 08:38:40 -04:00
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'
2013-04-18 08:09:21 -04:00
def initialize(key)
self.class.default_params AWSAccessKeyId: key
end
2013-04-18 08:09:21 -04:00
def search(options = {})
raise ArgumentError, 'You must search for something' if options[:query].blank?
2013-04-18 08:09:21 -04:00
# amazon uses nasty camelized query params
options[:query] = options[:query].inject({}) { |h, q| h[q[0].to_s.camelize] = q[1]; h }
2013-04-18 08:09:21 -04:00
# make a request and return the items (NOTE: this doesn't handle errors at this point)
self.class.get('/onca/xml', options)['ItemSearchResponse']['Items']
end
end
end
aaws = AAWS::Book.new(config[:access_key])
2016-11-08 09:20:36 -05:00
pp aaws.search(query: { title: 'Ruby On Rails' })