Giter Site home page Giter Site logo

vacuum's Introduction

Vacuum

Build Maintainability Test Coverage

Vacuum is a Ruby wrapper to Amazon Product Advertising API 5.0. The API provides programmatic access to query product information on the Amazon marketplaces.

Cart Form functionality is not covered by this gem but is a primary focus on carriage gem

You need to register first to use the API.

vacuum

Usage

Getting Started

Create a request with your marketplace credentials. Set the marketplace by passing its two-letter country code.

request = Vacuum.new(marketplace: 'US',
                     access_key: '<ACCESS_KEY>',
                     secret_key: '<SECRET_KEY>',
                     partner_tag: '<PARTNER_TAG>')

You can now access the API using the available operations.

response = request.search_items(title: 'lean startup')
puts response.to_h

Create a persistent connection to make multiple requests.

request.persistent

Operations

Refer to the API docs for more detailed information.

GetBrowseNodes

Given a BrowseNodeId, the GetBrowseNodes operation returns details about the specified browse node, like name, children and ancestors, depending on the resources specified in the request. The names and browse node IDs of the children and ancestor browse nodes are also returned. GetBrowseNodes enables you to traverse the browse node hierarchy to find a browse node.

request.get_browse_nodes(
  browse_node_ids: ['283155', '3040'],
  resources: ['BrowseNodes.Ancestor', 'BrowseNodes.Children']
)

GetItems

Given an Item identifier, the GetItems operation returns the item attributes, based on the resources specified in the request.

request.get_items(
  item_ids: ['B0199980K4', 'B000HZD168', 'B01180YUXS', 'B00BKQTA4A'],
  resources: ['Images.Primary.Small', 'ItemInfo.Title', 'ItemInfo.Features',
              'Offers.Summaries.HighestPrice' , 'ParentASIN']
)

GetVariations

Given an ASIN, the GetVariations operation returns a set of items that are the same product, but differ according to a consistent theme, for example size and color. These items which differ according to a consistent theme are called variations. A variation is a child ASIN. The parent ASIN is an abstraction of the children items. For example, a shirt is a parent ASIN and parent ASINs cannot be sold. A child ASIN would be a blue shirt, size 16, sold by MyApparelStore. This child ASIN is one of potentially many variations. The ways in which variations differ are called dimensions.

request.get_variations(
  asin: 'B00422MCUS',
  resources: ['ItemInfo.Title', 'VariationSummary.Price.HighestPrice',
              'VariationSummary.Price.LowestPrice',
              'VariationSummary.VariationDimension']
)

SearchItems

The SearchItems operation searches for items on Amazon based on a search query. The API returns up to ten items per search request.

request.search_items(keywords: 'harry potter')

Response

Consume a response by parsing it into a Ruby hash.

response.to_h

You can also #dig into this hash.

response.dig('ItemsResult', 'Items')

Logging

Write requests and reponses to a logger using the logging feature of the HTTP gem under the hood:

require 'logger'

logger = Logger.new(STDOUT)
request.use(logging: {logger: logger})

Bring your parser

You can extend Vacuum with a custom parser. Just swap the original with a class or module that responds to .parse.

response.parser = MyParser
response.parse

If no custom parser is set, Vacuum::Response#parse delegates to #to_h.

VCR

If you are using VCR to test an app that accesses the API, you can use the custom VCR matcher of Vacuum to stub requests.

require 'vacuum/matcher'

# in your test
VCR.insert_cassette('cassette_name',
                    match_requests_on: [Vacuum::Matcher])

In RSpec, use the :paapi metadata.

require 'vacuum/matcher'

# in your test
it 'queries Amazon', :paapi do
end

Development

Clone the repo and install dependencies.

bundle install

Tests and Rubocop should now pass as-is.

bundle exec rake

By default, the tests stub requests. Use the RECORD env var to record new interactions.

RECORD=true bundle exec rake test

You can set the LIVE env var to run all tests against live data.

LIVE=true bundle exec rake test

In either case, add actual API credentials to a locales.yml file under test.

Getting Help

vacuum's People

Contributors

aisensiy avatar bruno-campos avatar cambridgemike avatar christophebelpaire avatar ezkl avatar gerhard avatar hakanensari avatar heathnaylor avatar jmoon90 avatar klinker24 avatar laszpio avatar michaelfairley avatar onli avatar ryanmarshall avatar snoblenet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vacuum's Issues

All requests get "Missing service parameter" error

Every request I make ends up with the error:

Your request is missing the Service parameter. Please add the Service parameter to your request and retry

For example

>> req.search("books", :power => "foucault", :response_group => "medium")
=> #<Vacuum::Response::ProductAdvertising:0x1021e30b8 @body="<?xml version=\"1.0\" encoding=\"UTF-8\"?><Errors><Error><Code>AWS.MissingServiceParameter</Code><Message>Your request is missing the Service parameter. Please add  the Service parameter to your request and retry.</Message></Error></Errors>", @code=200>

