Sha256: 4a08812634e30a33c5bcc04403d8128b4ebf33a32a6fee868248fc6e69f0bad3

Contents?: true

Size: 1.04 KB

Versions: 82

Compression:

Stored size: 1.04 KB

Contents

require 'rubygems'
require 'activesupport'

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?
      
      # amazon uses nasty camelized query params
      options[:query] = options[:query].inject({}) { |h, q| h[q[0].to_s.camelize] = q[1]; h }
      
      # 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])
pp aaws.search(:query => {:title => 'Ruby On Rails'})

Version data entries

82 entries across 82 versions & 19 rubygems

Version Path
alexvollmer-httparty-0.2.6 examples/aaws.rb
alexvollmer-httparty-0.3.1 examples/aaws.rb
alexvollmer-httparty-0.4.3 examples/aaws.rb
cluon-httparty-0.4.3 examples/aaws.rb
dbalatero-httparty-0.4.4 examples/aaws.rb
ddollar-httparty-0.4.6 examples/aaws.rb
geetarista-httparty-0.4.5 examples/aaws.rb
jcinnamond-httparty-0.4.5 examples/aaws.rb
jcinnamond-httparty-0.4.6 examples/aaws.rb
jnunemaker-httparty-0.2.0 examples/aaws.rb
jnunemaker-httparty-0.2.1 examples/aaws.rb
jnunemaker-httparty-0.2.10 examples/aaws.rb
jnunemaker-httparty-0.2.2 examples/aaws.rb
jnunemaker-httparty-0.2.3 examples/aaws.rb
jnunemaker-httparty-0.2.4 examples/aaws.rb
jnunemaker-httparty-0.2.5 examples/aaws.rb
jnunemaker-httparty-0.2.6 examples/aaws.rb
jnunemaker-httparty-0.2.7 examples/aaws.rb
jnunemaker-httparty-0.2.8 examples/aaws.rb
jnunemaker-httparty-0.2.9 examples/aaws.rb