a2z 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +5 -0
- data/README.md +55 -4
- data/a2z.gemspec +1 -0
- data/lib/a2z/responses.rb +2 -0
- data/lib/a2z/responses/item.rb +11 -2
- data/lib/a2z/responses/offer.rb +54 -0
- data/lib/a2z/responses/offer_summary.rb +64 -0
- data/lib/a2z/version.rb +1 -1
- data/spec/a2z/responses/offer_spec.rb +13 -0
- data/spec/a2z/responses/offer_summary_spec.rb +13 -0
- data/spec/a2z/version_spec.rb +1 -1
- metadata +26 -9
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
## A2z 0.1.1 (Jan 3, 2012)
|
2
|
+
|
3
|
+
* Add `offers` and `offer_summary` accessors on `Item`, populating them when
|
4
|
+
present in an item lookup or item search API response. *Matt Huggins*
|
5
|
+
|
1
6
|
## A2z 0.1.0 (Jan 3, 2012)
|
2
7
|
|
3
8
|
* Add `editorial_reviews` accessor on `Item`, populating them when present in
|
data/README.md
CHANGED
@@ -216,18 +216,26 @@ For example:
|
|
216
216
|
|
217
217
|
response = client.item_search { ... } # => #<A2z::Responses::ItemSearch ...>
|
218
218
|
item = response.items.first # => #<A2z::Responses::Item ...>
|
219
|
+
|
219
220
|
item.asin # => "B008FERRFO"
|
220
|
-
item.
|
221
|
-
item.
|
221
|
+
item.keys # => ["artist", "manufacturer", "product_group", "title"]
|
222
|
+
item.title? # => true
|
222
223
|
item.artist? # => true
|
223
224
|
item.manufacturer? # => true
|
224
225
|
item.product_group? # => true
|
225
226
|
item.composer? # => false
|
227
|
+
item.title # => "Away From The World (Deluxe Version)"
|
226
228
|
item.artist # => "Dave Matthews Band"
|
227
229
|
item.manufacturer # => "RCA"
|
228
230
|
item.product_group # => "Music"
|
231
|
+
|
229
232
|
item.editorial_reviews.size # => 1
|
230
233
|
item.editorial_reviews.first # => #<A2z::Responses::EditorialReview ...>
|
234
|
+
|
235
|
+
item.offers.size # => 1
|
236
|
+
item.offers.first # => #<A2z::Responses::Offer ...>
|
237
|
+
item.offer_summary # => #<A2z::Responses::OfferSummary ...>
|
238
|
+
|
231
239
|
item.detail_page_url # => "http://www.amazon.com/Away-From-World-Deluxe-Version/dp/B008FERRFO..."
|
232
240
|
|
233
241
|
When an item lookup or item search includes the "Images" response group, items
|
@@ -251,7 +259,7 @@ response.
|
|
251
259
|
item.image_sets[:primary] # => #<A2z::Responses::ImageSet ...>
|
252
260
|
|
253
261
|
Refer to the Image Sets and Images sections below for more information on using
|
254
|
-
|
262
|
+
these objects.
|
255
263
|
|
256
264
|
### Image Sets
|
257
265
|
|
@@ -292,6 +300,49 @@ For example:
|
|
292
300
|
image.width # => 297
|
293
301
|
image.height # => 500
|
294
302
|
|
303
|
+
### Offers
|
304
|
+
|
305
|
+
Offers are accessible on items when the "Offers", "OfferListings", or
|
306
|
+
"OfferFull" response group is included as part of an item lookup or item search
|
307
|
+
request.
|
308
|
+
|
309
|
+
offer = item.offers.first # => #<A2z::Responses::Offer ...>
|
310
|
+
|
311
|
+
offer.price # => #<Money fractional:699 currency:USD>
|
312
|
+
offer.price.format # => "$6.99"
|
313
|
+
|
314
|
+
offer.amount_saved # => #<Money fractional:699 currency:USD>
|
315
|
+
offer.amount_saved.format # => "$6.99"
|
316
|
+
|
317
|
+
offer.percentage_saved # => 50
|
318
|
+
|
319
|
+
offer.listing_id # => "oRHYBpasjoYr7hV0Ji5g6wjyJVv4xj1ZKnYRnsLsdzvcYotTARQNNueaVBzRP2CJCq..."
|
320
|
+
offer.condition # => "New"
|
321
|
+
offer.availability # => "Usually ships in 24 hours"
|
322
|
+
offer.super_saver_shipping_eligible? # => true
|
323
|
+
|
324
|
+
For more help on working with Money objects, refer to the
|
325
|
+
[RubyMoney gem page](http://rubymoney.github.com/money/).
|
326
|
+
|
327
|
+
### Offer Summaries
|
328
|
+
|
329
|
+
Offer summaries are accessible on items when the "Offers", "OfferFull", or
|
330
|
+
"OfferSummary" response group is included as part of an item lookup or item
|
331
|
+
search request.
|
332
|
+
|
333
|
+
offer_summary = item.offer_summary # => #<A2z::Responses::OfferSummary ...>
|
334
|
+
|
335
|
+
offer_summary.lowest_new_price # => #<Money fractional:699 currency:USD>
|
336
|
+
offer_summary.lowest_used_price # => #<Money fractional:699 currency:USD>
|
337
|
+
|
338
|
+
offer_summary.total_new # => 28
|
339
|
+
offer_summary.total_used # => 17
|
340
|
+
offer_summary.total_collectible # => 0
|
341
|
+
offer_summary.total_refurbished # => 0
|
342
|
+
|
343
|
+
For more help on working with Money objects, refer to the
|
344
|
+
[RubyMoney gem page](http://rubymoney.github.com/money/).
|
345
|
+
|
295
346
|
### Editorial Reviews
|
296
347
|
|
297
348
|
Editorial reviews are accessible on items when the "EditorialResponse" response
|
@@ -304,7 +355,7 @@ response objects only include the source and the content.
|
|
304
355
|
|
305
356
|
### Operation Requests
|
306
357
|
|
307
|
-
Item lookup
|
358
|
+
Item lookup, item search, and browse node lookup response objects include an
|
308
359
|
`A2z::Responses::OperationRequest` accessible via the `#operation_request`
|
309
360
|
instance method.
|
310
361
|
|
data/a2z.gemspec
CHANGED
data/lib/a2z/responses.rb
CHANGED
data/lib/a2z/responses/item.rb
CHANGED
@@ -4,13 +4,15 @@ module A2z
|
|
4
4
|
include Helpers
|
5
5
|
|
6
6
|
attr_accessor :asin, :parent_asin, :detail_page_url, :links, :image_sets,
|
7
|
-
:small_image, :medium_image, :large_image, :editorial_reviews
|
7
|
+
:small_image, :medium_image, :large_image, :editorial_reviews,
|
8
|
+
:offers, :offer_summary
|
8
9
|
|
9
10
|
def initialize
|
10
11
|
@links = []
|
11
12
|
@attrs = {}
|
12
13
|
@image_sets = {}
|
13
14
|
@editorial_reviews = []
|
15
|
+
@offers = []
|
14
16
|
end
|
15
17
|
|
16
18
|
def keys
|
@@ -55,7 +57,9 @@ module A2z
|
|
55
57
|
item.medium_image = Image.from_response(data['MediumImage']) if data['MediumImage']
|
56
58
|
item.large_image = Image.from_response(data['LargeImage']) if data['LargeImage']
|
57
59
|
|
58
|
-
if data['
|
60
|
+
item.offer_summary = OfferSummary.from_response(data['OfferSummary']) if data['OfferSummary']
|
61
|
+
|
62
|
+
if data['ItemLinks'] && data['ItemLinks']['ItemLink']
|
59
63
|
item_links = array_wrap(data['ItemLinks']['ItemLink'])
|
60
64
|
item.links = item_links.collect { |link| ItemLink.from_response(link) }
|
61
65
|
end
|
@@ -77,6 +81,11 @@ module A2z
|
|
77
81
|
item.editorial_reviews = reviews.collect { |review| EditorialReview.from_response(review) }
|
78
82
|
end
|
79
83
|
|
84
|
+
if data['Offers'] && data['Offers']['Offer']
|
85
|
+
offers = array_wrap(data['Offers']['Offer'])
|
86
|
+
item.offers = offers.collect { |offer| Offer.from_response(offer) }
|
87
|
+
end
|
88
|
+
|
80
89
|
item.freeze
|
81
90
|
end
|
82
91
|
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'money'
|
2
|
+
|
3
|
+
module A2z
|
4
|
+
module Responses
|
5
|
+
class Offer
|
6
|
+
attr_accessor :listing_id, :condition, :price, :amount_saved,
|
7
|
+
:percentage_saved, :availability
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@price = Money.new(0, 'USD')
|
11
|
+
@amount_saved = Money.new(0, 'USD')
|
12
|
+
@percentage_saved = 0
|
13
|
+
@super_saver_shipping_eligible = false
|
14
|
+
end
|
15
|
+
|
16
|
+
def price=(value)
|
17
|
+
value = Money.new(value, 'USD') unless value.kind_of?(Money)
|
18
|
+
@price = value
|
19
|
+
end
|
20
|
+
|
21
|
+
def amount_saved=(value)
|
22
|
+
value = Money.new(value, 'USD') unless value.kind_of?(Money)
|
23
|
+
@amount_saved = value
|
24
|
+
end
|
25
|
+
|
26
|
+
def super_saver_shipping_eligible=(value)
|
27
|
+
@super_saver_shipping_eligible = !!value
|
28
|
+
end
|
29
|
+
|
30
|
+
def super_saver_shipping_eligible?
|
31
|
+
@super_saver_shipping_eligible
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.from_response(data)
|
35
|
+
new.tap do |offer|
|
36
|
+
if (attributes = data['OfferAttributes'])
|
37
|
+
offer.condition = attributes['Condition']
|
38
|
+
end
|
39
|
+
|
40
|
+
if (listing = data['OfferListing'])
|
41
|
+
offer.listing_id = listing['OfferListingId']
|
42
|
+
offer.price = Money.new(listing['Price']['Amount'].to_i, listing['Price']['CurrencyCode']) if listing['Price']
|
43
|
+
offer.amount_saved = Money.new(listing['AmountSaved']['Amount'].to_i, listing['AmountSaved']['CurrencyCode']) if listing['AmountSaved']
|
44
|
+
offer.percentage_saved = listing['PercentageSaved'].to_i
|
45
|
+
offer.availability = listing['Availability']
|
46
|
+
offer.super_saver_shipping_eligible = listing['IsEligibleForSuperSaverShipping'] == '1'
|
47
|
+
end
|
48
|
+
|
49
|
+
offer.freeze
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'money'
|
2
|
+
|
3
|
+
module A2z
|
4
|
+
module Responses
|
5
|
+
class OfferSummary
|
6
|
+
attr_accessor :lowest_new_price, :lowest_used_price, :total_new,
|
7
|
+
:total_used, :total_collectible, :total_refurbished
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@lowest_new_price = Money.new(0, 'USD')
|
11
|
+
@lowest_used_price = Money.new(0, 'USD')
|
12
|
+
@total_new = 0
|
13
|
+
@total_used = 0
|
14
|
+
@total_collectible = 0
|
15
|
+
@total_refurbished = 0
|
16
|
+
end
|
17
|
+
|
18
|
+
def lowest_new_price=(value)
|
19
|
+
value = Money.new(value, 'USD') unless value.kind_of?(Money)
|
20
|
+
@lowest_new_price = value
|
21
|
+
end
|
22
|
+
|
23
|
+
def lowest_used_price=(value)
|
24
|
+
value = Money.new(value, 'USD') unless value.kind_of?(Money)
|
25
|
+
@lowest_used_price = value
|
26
|
+
end
|
27
|
+
|
28
|
+
def total_new=(value)
|
29
|
+
@total_new = value.to_i
|
30
|
+
end
|
31
|
+
|
32
|
+
def total_used=(value)
|
33
|
+
@total_used = value.to_i
|
34
|
+
end
|
35
|
+
|
36
|
+
def total_collectible=(value)
|
37
|
+
@total_collectible = value.to_i
|
38
|
+
end
|
39
|
+
|
40
|
+
def total_refurbished=(value)
|
41
|
+
@total_refurbished = value.to_i
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.from_response(data)
|
45
|
+
new.tap do |offer_summary|
|
46
|
+
if data['LowestNewPrice']
|
47
|
+
offer_summary.lowest_new_price = Money.new(data['LowestNewPrice']['Amount'].to_i, data['LowestNewPrice']['CurrencyCode'])
|
48
|
+
end
|
49
|
+
|
50
|
+
if data['LowestUsedPrice']
|
51
|
+
offer_summary.lowest_used_price = Money.new(data['LowestNewPrice']['Amount'].to_i, data['LowestNewPrice']['CurrencyCode'])
|
52
|
+
end
|
53
|
+
|
54
|
+
offer_summary.total_new = data['TotalNew']
|
55
|
+
offer_summary.total_used = data['TotalUsed']
|
56
|
+
offer_summary.total_collectible = data['TotalCollectible']
|
57
|
+
offer_summary.total_refurbished = data['TotalRefurbished']
|
58
|
+
|
59
|
+
offer_summary.freeze
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/lib/a2z/version.rb
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe A2z::Responses::OfferSummary do
|
4
|
+
subject do
|
5
|
+
A2z::Responses::OfferSummary.from_response(offer_summary_hash)
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:offer_summary_hash) { Hash.new }
|
9
|
+
|
10
|
+
describe '.from_response' do
|
11
|
+
it 'should return an offer summary object'
|
12
|
+
end
|
13
|
+
end
|
data/spec/a2z/version_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: a2z
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2013-01-03 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: crack
|
16
|
-
requirement: &
|
16
|
+
requirement: &2151907560 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2151907560
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: jeff
|
27
|
-
requirement: &
|
27
|
+
requirement: &2151906660 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,21 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2151906660
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: money
|
38
|
+
requirement: &2151905960 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2151905960
|
36
47
|
- !ruby/object:Gem::Dependency
|
37
48
|
name: rake
|
38
|
-
requirement: &
|
49
|
+
requirement: &2151904760 !ruby/object:Gem::Requirement
|
39
50
|
none: false
|
40
51
|
requirements:
|
41
52
|
- - ! '>='
|
@@ -43,10 +54,10 @@ dependencies:
|
|
43
54
|
version: '0'
|
44
55
|
type: :development
|
45
56
|
prerelease: false
|
46
|
-
version_requirements: *
|
57
|
+
version_requirements: *2151904760
|
47
58
|
- !ruby/object:Gem::Dependency
|
48
59
|
name: rspec
|
49
|
-
requirement: &
|
60
|
+
requirement: &2151902900 !ruby/object:Gem::Requirement
|
50
61
|
none: false
|
51
62
|
requirements:
|
52
63
|
- - ! '>='
|
@@ -54,7 +65,7 @@ dependencies:
|
|
54
65
|
version: '0'
|
55
66
|
type: :development
|
56
67
|
prerelease: false
|
57
|
-
version_requirements: *
|
68
|
+
version_requirements: *2151902900
|
58
69
|
description: Ruby DSL for Amazon Product Advertising API
|
59
70
|
email: matt.huggins@gmail.com
|
60
71
|
executables: []
|
@@ -88,6 +99,8 @@ files:
|
|
88
99
|
- lib/a2z/responses/item_link.rb
|
89
100
|
- lib/a2z/responses/item_lookup.rb
|
90
101
|
- lib/a2z/responses/item_search.rb
|
102
|
+
- lib/a2z/responses/offer.rb
|
103
|
+
- lib/a2z/responses/offer_summary.rb
|
91
104
|
- lib/a2z/responses/operation_request.rb
|
92
105
|
- lib/a2z/version.rb
|
93
106
|
- spec/a2z/client_spec.rb
|
@@ -104,6 +117,8 @@ files:
|
|
104
117
|
- spec/a2z/responses/item_lookup_spec.rb
|
105
118
|
- spec/a2z/responses/item_search_spec.rb
|
106
119
|
- spec/a2z/responses/item_spec.rb
|
120
|
+
- spec/a2z/responses/offer_spec.rb
|
121
|
+
- spec/a2z/responses/offer_summary_spec.rb
|
107
122
|
- spec/a2z/version_spec.rb
|
108
123
|
- spec/spec_helper.rb
|
109
124
|
- tasks/debug.rake
|
@@ -147,5 +162,7 @@ test_files:
|
|
147
162
|
- spec/a2z/responses/item_lookup_spec.rb
|
148
163
|
- spec/a2z/responses/item_search_spec.rb
|
149
164
|
- spec/a2z/responses/item_spec.rb
|
165
|
+
- spec/a2z/responses/offer_spec.rb
|
166
|
+
- spec/a2z/responses/offer_summary_spec.rb
|
150
167
|
- spec/a2z/version_spec.rb
|
151
168
|
- spec/spec_helper.rb
|