Works with Rails 5? Getting Excon::Error::BadRequest

Hello,

I am trying to integrate this gem into a Rails 5.1 application to pull product images. Running the code from the rails console works fine, but calling from a controller returns Excon::Error::BadRequest (Expected([200, 403]) <=> Actual(400 Bad Request).

Gemfile:

gem 'vacuum', github: 'hakanensari/vacuum', tag: 'v2.0.2', require: 'vacuum'

Controller:

def show
    req = Vacuum.new
    req.configure(aws_access_key_id: ENV['AWS_PROD_IMG_ACCESS_KEY'],
                  aws_secret_access_key: ENV['AWS_PROD_IMG_SECRET_KEY'])
    req.associate_tag = 'foo'
    query = {
      ResponseGroup: 'Images',
      ItemId: '1338099132'
    }
    res = req.item_lookup(query: query)
    @images = res.to_h
  end

  private

  def product_image_params
    params.permit(:asin)
  end

Of course i want to replace ItemId with params[:asin] when this works in the controller.

I'm stumped because I don't know why copying the guts of show into rails console produces results, but calling it over its HTTP enpoint would throw a bad request from Vacuum.

Proxy support that requires authentication

Hi, I'm trying to use a proxy that requires authentication. I tried to input my username and password for the proxy into the connection_params hash as shown below:

@request.connection_params[:proxy] = "http://#{@proxy}"
@request.connection_params[:user] = my_username
@request.connection_params[:password] = my_password

Unfortunately, I'm still getting an authentication error. Any ideas?

HTTPS/Secure request

Hi there, thanks for making this gem, very helpful, only issue I am having is making secure requests. I have an https domain and when I run a search the green padlock in Chrome signifying the connection is secure goes away, is there a way to get results with https or does the API not support this?

different behavior when running from a different country

Hi there,

First of all, thank you for this library which make me save a lot of time on one of my current project.
I'm doing a barcode lookup on the Amazon Product Advertising API for this project and I've made a lot of tests but sadly there is one I don't know how to solve:

req = Vacuum.new('FR')
req.configure(
    aws_access_key_id:     'mykey',
    aws_secret_access_key: 'mysecret',
    associate_tag:         'mytag'
)
params = {
  'IdType' => 'EAN',
  'ItemId'    => '0600753233245',
  'SearchIndex' => 'Music',
  'ResponseGroup' => 'Images,ItemAttributes,ItemIds'
}
res = req.item_lookup(params)

on my laptop, in France, this request work well.
But if I run it on my production server located in Amsterdam the item_lookup is raising a 500 error:

/Users/tibo/.rvm/gems/ruby-2.0.0-p247@cd/gems/excon-0.31.0/lib/excon/middlewares/expects.rb:6:in `response_call': Expected(200) <=> Actual(500 InternalServerError) (Excon::Errors::InternalServerError)
    from /Users/tibo/.rvm/gems/ruby-2.0.0-p247@cd/gems/excon-0.31.0/lib/excon/middlewares/response_parser.rb:26:in `response_call'
    from /Users/tibo/.rvm/gems/ruby-2.0.0-p247@cd/gems/excon-0.31.0/lib/excon/connection.rb:398:in `response'
    from /Users/tibo/.rvm/gems/ruby-2.0.0-p247@cd/gems/excon-0.31.0/lib/excon/connection.rb:268:in `request'
    from (eval):3:in `get'
    from /Users/tibo/.rvm/gems/ruby-2.0.0-p247@cd/gems/vacuum-1.0.0/lib/vacuum/request.rb:71:in `block (2 levels) in <class:Request>'
    from vanessa.rb:21:in `<main>'

Is the 500 error raised by the amazon server? how can I see the request?
any idea what's wrong and how I can solve my problem?

Thanks
Thibaut

403 Forbidden

These credentials were working when I was making calls using this client a few months ago. So I'm guessing it's something internal that changed?

irb(main):006:0* client = Apis::AwsSearch::Client.new
=> #<Apis::AwsSearch::Client:0x007faaa1ac7008 @client=#<Vacuum::Request:0x007faaa1ac6f40 @aws_endpoint="http://webservices.amazon.com/onca/xml", @aws_access_key_id="AKIAI7QGG7FPHHF2C56A", @aws_secret_access_key="xxxxxxxxxxxxxxxxxxxxxxxxxxxxpzxW", @associate_tag="celeryai-20">>
irb(main):007:0> client.item_search("George", "Books")
Excon::Error::Forbidden: Expected(200) <=> Actual(403 Forbidden)

	from /Users/carlos/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/excon-0.57.1/lib/excon/middlewares/expects.rb:7:in `response_call'
	from /Users/carlos/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/excon-0.57.1/lib/excon/middlewares/response_parser.rb:9:in `response_call'
	from /Users/carlos/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/excon-0.57.1/lib/excon/connection.rb:388:in `response'
	from /Users/carlos/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/excon-0.57.1/lib/excon/connection.rb:252:in `request'
	from (eval):6:in `get'
	from /Users/carlos/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/vacuum-1.5.0/lib/vacuum/request.rb:112:in `block (2 levels) in <class:Request>'
	from /Users/carlos/Documents/projects/bots/boardbot/lib/apis/aws_search/client.rb:13:in `item_search'
	from (irb):7
	from /Users/carlos/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.3/lib/rails/commands/console.rb:65:in `start'
	from /Users/carlos/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.3/lib/rails/commands/console_helper.rb:9:in `start'
	from /Users/carlos/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.3/lib/rails/commands/commands_tasks.rb:78:in `console'
	from /Users/carlos/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.3/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
	from /Users/carlos/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.3/lib/rails/commands.rb:18:in `<top (required)>'
	from /Users/carlos/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/skylight-1.3.0/lib/skylight/probes.rb:81:in `require'
	from /Users/carlos/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/skylight-1.3.0/lib/skylight/probes.rb:81:in `require'
	from /Users/carlos/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.3/lib/active_support/dependencies.rb:293:in `block in require'
	from /Users/carlos/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.3/lib/active_support/dependencies.rb:259:in `load_dependency'
	from /Users/carlos/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.3/lib/active_support/dependencies.rb:293:in `require'
	from /Users/carlos/Documents/projects/bots/boardbot/bin/rails:9:in `<top (required)>'
	from /Users/carlos/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.3/lib/active_support/dependencies.rb:287:in `load'
	from /Users/carlos/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.3/lib/active_support/dependencies.rb:287:in `block in load'
	from /Users/carlos/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.3/lib/active_support/dependencies.rb:259:in `load_dependency'
	from /Users/carlos/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.3/lib/active_support/dependencies.rb:287:in `load'
	from /Users/carlos/.rbenv/versions/2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
	from /Users/carlos/.rbenv/versions/2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
	from -e:1:in `<main>'

Issues with ruby 2.1.1 ?

System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in gem_original_require': /Users/fregas/.gem/ruby/2.1.1/gems/vacuum-1.1.0/lib/vacuum/request.rb:37: syntax error, unexpected '>' (SyntaxError) params 'AssociateTag' => -> { associate_tag }, ^ /Users/fregas/.gem/ruby/2.1.1/gems/vacuum-1.1.0/lib/vacuum/request.rb:37: odd number list for Hash params 'AssociateTag' => -> { associate_tag }, ^ /Users/fregas/.gem/ruby/2.1.1/gems/vacuum-1.1.0/lib/vacuum/request.rb:37: syntax error, unexpected ',', expecting kEND /Users/fregas/.gem/ruby/2.1.1/gems/vacuum-1.1.0/lib/vacuum/request.rb:38: syntax error, unexpected tASSOC, expecting kEND 'Service' => 'AWSECommerceService', ^ /Users/fregas/.gem/ruby/2.1.1/gems/vacuum-1.1.0/lib/vacuum/request.rb:38: syntax error, unexpected ',', expecting kEND /Users/fregas/.gem/ruby/2.1.1/gems/vacuum-1.1.0/lib/vacuum/request.rb:39: syntax error, unexpected tASSOC, expecting kEND 'Version' => '2011-08-01' ^ /Users/fregas/.gem/ruby/2.1.1/gems/vacuum-1.1.0/lib/vacuum/request.rb:94: syntax error, unexpected kDO_BLOCK, expecting kEND OPERATIONS.each do |operation| ^ /Users/fregas/.gem/ruby/2.1.1/gems/vacuum-1.1.0/lib/vacuum/request.rb:96: syntax error, unexpected kDO_BLOCK, expecting kEND define_method(method_name) do |params, opts = {}| ^ /Users/fregas/.gem/ruby/2.1.1/gems/vacuum-1.1.0/lib/vacuum/request.rb:97: syntax error, unexpected ':', expecting ')' ... = params : opts.update(query: params) ^ /Users/fregas/.gem/ruby/2.1.1/gems/vacuum-1.1.0/lib/vacuum/request.rb:103: syntax error, unexpected kEND, expecting $end from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:inrequire'
from /Users/fregas/.gem/ruby/2.1.1/gems/vacuum-1.1.0/lib/vacuum.rb:2
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in gem_original_require' from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:inrequire'
from ./start:5

I always have Excon::Errors::BadRequest: Expected(200) <=> Actual(400 Bad Request) when I do a 'get'

Hello!
I can't make any request, it always give me back :

Excon::Errors::BadRequest: Expected(200) <=> Actual(400 Bad Request)
    from /Users/christophebelpaire/.rvm/gems/ruby-1.9.3-p392/gems/excon-0.23.0/lib/excon/middlewares/expects.rb:10:in `response_call'
    from /Users/christophebelpaire/.rvm/gems/ruby-1.9.3-p392/gems/excon-0.23.0/lib/excon/connection.rb:353:in `response'
    from /Users/christophebelpaire/.rvm/gems/ruby-1.9.3-p392/gems/excon-0.23.0/lib/excon/connection.rb:247:in `request'
    from (eval):3:in `get'
    from /Users/christophebelpaire/ember-devise/lib/searchable/amazon_search.rb:10:in `search'
    from (irb):13
    from /Users/christophebelpaire/.rvm/gems/ruby-1.9.3-p392/gems/railties-4.0.0.rc2/lib/rails/commands/console.rb:90:in `start'
    from /Users/christophebelpaire/.rvm/gems/ruby-1.9.3-p392/gems/railties-4.0.0.rc2/lib/rails/commands/console.rb:9:in `start'
    from /Users/christophebelpaire/.rvm/gems/ruby-1.9.3-p392/gems/railties-4.0.0.rc2/lib/rails/commands.rb:66:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'

Thanks in advance!

Product Advertising API Amazon

Hi,

My name is Duc, my job is developer website. I need a Product Advertising API Associate account, but I can not register because I do not have an online shop. I just need it to get the products of amazon. You can sell or share account Associate ?

Sorry for my English is not good

Thanks!

Expected(200) <=> Actual(400 Bad Request)

   request = Vacuum.new
   request.configure(
      aws_access_key_id: '<actual_code_here',
      aws_secret_access_key: '<actual_secret_here>',
      associate_tag: '<actual_tag_here>'
    )
    response = request.item_search(
      query: {
        'ItemSearch.Shared.SearchIndex'   => 'All',
        'ItemSearch.Shared.Keywords'      => 'Foucault'
      }
    )

This generates the following error:
Expected(200) <=> Actual(400 Bad Request)

Issue with installation

Just tried to install this gem and got the following error:

gem install vacuum
ERROR:  While executing gem ... (Gem::DependencyError)
    Unable to resolve dependencies: vacuum requires knack (~> 1.0)

I dont see any gem dependencies in gemspec file for this gem, and it does not exist in rubygems.

Any ideas why?

Which project to use – Vacuum or AmazonProduct?

On a project at work, we started to use your AmazonProduct gem (formerly Sucker), which seems perfect for our needs. But today we noticed that you seem to have stopped committing to that repo, and instead are committing to the Vacuum repo. Which repo should we use?

Thanks,
Chris

Missing Examples

The examples are pretty sparse. Most of the time people would also like prices and images which come from the Medium response group, however there is no documentation on how to trigger this request.

Item Lookup Error

{"ItemLookupErrorResponse"=>{"Error"=>{"Code"=>"SignatureDoesNotMatch", "Message"=>"The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details."}, "RequestID"=>"1d7c4e02-f430-4ddb-b4e1-32dab1b2a333"}}

The keys are correct.

Documentation for :response_group

Hey,

Thanks so much for your great gem, it just works :)

