dpickett-ramazon_advertising 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
@@ -22,7 +22,6 @@ Feature: Search for products
22
22
  When I perform the product search
23
23
  Then I should get a list of products
24
24
  And the list of products should have more than 1 product
25
- And each product should have the "product_group" "Video Games"
26
25
 
27
26
  Scenario: Finding multiple browse nodes
28
27
  Given I am searching with the "search_index" of "VideoGames"
@@ -32,3 +31,17 @@ Feature: Search for products
32
31
  Then I should get a list of products
33
32
  And the list of products should have more than 1 product
34
33
  And each product should have the "product_group" "Video Games"
34
+
35
+ Scenario: Finding All Offers optimization
36
+ Given I am searching with the "search_index" of "VideoGames"
37
+ And I am searching with the "response_group" of "Medium,OfferListings"
38
+ And I am searching with the "merchant_id" of "All"
39
+ And I am searching with the "condition" of "All"
40
+ And I am searching with the "offer_page" of "1"
41
+ And I am searching with the "browse_node" of "11075221"
42
+ When I perform the product search
43
+ Then I should get a list of products
44
+ And each product should have "offer_pages"
45
+ And each product should have "has_first_page_of_full_offers"
46
+
47
+
@@ -66,3 +66,10 @@ Then /^the product should have a category tree for "([^\"]*)"$/ do |category_nam
66
66
  @product.category_tree[category_name].should_not be_nil
67
67
  end
68
68
 
69
+
70
+ Then /^each product should have (a\s)?"([^\"]*)"$/ do |a, attr|
71
+ @products.each do |p|
72
+ p.send(attr).should_not be_nil
73
+ end
74
+ end
75
+
@@ -82,6 +82,7 @@ module Ramazon
82
82
  element :release_date, Date, :tag => 'ItemAttributes/ReleaseDate'
83
83
  element :original_release_date, Date, :tag => 'ItemAttributes/OriginalReleaseDate'
84
84
 
85
+ attr_accessor :has_first_page_of_full_offers
85
86
 
86
87
  # Creates the worker that performs the delta indexing
87
88
  # @param options Amazon request options (you can use an underscore convention)
@@ -97,10 +98,17 @@ module Ramazon
97
98
  options[:search_index] ||= "Blended"
98
99
  options[:item_page] ||= 1
99
100
  res = Ramazon::Request.new(options).submit
100
- Ramazon::ProductCollection.create_from_results(options[:item_page] || 1, 10, res)
101
+ products = Ramazon::ProductCollection.create_from_results(options[:item_page] || 1, 10, res)
102
+ if find_options_retrieve_all_offers?(options)
103
+ products.each do |p|
104
+ p.has_first_page_of_full_offers = true
105
+ p.offer_pages = offer_pages_for(p)
106
+ end
107
+ end
108
+ products
101
109
  end
102
110
  end
103
-
111
+
104
112
  # Performs an item lookup
105
113
  # @param item_id the ASIN or UPC you're looking for
106
114
  # @options additional Amazon request options (i.e. :response_group)
@@ -174,7 +182,6 @@ module Ramazon
174
182
  @offer_hash = {}
175
183
  offer_page = 1
176
184
 
177
-
178
185
  offers = offer_page(offer_page)
179
186
  while offer_page <= offer_pages
180
187
  offers.each do |o|
@@ -191,7 +198,7 @@ module Ramazon
191
198
  end
192
199
 
193
200
  # gets the number of offer pages for the specified product
194
- # @pram product the Ramazon::Product we want to get offer pages for
201
+ # @param [Ramazon::Product] product the we want to get offer pages for
195
202
  # @returns [Integer] number of offer pages
196
203
  def self.offer_pages_for(product)
197
204
  if !@offer_pages
@@ -236,18 +243,22 @@ module Ramazon
236
243
  # @return [Array] Array of Offers returned from the page
237
244
  def offer_page(page = 1)
238
245
  #get all offers
239
- products = self.class.find(:item_id => self.asin,
240
- :response_group => "OfferListings",
241
- :merchant_id => "All",
242
- :condition => "All",
243
- :offer_page => page)
244
-
245
- if products
246
- product = products[0]
247
- self.offer_pages = self.class.offer_pages_for(product)
248
- product.offers
246
+ if page == 1 && has_first_page_of_full_offers
247
+ self.offers
249
248
  else
250
- []
249
+ products = self.class.find(:item_id => self.asin,
250
+ :response_group => "OfferListings",
251
+ :merchant_id => "All",
252
+ :condition => "All",
253
+ :offer_page => page)
254
+
255
+ if products
256
+ product = products[0]
257
+ self.offer_pages = self.class.offer_pages_for(product)
258
+ product.offers
259
+ else
260
+ []
261
+ end
251
262
  end
252
263
  end
253
264
 
@@ -275,5 +286,18 @@ module Ramazon
275
286
  n.ancestors("//BrowseNodes/BrowseNode")
276
287
  end
277
288
  end
289
+
290
+ def self.find_options_retrieve_all_offers?(options = {})
291
+ if options[:response_group].is_a?(Array)
292
+ groups = options[:response_group].join(" ")
293
+ else
294
+ groups = options[:response_group] || ""
295
+ end
296
+
297
+ groups =~ /OfferListings/ &&
298
+ (options[:offer_page].nil? || options[:offer_page].to_i == 1) &&
299
+ (options[:merchant_id] == "All") &&
300
+ (options[:condition] == "All")
301
+ end
278
302
  end
279
303
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ramazon_advertising}
8
- s.version = "0.3.0"
8
+ s.version = "0.3.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Dan Pickett"]
12
- s.date = %q{2009-09-14}
12
+ s.date = %q{2009-09-15}
13
13
  s.description = %q{TODO: longer description of your gem}
14
14
  s.email = %q{dpickett@enlightsolutions.com}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dpickett-ramazon_advertising
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Pickett
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-14 00:00:00 -07:00
12
+ date: 2009-09-15 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency