Sha256: c1286f627ab0f99e9c775cbdc7780e6807b857365bc52b1c4a61ee3e27ca7301

Contents?: true

Size: 1.03 KB

Versions: 16

Compression:

Stored size: 1.03 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

16 entries across 15 versions & 5 rubygems

Version Path
alloy_sdk-0.1.0 vendor/bundle/ruby/3.0.0/gems/httparty-0.13.1/examples/aaws.rb
alloy_sdk-0.1.0 vendor/bundle/ruby/2.6.0/gems/httparty-0.13.1/examples/aaws.rb
allegro_api_client-0.0.9 gems/ruby/2.1.0/gems/httparty-0.13.1/examples/aaws.rb
allegro_api_client-0.0.8 gems/ruby/2.1.0/gems/httparty-0.13.1/examples/aaws.rb
allegro_api_client-0.0.7 gems/ruby/2.1.0/gems/httparty-0.13.1/examples/aaws.rb
asana2flowdock-1.0.0 vendor/bundle/ruby/1.9.1/gems/httparty-0.13.1/examples/aaws.rb
allegro_api_client-0.0.6 gems/ruby/2.1.0/gems/httparty-0.13.1/examples/aaws.rb
allegro_api_client-0.0.5 gems/ruby/2.1.0/gems/httparty-0.13.1/examples/aaws.rb
allegro_api_client-0.0.4 gems/ruby/2.1.0/gems/httparty-0.13.1/examples/aaws.rb
allegro_api_client-0.0.3 gems/ruby/2.1.0/gems/httparty-0.13.1/examples/aaws.rb
allegro_api_client-0.0.2 gems/ruby/2.1.0/gems/httparty-0.13.1/examples/aaws.rb
allegro_api_client-0.0.1 gems/ruby/2.1.0/gems/httparty-0.13.1/examples/aaws.rb
httparty-0.13.1 examples/aaws.rb
yoyle439587298-0.13.0 examples/aaws.rb
httparty-0.13.0 examples/aaws.rb
httparty-0.12.0 examples/aaws.rb