I was debugging for quite a while to understand why, when I search (req.find), there are no images in the response and only after going through your code I figured that you can include your :response_group as a parameter.

I think it would be a great idea to add that to your README and the project website, so that users can easily find an answer to the problem.

Cheers!
f3r

seemingly valid xpaths aren't working in find

I'm having trouble using what seems like valid xpath expressions...

>>ah.amazon_response.find("MediumImage")
=> [{"URL"=>"http://ecx.images-amazon.com/images/I/21CBUg0jRpL._SL160_.jpg", "Width"=>{"__content__"=>"160", "Units"=>"pixels"}, "Height"=>{"__content__"=>"160", "Units"=>"pixels"}}, {"URL"=>"http://ecx.images-amazon.com/images/I/21CBUg0jRpL._SL160_.jpg", "Width"=>{"__content__"=>"160", "Units"=>"pixels"}, "Height"=>{"__content__"=>"160", "Units"=>"pixels"}}]
>>ah.amazon_response.find("//MediumImage")
Nokogiri::XML::XPath::SyntaxError: Invalid expression: //xmlns://MediumImage

#get!

Add a Request::Base#get! method that would raise an error if response is not valid.

Excon::Errors::SocketError: malformed header ["missing" Operation parameter?]

I'm using vacuum to access Amazon product data, and all has been well for ~2 weeks now, but last night I started getting this error. The strangest part is that none of the relevant code in my project has changed in any way... this just started out of the blue, seemingly, and now nothing works.

