dpickett-ramazon_advertising 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/features/getting_offer_details.feature +13 -1
- data/features/step_definitions/product_steps.rb +8 -0
- data/lib/ramazon/offer.rb +3 -1
- data/lib/ramazon/product.rb +98 -0
- data/ramazon_advertising.gemspec +2 -2
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.4
|
@@ -9,10 +9,22 @@ Feature: Retrieving offer details
|
|
9
9
|
|
10
10
|
Scenario: Getting offers on a DVD
|
11
11
|
Given I am searching with the "item_id" of "B000NTPDSW"
|
12
|
-
And I am searching with the "
|
12
|
+
And I am searching with the "condition" of "Used"
|
13
|
+
And I am searching with the "response_group" of "Medium,OfferListings"
|
14
|
+
And I am searching with the "merchant_id" of "All"
|
13
15
|
When I perform the product search
|
14
16
|
Then I should get a product
|
15
17
|
And the product should have "offers"
|
16
18
|
And each of the product's "offers" should have a "price"
|
17
19
|
And each of the product's "offers" should have a "condition"
|
18
20
|
And each of the product's "offers" should have a "sub_condition"
|
21
|
+
And the product should have "used_offers"
|
22
|
+
And each of the product's "used_offers" should have a "condition" of "Used"
|
23
|
+
|
24
|
+
Scenario: Getting offers by subcondition hash
|
25
|
+
Given I am searching with the "item_id" of "B000NTPDSW"
|
26
|
+
And I am searching with the "response_group" of "Medium,OfferListings"
|
27
|
+
When I perform the product search
|
28
|
+
Then I should get a product
|
29
|
+
And the product should have "offers_by_condition"
|
30
|
+
And the product should have "lowest_offers"
|
@@ -54,6 +54,14 @@ Then /^each of the product's "([^\"]*)" should have a "([^\"]*)"$/ do |collectio
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
+
Then /^each of the product's "([^\"]*)" should have a "([^\"]*)" of "([^\"]*)"$/ do |collection_name, attr, value|
|
58
|
+
@product.send(collection_name).should_not be_empty
|
59
|
+
@product.send(collection_name).each do |i|
|
60
|
+
i.send(attr).should_not be_nil
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
|
57
65
|
Then /^the product should have a category tree for "([^\"]*)"$/ do |category_name|
|
58
66
|
@product.category_tree[category_name].should_not be_nil
|
59
67
|
end
|
data/lib/ramazon/offer.rb
CHANGED
@@ -13,13 +13,15 @@ module Ramazon
|
|
13
13
|
# The asking price of the listing (NOTE: Returns Ramazon::Price object)
|
14
14
|
class Offer
|
15
15
|
include HappyMapper
|
16
|
+
include Ramazon::AbstractElement
|
17
|
+
|
16
18
|
tag "Offer"
|
17
19
|
|
18
20
|
has_one :merchant, Ramazon::Merchant, :tag => "Merchant"
|
19
21
|
element :condition, String, :tag => "OfferAttributes/Condition"
|
20
22
|
element :sub_condition, String, :tag => "OfferAttributes/SubCondition"
|
21
23
|
element :listing_id, String, :tag => "OfferListing/OfferListingId"
|
22
|
-
|
24
|
+
abstract_element :price, Ramazon::Price, :tag => "OfferListing/Price"
|
23
25
|
|
24
26
|
end
|
25
27
|
end
|
data/lib/ramazon/product.rb
CHANGED
@@ -153,6 +153,104 @@ module Ramazon
|
|
153
153
|
@category_tree
|
154
154
|
end
|
155
155
|
|
156
|
+
# a sorted list of used offers
|
157
|
+
def used_offers
|
158
|
+
if @used_offers.nil?
|
159
|
+
@used_offers = []
|
160
|
+
self.offers.each do |o|
|
161
|
+
if o.condition.downcase == "used"
|
162
|
+
@used_offers << o
|
163
|
+
end
|
164
|
+
end
|
165
|
+
@used_offers.sort!{|a,b| a.price.amount <=> b.price.amount}
|
166
|
+
end
|
167
|
+
@used_offers
|
168
|
+
end
|
169
|
+
|
170
|
+
# breaks down all the offers in a nested hash of [condition][subcondition]
|
171
|
+
# note: this will load ALL offers into memory
|
172
|
+
# @return [Hash] a nest hash of offers [condition][subcondition] => Array of Ramazon::Offer objects
|
173
|
+
def offers_by_condition
|
174
|
+
@offer_hash = {}
|
175
|
+
offer_page = 1
|
176
|
+
|
177
|
+
|
178
|
+
offers = offer_page(offer_page)
|
179
|
+
while offer_page <= offer_pages
|
180
|
+
offers.each do |o|
|
181
|
+
@offer_hash[o.condition.downcase] ||= {}
|
182
|
+
@offer_hash[o.condition.downcase][o.sub_condition] ||= []
|
183
|
+
@offer_hash[o.condition.downcase][o.sub_condition] << o
|
184
|
+
end
|
185
|
+
|
186
|
+
offer_page += 1
|
187
|
+
offers = offer_page(offer_page)
|
188
|
+
end
|
189
|
+
|
190
|
+
@offer_hash
|
191
|
+
end
|
192
|
+
|
193
|
+
# gets the number of offer pages for the specified product
|
194
|
+
# @pram product the Ramazon::Product we want to get offer pages for
|
195
|
+
# @returns [Integer] number of offer pages
|
196
|
+
def self.offer_pages_for(product)
|
197
|
+
if !@offer_pages
|
198
|
+
offer_page_tags = product.get("//Offers/TotalOfferPages")
|
199
|
+
if offer_page_tags.size > 0
|
200
|
+
offer_pages = offer_page_tags[0].content.to_i
|
201
|
+
else
|
202
|
+
offer_pages = 1
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
offer_pages
|
207
|
+
end
|
208
|
+
|
209
|
+
# get the lowest offers broken down by subcondition
|
210
|
+
# @return [Hash] a nested hash of prices ie ["new"]["mint"] => Ramazon::Offer
|
211
|
+
def lowest_offers
|
212
|
+
if @lowest_offers.nil?
|
213
|
+
@lowest_offers = {}
|
214
|
+
offers_by_condition.each do |condition, sub_conditions|
|
215
|
+
@lowest_offers[condition] = {}
|
216
|
+
sub_conditions.each do |sub_condition, col|
|
217
|
+
sorted_offers = col.sort{|a,b| a.price.amount.to_i <=> b.price.amount.to_i}
|
218
|
+
@lowest_offers[condition][sub_condition] = sorted_offers.first
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
@lowest_offers
|
224
|
+
end
|
225
|
+
|
226
|
+
def offer_pages=(pages)
|
227
|
+
@offer_pages = pages.to_i
|
228
|
+
end
|
229
|
+
|
230
|
+
def offer_pages
|
231
|
+
@offer_pages
|
232
|
+
end
|
233
|
+
|
234
|
+
#get offers from a given page
|
235
|
+
# @param page [Integer] the page number you want to get
|
236
|
+
# @return [Array] Array of Offers returned from the page
|
237
|
+
def offer_page(page = 1)
|
238
|
+
#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
|
249
|
+
else
|
250
|
+
[]
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
156
254
|
private
|
157
255
|
# recursive function used to generate a topdown category tree
|
158
256
|
def build_category_tree(n, child = nil)
|
data/ramazon_advertising.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{ramazon_advertising}
|
5
|
-
s.version = "0.2.
|
5
|
+
s.version = "0.2.4"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Dan Pickett"]
|
9
|
-
s.date = %q{2009-09-
|
9
|
+
s.date = %q{2009-09-12}
|
10
10
|
s.description = %q{TODO: longer description of your gem}
|
11
11
|
s.email = %q{dpickett@enlightsolutions.com}
|
12
12
|
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.2.
|
4
|
+
version: 0.2.4
|
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-
|
12
|
+
date: 2009-09-12 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|