Sha256: 6684befb046b0a192fb6bab0fdb5ad719cea4ccfc4b115aae0812bfe3c0b86b3

Contents?: true

Size: 1.01 KB

Versions: 8

Compression:

Stored size: 1.01 KB

Contents

require 'rubygems'
require 'active_support'

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

8 entries across 7 versions & 3 rubygems

Version Path
httparty-0.14.0 examples/aaws.rb
simplenet-client-0.2.0 ./vendor/bundle/ruby/2.0.0/gems/httparty-0.13.7/examples/aaws.rb
simplenet-client-0.2.0 ./vendor/bundle/ruby/1.9.1/gems/httparty-0.13.7/examples/aaws.rb
httparty-0.13.7 examples/aaws.rb
httparty-0.13.6 examples/aaws.rb
httpserious-0.13.5.lstoll1 examples/aaws.rb
httparty-0.13.5 examples/aaws.rb
httparty-0.13.4 examples/aaws.rb