Sha256: 5230cc13a6d6efa81e55d3d4adc9db8b4e8511ec9140a7d50436d5ef3ba5208a

Contents?: true

Size: 1.01 KB

Versions: 62

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

62 entries across 37 versions & 4 rubygems

Version Path
paynow_sdk-1.1.0 vendor/bundle/ruby/2.7.0/gems/paynow_sdk-1.0.9/vendor/cache/ruby/2.7.0/gems/paynow_sdk-1.0.0/vendor/cache/ruby/2.7.0/gems/httparty-0.18.1/examples/aaws.rb
paynow_sdk-1.1.0 vendor/bundle/ruby/2.7.0/gems/paynow_sdk-1.0.9/vendor/cache/ruby/2.7.0/gems/httparty-0.18.1/examples/aaws.rb
paynow_sdk-1.1.0 vendor/cache/ruby/2.7.0/gems/httparty-0.18.1/examples/aaws.rb
paynow_sdk-1.1.0 vendor/bundle/ruby/2.7.0/gems/paynow_sdk-1.0.9/vendor/bundle/ruby/2.7.0/gems/httparty-0.18.1/examples/aaws.rb
paynow_sdk-1.1.0 vendor/cache/ruby/2.7.0/gems/paynow_sdk-1.0.0/vendor/cache/ruby/2.7.0/gems/httparty-0.18.1/examples/aaws.rb
paynow_sdk-1.1.0 vendor/bundle/ruby/2.7.0/gems/httparty-0.18.1/examples/aaws.rb
paynow_sdk-1.0.9 vendor/cache/ruby/2.7.0/gems/httparty-0.18.1/examples/aaws.rb
paynow_sdk-1.0.9 vendor/cache/ruby/2.7.0/gems/paynow_sdk-1.0.0/vendor/cache/ruby/2.7.0/gems/httparty-0.18.1/examples/aaws.rb
paynow_sdk-1.0.9 vendor/bundle/ruby/2.7.0/gems/httparty-0.18.1/examples/aaws.rb
paynow_sdk-1.0.8 vendor/cache/ruby/2.7.0/gems/httparty-0.18.1/examples/aaws.rb
paynow_sdk-1.0.8 vendor/cache/ruby/2.7.0/gems/paynow_sdk-1.0.0/vendor/cache/ruby/2.7.0/gems/httparty-0.18.1/examples/aaws.rb
paynow_sdk-1.0.8 vendor/bundle/ruby/2.7.0/gems/httparty-0.18.1/examples/aaws.rb
paynow_sdk-1.0.7 vendor/cache/ruby/2.7.0/gems/paynow_sdk-1.0.0/vendor/cache/ruby/2.7.0/gems/httparty-0.18.1/examples/aaws.rb
paynow_sdk-1.0.7 vendor/cache/ruby/2.7.0/gems/httparty-0.18.1/examples/aaws.rb
paynow_sdk-1.0.6 vendor/cache/ruby/2.7.0/gems/paynow_sdk-1.0.0/vendor/cache/ruby/2.7.0/gems/httparty-0.18.1/examples/aaws.rb
paynow_sdk-1.0.6 vendor/cache/ruby/2.7.0/gems/httparty-0.18.1/examples/aaws.rb
paynow_sdk-1.0.5 vendor/cache/ruby/2.7.0/gems/paynow_sdk-1.0.0/vendor/cache/ruby/2.7.0/gems/httparty-0.18.1/examples/aaws.rb
paynow_sdk-1.0.5 vendor/cache/ruby/2.7.0/gems/httparty-0.18.1/examples/aaws.rb
paynow_sdk-1.0.4 vendor/cache/ruby/2.7.0/gems/httparty-0.18.1/examples/aaws.rb
paynow_sdk-1.0.4 vendor/cache/ruby/2.7.0/gems/paynow_sdk-1.0.0/vendor/cache/ruby/2.7.0/gems/httparty-0.18.1/examples/aaws.rb