Here is part of an irb session showing what I mean:

2.1.2 :006 > v.item_lookup('ItemId'=>'B00B9BLLMU,B009NW3EGS,B004TGYY08,B006MKR3M0,B000K1CR0K,B00AO07S5G,B004DIQTD2,B00F1O6OEQ,B00A8A52NW,B00ECMZL4C','ResponseGroup'=>'Medium')
Excon::Errors::SocketError: malformed header (Excon::Errors::ResponseParseError)
    from /home/inkybro/.rvm/gems/ruby-2.1.2/gems/excon-0.34.0/lib/excon/response.rb:126:in `parse_headers'
    from /home/inkybro/.rvm/gems/ruby-2.1.2/gems/excon-0.34.0/lib/excon/response.rb:89:in `parse'
    from /home/inkybro/.rvm/gems/ruby-2.1.2/gems/excon-0.34.0/lib/excon/middlewares/response_parser.rb:6:in `response_call'
    from /home/inkybro/.rvm/gems/ruby-2.1.2/gems/excon-0.34.0/lib/excon/connection.rb:402:in `response'
    from /home/inkybro/.rvm/gems/ruby-2.1.2/gems/excon-0.34.0/lib/excon/connection.rb:272:in `request'
    from (eval):3:in `get'
    from /home/inkybro/.rvm/gems/ruby-2.1.2/gems/vacuum-1.1.0/lib/vacuum/request.rb:100:in `block (2 levels) in <class:Request>'
    from (irb):6
    from /home/inkybro/.rvm/rubies/ruby-2.1.2/bin/irb:11:in `<main>'

