Sha256: dfb1f498d93fa65336c61b96cd705250d778dcafb0cfa054c320808237ef8c8f

Contents?: true

Size: 1.1 KB

Versions: 87

Compression:

Stored size: 1.1 KB

Contents

require 'rubygems'
require 'active_support'
require 'active_support/core_ext/hash'
require 'active_support/core_ext/string'

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)
      @auth = { 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]
        .reverse_merge(@auth)
        .transform_keys { |k| k.to_s.camelize }

      # 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

87 entries across 86 versions & 4 rubygems

Version Path
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/httparty-0.22.0/examples/aaws.rb
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.1.0/gems/httparty-0.22.0/examples/aaws.rb
httparty-0.22.0 examples/aaws.rb
harbr-2.8.1 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/aaws.rb
study_line-0.2.7 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/aaws.rb
study_line-0.2.6 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/aaws.rb
study_line-0.2.5 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/aaws.rb
study_line-0.2.4 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/aaws.rb
study_line-0.2.3 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/aaws.rb
study_line-0.2.2 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/aaws.rb
study_line-0.2.1 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/aaws.rb
study_line-0.2.0 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/aaws.rb
harbr-0.2.10 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/aaws.rb
harbr-0.2.9 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/aaws.rb
harbr-0.2.8 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/aaws.rb
harbr-0.2.7 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/aaws.rb
harbr-0.2.6 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/aaws.rb
harbr-0.2.5 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/aaws.rb
harbr-0.2.4 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/aaws.rb
harbr-0.2.3 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/examples/aaws.rb