Permalink
Browse files

Rename Request::ProductAdvertising#find to #look_up

  • Loading branch information...
1 parent 7ad8849 commit a7146d9d758a9f7044c20cc192dd23466ec8d07c @hakanensari committed Apr 2, 2012
@@ -1,7 +1,6 @@
require File.expand_path('../shared.rb', __FILE__)
-@req.build 'Operation' => 'ItemLookup',
- 'ItemId' => '0816614024'
-items = @req.get.find 'Item'
+res = @req.look_up '0816614024'
+items = res.find 'Item'
binding.pry
@@ -1,8 +1,5 @@
require File.expand_path('../shared.rb', __FILE__)
-@req.build 'Operation' => 'ItemSearch',
- 'SearchIndex' => 'Books',
- 'Keywords' => 'deleuze'
-items = @req.get.find 'Item'
+items = @req.search(:books, 'Deleuze').find('Item')
binding.pry
@@ -1,13 +1,6 @@
require File.expand_path('../shared.rb', __FILE__)
-# Using a batch request, you can request up to 20 ASINs at a time.
-@req.build 'Operation' => 'ItemLookup',
- 'ItemLookup.Shared.IdType' => 'ASIN',
- 'ItemLookup.Shared.Condition' => 'All',
- 'ItemLookup.Shared.MerchantId' => 'All',
- 'ItemLookup.Shared.ResponseGroup' => 'OfferFull',
- 'ItemLookup.1.ItemId' => Asin[0, 10],
- 'ItemLookup.2.ItemId' => Asin[10, 10]
-items = @req.get.find 'Item'
+res = @req.look_up *Asin.first(20), response_group: 'OfferFull'
+items = res.find 'Item'
binding.pry
@@ -1,11 +1,9 @@
require File.expand_path('../shared.rb', __FILE__)
-@req.build 'Operation' => 'ItemLookup',
- 'MerchantId' => 'All',
- 'Condition' => 'All',
- 'ResponseGroup' => 'OfferFull',
- 'ItemId' => '0816614024',
- 'Version' => '2010-11-01'
-items = @req.get.find('Item')
+res = @req.look_up '0816614024', response_group: 'OfferFull',
+ merchant_id: 'All',
+ condition: 'All',
+ version: '2010-11-01'
+items = res.find('Item')
binding.pry
@@ -3,10 +3,8 @@
# Caveat: Currently there is no way to query Kindle prices other than scraping
# Amazon.
# Alternative strategy: SearchIndex: Books, Power: 'deleuze binding:kindle'
-@req.build 'Operation' => 'ItemSearch',
- 'SearchIndex' => 'KindleStore',
- 'Keywords' => 'deleuze',
- 'ResponseGroup' => 'Large'
-items = @req.get.find 'Item'
+res = @req.search :kindle_store, keywords: 'deleuze',
+ response_group: 'Large'
+items = res.find 'Item'
binding.pry
@@ -20,26 +20,6 @@ def marshal_load(hsh)
end
module Vacuum
- module Request
- class ProductAdvertising
- def search(search_index, parameters = nil)
- if parameters.nil?
- parameters = { 'Keywords' => search_index }
- search_index = 'All'
- end
-
- if parameters.is_a? String
- parameters = { 'Keywords' => parameters }
- end
-
- build!({ 'Operation' => 'ItemSearch',
- 'SearchIndex' => search_index }.merge(parameters))
-
- get.items
- end
- end
- end
-
module Response
class ProductAdvertising
def items
@@ -54,6 +34,6 @@ def items
config.secret = SECRET
config.tag = TAG
end
-items = req.search 'deleuze'
+items = req.search(:books, 'deleuze').items
binding.pry
@@ -1,6 +1,6 @@
require File.expand_path('../shared.rb', __FILE__)
-results, mutex = {}, Mutex.new
+res, mutex = {}, Mutex.new
Vacuum::Endpoint::Base::LOCALES.map do |locale|
Thread.new do
req = Vacuum.new(:product_advertising) do |config|
@@ -10,10 +10,7 @@
config.tag = TAG
end
- req.build 'Operation' => 'ItemLookup',
- 'ItemId' => '0143105825'
-
- mutex.synchronize { results[locale] = req.get.find('Item') }
+ mutex.synchronize { res[locale] = req.look_up('0143105825').find('Item') }
end
end.each(&:join)
@@ -4,15 +4,15 @@ module Request
class ProductAdvertising < Base
# Looks up attributes of up to twenty items.
#
- # item_ids - Splat Array of item IDs. The last element may optionally
- # specify a Hash of parameter key and value pairs.
+ # item_ids - Splat Array of item IDs. The last element may optionally
+ # specify a Hash of parameter key and value pairs.
#
# Examples
#
# request.find '0679753354', response_group: 'Images'
#
# Returns a Vacuum::Response.
- def find(*item_ids)
+ def look_up(*item_ids)
given_params = item_ids.last.is_a?(Hash) ? item_ids.pop : {}
params =
@@ -25,8 +25,8 @@ def find(*item_ids)
when 11..20
default = {
'Operation' => 'ItemLookup',
- 'ItemId.1.ItemId' => item_ids.shift(10),
- 'ItemId.2.ItemId' => item_ids
+ 'ItemLookup.1.ItemId' => item_ids.shift(10),
+ 'ItemLookup.2.ItemId' => item_ids
}
given_params.reduce(default) do |a, (k, v)|
a.merge "ItemLookup.Shared.#{Utils.camelize k.to_s}" => v
@@ -13,7 +13,7 @@ module Request
it_behaves_like 'a request'
- describe '#find' do
+ describe '#look_up' do
before do
request.stub! :get
end
@@ -24,13 +24,13 @@ module Request
context 'given no items' do
it 'raises an error' do
- expect { request.find }.to raise_error ArgumentError
+ expect { request.look_up }.to raise_error ArgumentError
end
end
context 'given up to 10 items' do
before do
- request.find *((1..10).to_a << { :foo => 'bar' })
+ request.look_up *((1..10).to_a << { :foo => 'bar' })
end
it 'builds a single-batch query' do
@@ -44,13 +44,13 @@ module Request
context 'given 11 to to 20 items' do
before do
- request.find *((1..20).to_a << { :foo => 'bar' })
+ request.look_up *((1..20).to_a << { :foo => 'bar' })
end
it 'builds a multi-batch query' do
- first_batch = parameters['ItemId.1.ItemId'].split(',')
+ first_batch = parameters['ItemLookup.1.ItemId'].split(',')
first_batch.should =~ (1..10).map(&:to_s)
- second_batch = parameters['ItemId.2.ItemId'].split(',')
+ second_batch = parameters['ItemLookup.2.ItemId'].split(',')
second_batch.should =~ (11..20).map(&:to_s)
end
@@ -61,7 +61,7 @@ module Request
context 'given over 20 items' do
it 'raises an error' do
- expect { request.find *(1..21) }.to raise_error ArgumentError
+ expect { request.look_up *(1..21) }.to raise_error ArgumentError
end
end
end
@@ -21,7 +21,7 @@ module Response
it_behaves_like 'a response'
- describe '#find' do
+ describe '#[]' do
it 'returns an array of matches' do
response.find('child').should_not be_empty
end

0 comments on commit a7146d9

Please sign in to comment.