As you can see, the same happens when I request only 1 ItemId (although it always worked fine with 10).

v.item_lookup('ItemId'=>'B00B9BLLMU','ResponseGroup'=>'Medium')Excon::Errors::SocketError: malformed header (Excon::Errors::ResponseParseError)
    from /home/inkybro/.rvm/gems/ruby-2.1.2/gems/excon-0.34.0/lib/excon/response.rb:126:in `parse_headers'
    from /home/inkybro/.rvm/gems/ruby-2.1.2/gems/excon-0.34.0/lib/excon/response.rb:89:in `parse'
    from /home/inkybro/.rvm/gems/ruby-2.1.2/gems/excon-0.34.0/lib/excon/middlewares/response_parser.rb:6:in `response_call'
    from /home/inkybro/.rvm/gems/ruby-2.1.2/gems/excon-0.34.0/lib/excon/connection.rb:402:in `response'
    from /home/inkybro/.rvm/gems/ruby-2.1.2/gems/excon-0.34.0/lib/excon/connection.rb:272:in `request'
    from (eval):3:in `get'
    from /home/inkybro/.rvm/gems/ruby-2.1.2/gems/vacuum-1.1.0/lib/vacuum/request.rb:100:in `block (2 levels) in <class:Request>'
    from (irb):7
    from /home/inkybro/.rvm/rubies/ruby-2.1.2/bin/irb:11:in `<main>'

When I investigated this further using curl (built and signed the request manually), I found that Amazon was complaining about a "Missing 'Operation' parameter", except that it wasn't missing! I suspect this excon error may be the same thing.

Does anyone have any ideas on this? If I can provide any more info, please let me know.

EDIT: Here's where the error is coming from in excon:

    def self.parse_headers(socket, datum)
      last_key = nil
      until (data = socket.readline.chop!).empty?
        if !data.lstrip!.nil?
          raise Excon::Errors::ResponseParseError, 'malformed header' unless last_key
          # append to last_key's last value
          datum[:response][:headers][last_key] << ' ' << data.rstrip
        else

          # i added these 2 lines
          pp data 
          puts data.inspect

          key, value = data.split(':', 2)

          # this is the error that is raised
          raise Excon::Errors::ResponseParseError, 'malformed header' unless value

          # add key/value or append value to existing values
          datum[:response][:headers][key] = ([datum[:response][:headers][key]] << value.strip).compact.join(', ')
          last_key = key
        end
      end
    end

Here's the output of the 2 lines I added:

2.1.2 :008 > v.item_lookup('ItemId'=>'B00B9BLLMU','ResponseGroup'=>'Medium')
"Date: Fri, 30 May 2014 22:47:17 GMT"
"Date: Fri, 30 May 2014 22:47:17 GMT"
"Server: Server"
"Server: Server"
"Content-Type: text/xml;charset=UTF-8"
"Content-Type: text/xml;charset=UTF-8"
"Vary: Accept-Encoding,User-Agent"
"Vary: Accept-Encoding,User-Agent"
"Connection: close"
"Connection: close"
"Transfer-Encoding: chunked"
"Transfer-Encoding: chunked"
"42e" # <-- NOTE! This seems to change every request I make
"42e" # <-- NOTE! This seems to change every request I make
Excon::Errors::SocketError: malformed header (Excon::Errors::ResponseParseError)
    from /home/kinginky/.rvm/gems/ruby-2.1.2/gems/excon-0.34.0/lib/excon/response.rb:128:in `parse_headers'
    from /home/kinginky/.rvm/gems/ruby-2.1.2/gems/excon-0.34.0/lib/excon/response.rb:89:in `parse'
    from /home/kinginky/.rvm/gems/ruby-2.1.2/gems/excon-0.34.0/lib/excon/middlewares/response_parser.rb:6:in `response_call'
    from /home/kinginky/.rvm/gems/ruby-2.1.2/gems/excon-0.34.0/lib/excon/connection.rb:402:in `response'
    from /home/kinginky/.rvm/gems/ruby-2.1.2/gems/excon-0.34.0/lib/excon/connection.rb:272:in `request'
    from (eval):3:in `get'
    from /home/kinginky/.rvm/gems/ruby-2.1.2/gems/vacuum-1.1.0/lib/vacuum/request.rb:100:in `block (2 levels) in <class:Request>'
    from (irb):8
    from /home/kinginky/.rvm/rubies/ruby-2.1.2/bin/irb:11:in `<main>'

valid? returns true when there are Errors in the response

If you create a request with no operation, you'll get a response where the code is 200, but errors exist. Response.valid? checks that the code is 200, but I'd recommend that you implement with:
def valid?
code == 200 && find("Errors").length == 0
end

NoMethodError for item_search

I have a very simple amazon ruby method defined

class Amazon
  include Cartable

  def initialize
    request.configure(
        aws_access_key_id: 'A...Q',
        aws_secret_access_key: 'Q...y',
        associate_tag: 'p...0'
    )
  end

  def request
    @request ||= Vacuum.new
  end 

  def search keywords, category=""
    @results = request.item_search(
      query: {
        'Keywords' => keywords,
        'SearchIndex' => category
      }
    )
  end

...but when I call search, I always get a NoMethodError on request.item_search

>> am=Amazon.new
=> #<Amazon:0x007fd8bd041350 @request=#<Vacuum::Request:0x007fd8bd040ea0 @aws_endpoint="http://webservices.amazon.com/onca/xml", @aws_access_key_id="A...Q", @aws_secret_access_key="Q..y", @associate_tag="p..0">>
>> am.search "monkey"
NoMethodError: undefined method `item_search' for #<Vacuum::Request:0x007fd8bd040ea0>
	from app/models/amazon.rb:33:in `search'
	from (irb):11

Use Nokogiri methods to browse Amazon response

As this is based on Nokogiri, I thought it might be handy to use Nokogiri methods to browse the Amazon response.

For example, if res is the Amazon response, it would be great to be able to do...

res.xpath('//search critereon')

...even if you first had to do a...

nokores = Nokogiri::XML(res)

Is anything like this possible?

Fails to authenticate with a space in request parameter

Without a space in a request parameter, the request works fine, but with a space it fails.

Example code (where worker = Sucker.new() with appropriate args)

worker << {
  "Operation"     => "ItemSearch",
  "SearchIndex"   => "Books",
  "Author"        => "Orwell" }

response = worker.get

Response is valid

worker << {
  "Operation"     => "ItemSearch",
  "SearchIndex"   => "Books",
  "Author"        => "George Orwell" }

response = worker.get

Response is as follows

<?xml version=\"1.0\"?>
<ItemSearchErrorResponse xmlns=\"http://ecs.amazonaws.com/doc/2010-06-01/\">
<Error>
    <Code>SignatureDoesNotMatch</Code>
    <Message>The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.</Message>
</Error>
<RequestID>ab545dd5-6330-42b6-afd0-5e14233f0f6d</RequestID>
</ItemSearchErrorResponse>

Throttling issue

I need another help, I facing throttling issue in 'VACUUM' gem (It occurs when i request more than 10 queries in a loop)

request = Vacuum.new('IN')

request.configure(
aws_access_key_id: 'AKIAJGAXOKAK********',
aws_secret_access_key: 'yPWtg3vMUTDX5IP0Ko8VJ********************',
associate_tag: 'pen*********'
)

response = request.item_lookup(
query: {
'ItemId' => '1937707881',
'ResponseGroup' => 'Large'
}
)
If i used the request repeatedly throttling errors occur...

Change locale after initialize

Is it possible to change the locale after initializing (using the product_advertising API)? I have the use case where I need to iterate through all marketplaces and it would be useful if I only had to initialize Vacuum once.

Not getting affiliate credit for purchases

Although I have specified my associate tag on every request, including the cart create, I am not getting any credit on my affiliate account for any purchases. I have had a lot of traffic on my site and I know my now there have been purchases yet my affiliate account shows nothing.

I do not believe the associate tags are working properly or, at least it's worth testing.

How can we change the products per page?

Hello,

 Is there any way to increase the number of results in results['ItemSearchResponse']['Items']['Item']? Currently we get only 10 products. How can we display 12 per page?

Thanks

Refactor MWS to separate gem

Refactor common interface to AWS to a separate library.

Move MWS code out of Vacuum.

I can't imagine using former for any other purpose than Product Advertising and Vacuum since Fog has all other bases pretty much covered.

Proxy support

Proxy support through Excon? I can work on it but it will be necessary to modify Jeff also.

request error

require 'sucker'
=> true

worker = Sucker.new( :locale => "us", :key => '###', :secret => '###' )
=> #<Sucker::Request:0x14a1f8c @parameters= ...

@asins = ["0816614024", "0143105825"]
=> ["0816614024", "0143105825"]

worker << { "Operation" => "ItemLookup", "IdType" => "ASIN", "ResponseGroup" => ["ItemAttributes", "OfferFull"], "ItemId" => @asins }
=> {"Service"=>"AWSECommerceService", "Version"=>"2010-06-01", ...}

worker.get

NameError: uninitialized constant Sucker::Request::URI
from .rvm/gems/ruby-1.9.1-p378/gems/sucker-0.7.1/lib/sucker/request.rb:93:in 'uri'
from .rvm/gems/ruby-1.9.1-p378/gems/sucker-0.7.1/lib/sucker/request.rb:53:in 'get'

Excon::Errors::SocketError: Broken pipe (Errno::EPIPE)

Hi Hakan, Thanks for your gem It's really useful, and awesome.
But sometimes got this issue when try to access some books at amazon. It appears only sometimes, not often.

Example of line where this happens:

  $vacuum_amazon.get query: { 'Operation'   => 'ItemSearch', 'SearchIndex' => 'Books', 'Keywords'    => isbn, 'ResponseGroup' => 'Medium' }  

isbn - some isbn of book. They are real, and they exist, so with this everything alright.
Environment:
vacuum v=3.0.0, rails 3.2.7, ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux], debian 6.0.4. This issue found only at production.
Vacuum initializer:

  $vacuum_amazon = Vacuum.new('CA')
  $vacuum_amazon.configure Yml file with key,secret and tag('affiliateTag').

Multiple BrowseNodes doesn't seem to work

def item_search_for node_id
  response = @request.item_search(
               query: {
                 BrowseNode: node_id,
                 Keywords:   'car',
                 SearchIndex:  :Books })
end

puts item_search_for '156566011'
puts item_search_for '156566011'

These two searches both return a few books.

However,

item_search_for '156567011,156566011'

returns an empty array.

The idea is to return results from either BrowseNode.

This seems to be a limitation of the Amazon API, but not sure if there is a good way to do this.

comparison of Array with Array failed

When I try either item_search or item_lookup with the given example I get the error in the title.

Example: @res = req.item_lookup(query: { 'IdType' => 'ASIN', 'ItemId' => '0679753354'})

'key' : wrong number of arguments...

I really want to use this gem, but can't seem to make it past creating a new Vacuum instance. I've tested my key, secret key and tag with Amazon's Signed Requests Helper to confirm they're legit. Here's what I have (just the readme example…)

require 'vacuum'

req = Vacuum.new(:product_advertising) do |config|
  config.key     'AKIAIX6QPD7FK4RDROYQ'
  config.secret  'secret key...'
  config.tag     'battagaiambi-20'
  config.locale  'US'
end

req.build operation:    'ItemSearch', 
          search_index: 'All',
          keywords:     'widget'

res = request.get

if res.valid?
  res.find('Item') do |item|
    puts item['ASIN']
  end
end

Error:

/usr/local/Cellar/ruby/1.9.2-p290/lib/ruby/gems/1.9.1/gems/gems/vacuum-0.2.0/lib/vacuum.rb:38: warning: `&' interpreted as argument prefix
/usr/local/Cellar/ruby/1.9.2-p290/lib/ruby/gems/1.9.1/gems/gems/rack-1.4.0/lib/rack/backports/uri/common_192.rb:20: warning: method redefined; discarding old decode_www_form
/usr/local/Cellar/ruby/1.9.2-p290/lib/ruby/1.9.1/uri/common.rb:836: warning: previous definition of decode_www_form was here
/usr/local/Cellar/ruby/1.9.2-p290/lib/ruby/gems/1.9.1/gems/gems/rack-1.4.0/lib/rack/backports/uri/common_192.rb:32: warning: method redefined; discarding old decode_www_form_component
/usr/local/Cellar/ruby/1.9.2-p290/lib/ruby/1.9.1/uri/common.rb:761: warning: previous definition of decode_www_form_component was here
/usr/local/Cellar/ruby/1.9.2-p290/lib/ruby/gems/1.9.1/gems/gems/vacuum-0.2.0/lib/vacuum/request/base.rb:15: warning: `&' interpreted as argument prefix
/usr/local/Cellar/ruby/1.9.2-p290/lib/ruby/gems/1.9.1/gems/gems/vacuum-0.2.0/lib/vacuum/endpoint/base.rb:17:in `key': wrong number of arguments (1 for 0) (ArgumentError)
    from vacuum.rb:6:in `block in <main>'
    from /usr/local/Cellar/ruby/1.9.2-p290/lib/ruby/gems/1.9.1/gems/gems/vacuum-0.2.0/lib/vacuum/request/base.rb:46:in `configure'
    from /usr/local/Cellar/ruby/1.9.2-p290/lib/ruby/gems/1.9.1/gems/gems/vacuum-0.2.0/lib/vacuum/request/base.rb:15:in `initialize'
    from /usr/local/Cellar/ruby/1.9.2-p290/lib/ruby/gems/1.9.1/gems/gems/vacuum-0.2.0/lib/vacuum.rb:38:in `new'
    from /usr/local/Cellar/ruby/1.9.2-p290/lib/ruby/gems/1.9.1/gems/gems/vacuum-0.2.0/lib/vacuum.rb:38:in `new'
    from vacuum.rb:5:in `<main>'

Bad Request

I have installed this and tried to use it. I am getting 400 errors every time. Has the request requirements changed?

Error:

res = req.item_lookup(query:{'ItemId'=>asin,'ResponseGroup'=>'Medium,OfferFull'}) Excon::Errors::BadRequest: Expected(200) <=> Actual(400 Bad Request)

sucker => amazon_product?

Is this the gem previously knows as "sucker"?
When/Why has it been renamed to "amazon_product"?
Is the "sucker" gem discontinued?
What steps are necessary updating from the latest "sucker" version to "amazon_product"?

It would be nice having a section in the readme (and possibly your blog post about "amazon_product") answering those questions!

Otherwise: thanks for a great library! :)

Regularly: Excon::Errors::Timeout: read timeout reached

I get regularly the following error. What is the best strategy to avoid this?

Excon::Errors::Timeout: read timeout reached
        from /var/www/ast/shared/bundle/ruby/2.3.0/gems/excon-0.48.0/lib/excon/socket.rb:299:in `raise_timeout_error'
        from /var/www/ast/shared/bundle/ruby/2.3.0/gems/excon-0.48.0/lib/excon/socket.rb:49:in `rescue in readline'
        from /var/www/ast/shared/bundle/ruby/2.3.0/gems/excon-0.48.0/lib/excon/socket.rb:44:in `readline'
        from /var/www/ast/shared/bundle/ruby/2.3.0/gems/excon-0.48.0/lib/excon/response.rb:62:in `parse'
        from /var/www/ast/shared/bundle/ruby/2.3.0/gems/excon-0.48.0/lib/excon/middlewares/response_parser.rb:6:in `response_call'
        from /var/www/ast/shared/bundle/ruby/2.3.0/gems/excon-0.48.0/lib/excon/connection.rb:389:in `response'
        from /var/www/ast/shared/bundle/ruby/2.3.0/gems/excon-0.48.0/lib/excon/connection.rb:253:in `request'
        from (eval):6:in `get'
        from /var/www/ast/shared/bundle/ruby/2.3.0/bundler/gems/vacuum-2340ab69a183/lib/vacuum/request.rb:111:in `block (2 levels) in <class:Request>'

Throttle

Any feature or best practice for throttling requests to avoid a Service Unavailable error?

UK Locale

Hi,

im using Vacuum in one of my projects and it works great. Thanks for putting this on GitHub! I found one issue with the Amazon locales. You are using the key "GB" in your HOSTS hash while the official Amazon locale (according to http://docs.aws.amazon.com/AWSECommerceService/latest/DG/InternationalLocales.html) is "UK". It took me while to to figure out why i get "Bad Locale" errors. Maybe it would be possible to accept both "UK" and "GB" in order to not break existing code.

Florian

connection refused on MWS requests

I'm getting the following error when running mws_products/lowest_offer_listings_for_asin.rb example code. The only way to make it works is to hack faraday/adapter/net_http.rb to make Addressable::URI give out #inferred_port instead of #port in faraday/adapter/net_http.rb#net_http_connection.

Another strange thing is that: I also ran a very simple test case using faraday (attached below), and it works. But when I run the example code, it doesn't. I'm not sure whether it's faraday net/http problem or not.

BTW, vacuum's product advertising api works.

version: vacuum 0.2.2 from git master branch
vacuum (0.2.2)
addressable (> 2.2)
faraday (
> 0.7.6)
nokogiri (~> 1.5)

/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:763:in `initialize': Connection refused - connect(2) (Faraday::Error::ConnectionFailed)
    from /rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:763:in `open'
    from /rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:763:in `block in connect'
    from /rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/timeout.rb:54:in `timeout'
    from /rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/timeout.rb:99:in `timeout'
    from /rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:763:in `connect'
    from /rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:755:in `do_start'
    from /rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:744:in `start'
    from /rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:1285:in `request'
    from /rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:1027:in `get'
    from /rvm/gems/ruby-1.9.3-p194@fbaflow/gems/faraday-0.8.1/lib/faraday/adapter/net_http.rb:72:in `perform_request'
    from /rvm/gems/ruby-1.9.3-p194@fbaflow/gems/faraday-0.8.1/lib/faraday/adapter/net_http.rb:36:in `call'
    from /vacuum/request/signature/authentication.rb:27:in `call'
    from /rvm/gems/ruby-1.9.3-p194@fbaflow/gems/faraday-0.8.1/lib/faraday/connection.rb:227:in `run_request'
    from /rvm/gems/ruby-1.9.3-p194@fbaflow/gems/faraday-0.8.1/lib/faraday/connection.rb:87:in `get'
    from /vacuum/lib/vacuum/request/base.rb:70:in `get'
    from examples/mws_products/lowest_offer_listings_for_asin.rb:5:in `<main>'
conn = Faraday.new
uri = Addressable::URI.new :scheme        => 'https',
                           :host          => 'mws.amazonservices.com',
                           :path          => '/'
conn.get uri

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.