a2z 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,22 @@
1
+ ## A2z 0.0.3 (Dec 30, 2012)
2
+
3
+ * Add `small_image`, `medium_image`, and `large_image` accessors on `Item`,
4
+ populating them when present in an item lookup or item search API response.
5
+ *Matt Huggins*
6
+
7
+ * Add `image_sets` accessor on `Item`, populating them when present in an item
8
+ lookup or item search API response. *Matt Huggins*
9
+
10
+ * Add `Item#parent_asin` method to retrieve ASIN for parent item when
11
+ available. *Matt Huggins*
12
+
13
+ * Create this change log file. *Matt Huggins*
14
+
15
+ ## A2z 0.0.2 (Dec 29, 2012)
16
+
17
+ * Create `Item#keys` method & dynamic boolean methods to check for item
18
+ attribute existence. *Matt Huggins*
19
+
20
+ ## A2z 0.0.1 (Dec 27, 2012)
21
+
22
+ * Initial release. *Matt Huggins*
data/README.md CHANGED
@@ -219,6 +219,69 @@ For example:
219
219
  item.detail_page_url
220
220
  => ""http://www.amazon.com/Away-From-World-Deluxe-Version/dp/B008FERRFO..."
221
221
 
222
+ When an item lookup or item search includes the "Images" response group, items
223
+ will also have their `small_image`, `medium_image`, `large_image`, and
224
+ `image_sets` attributes populated, assuming they are included in the API
225
+ response.
226
+
227
+ response = client.item_lookup do
228
+ id 'B008VVEJNE'
229
+ response_group 'Images'
230
+ end
231
+
232
+ item = response.item
233
+
234
+ item.small_image # => #<A2z::Responses::Image ...>
235
+ item.medium_image # => #<A2z::Responses::Image ...>
236
+ item.large_image # => #<A2z::Responses::Image ...>
237
+
238
+ item.image_sets.size # => 2
239
+ item.image_sets.keys # => [:primary, :variant]
240
+ item.image_sets[:primary] # => #<A2z::Responses::ImageSet ...>
241
+
242
+ Refer to the Image Sets and Images sections below for more information on using
243
+ this objects.
244
+
245
+ ### Image Sets
246
+
247
+ Image sets are accessible on items when the "Images" responses group is
248
+ included as part of an item lookup or item search request. Image sets are
249
+ relatively simple objects, only including a category name and hash of images
250
+ keyed by size.
251
+
252
+ For example:
253
+
254
+ response = client.item_lookup do
255
+ id 'B008VVEJNE'
256
+ response_group 'Images'
257
+ end
258
+
259
+ item_set = response.item.image_sets[:primary]
260
+
261
+ item_set.category # => "primary"
262
+ item_set.images.keys # => [:swatch, :small, :thumbnail, :tiny, :medium, :large]
263
+ item_set.images[:swatch] # => #<A2z::Responses::Image ...>
264
+
265
+ Refer to the Images section below for more information on using this objects.
266
+
267
+ ### Images
268
+
269
+ Images are accessible on items and through item sets when the "Images" response
270
+ group is included as part of an item lookup or item search request. Images
271
+ include only vital information, including the URL, width, and height in pixels.
272
+
273
+ For example:
274
+
275
+ response = client.item_lookup do
276
+ id 'B008VVEJNE'
277
+ response_group 'Images'
278
+ end
279
+
280
+ image = response.item.large_image
281
+ image.url # => "http://ecx.images-amazon.com/images/I/411%2BCDuXoSL.jpg"
282
+ image.width # => 297
283
+ image.height # => 500
284
+
222
285
  ### Operation Requests
223
286
 
224
287
  Item lookup and item search response objects include an
@@ -1,3 +1,5 @@
1
+ require 'a2z/responses/image'
2
+ require 'a2z/responses/image_set'
1
3
  require 'a2z/responses/item'
2
4
  require 'a2z/responses/item_link'
3
5
  require 'a2z/responses/item_lookup'
@@ -0,0 +1,24 @@
1
+ module A2z
2
+ module Responses
3
+ class Image
4
+ attr_accessor :url, :width, :height
5
+
6
+ def width=(value)
7
+ @width = value.to_i
8
+ end
9
+
10
+ def height=(value)
11
+ @height = value.to_i
12
+ end
13
+
14
+ def self.from_response(data)
15
+ new.tap do |image|
16
+ image.url = data['URL']
17
+ image.width = data['Width']
18
+ image.height = data['Height']
19
+ image.freeze
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,28 @@
1
+ module A2z
2
+ module Responses
3
+ class ImageSet
4
+ include Helpers
5
+
6
+ attr_accessor :category, :images
7
+
8
+ def initialize
9
+ @images = {}
10
+ end
11
+
12
+ def self.from_response(data)
13
+ new.tap do |image_set|
14
+ image_set.category = data['Category']
15
+
16
+ data.each_pair do |key, value|
17
+ if key =~ /\A(.+)Image\z/
18
+ name = underscore($1).to_sym
19
+ image_set.images[name] = Image.from_response(value)
20
+ end
21
+ end
22
+
23
+ image_set.freeze
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -3,11 +3,13 @@ module A2z
3
3
  class Item
4
4
  include Helpers
5
5
 
6
- attr_accessor :asin, :detail_page_url, :links
6
+ attr_accessor :asin, :parent_asin, :detail_page_url, :links, :image_sets,
7
+ :small_image, :medium_image, :large_image
7
8
 
8
9
  def initialize
9
10
  @links = []
10
11
  @attrs = {}
12
+ @image_sets = {}
11
13
  end
12
14
 
13
15
  def keys
@@ -45,6 +47,7 @@ module A2z
45
47
  def self.from_response(data)
46
48
  new.tap do |item|
47
49
  item.asin = data['ASIN']
50
+ item.parent_asin = data['ParentASIN']
48
51
  item.detail_page_url = data['DetailPageURL']
49
52
 
50
53
  if data['ItemLinks']
@@ -55,6 +58,20 @@ module A2z
55
58
  data['ItemAttributes'].each { |key, value| item[underscore(key)] = value }
56
59
  end
57
60
 
61
+ if data['ImageSets'] && data['ImageSets']['ImageSet']
62
+ image_sets = data['ImageSets']['ImageSet']
63
+ image_sets = [image_sets] unless image_sets.kind_of?(Array)
64
+
65
+ image_sets.each do |image_set|
66
+ image_set = ImageSet.from_response(image_set)
67
+ item.image_sets[image_set.category.to_sym] = image_set
68
+ end
69
+ end
70
+
71
+ item.small_image = Image.from_response(data['SmallImage']) if data['SmallImage']
72
+ item.medium_image = Image.from_response(data['MediumImage']) if data['MediumImage']
73
+ item.large_image = Image.from_response(data['LargeImage']) if data['LargeImage']
74
+
58
75
  item.freeze
59
76
  end
60
77
  end
@@ -1,3 +1,3 @@
1
1
  module A2z
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe A2z::Responses::ImageSet do
4
+ subject do
5
+ A2z::Responses::ImageSet.from_response(image_set_hash)
6
+ end
7
+
8
+ let(:image_set_hash) { Hash.new }
9
+
10
+ describe '.from_response' do
11
+ it 'should return an image set object'
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe A2z::Responses::Image do
4
+ subject do
5
+ A2z::Responses::Image.from_response(image_hash)
6
+ end
7
+
8
+ let(:image_hash) { Hash.new }
9
+
10
+ describe '.from_response' do
11
+ it 'should return an image object'
12
+ end
13
+ end
@@ -2,10 +2,10 @@ require 'spec_helper'
2
2
 
3
3
  describe A2z::Responses::ItemLink do
4
4
  subject do
5
- A2z::Responses::ItemLink.from_response(item_hash)
5
+ A2z::Responses::ItemLink.from_response(item_link_hash)
6
6
  end
7
7
 
8
- let(:item_hash) { Hash.new }
8
+ let(:item_link_hash) { Hash.new }
9
9
 
10
10
  describe '.from_response' do
11
11
  it 'should return an item link object'
@@ -2,10 +2,10 @@ require 'spec_helper'
2
2
 
3
3
  describe A2z::Responses::ItemLookup do
4
4
  subject do
5
- A2z::Responses::ItemLookup.from_response(item_hash)
5
+ A2z::Responses::ItemLookup.from_response(item_lookup_hash)
6
6
  end
7
7
 
8
- let(:item_hash) { Hash.new }
8
+ let(:item_lookup_hash) { Hash.new }
9
9
 
10
10
  describe '.from_response' do
11
11
  it 'should return an item lookup object'
@@ -2,10 +2,10 @@ require 'spec_helper'
2
2
 
3
3
  describe A2z::Responses::ItemSearch do
4
4
  subject do
5
- A2z::Responses::ItemSearch.from_response(item_hash)
5
+ A2z::Responses::ItemSearch.from_response(item_search_hash)
6
6
  end
7
7
 
8
- let(:item_hash) { Hash.new }
8
+ let(:item_search_hash) { Hash.new }
9
9
 
10
10
  describe '.from_response' do
11
11
  it 'should return an item search object'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: a2z
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matt Huggins
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-12-29 00:00:00 -05:00
18
+ date: 2012-12-30 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -84,6 +84,7 @@ extra_rdoc_files: []
84
84
 
85
85
  files:
86
86
  - .gitignore
87
+ - CHANGELOG.md
87
88
  - Gemfile
88
89
  - LICENSE
89
90
  - README.md
@@ -98,6 +99,8 @@ files:
98
99
  - lib/a2z/requests/item_search.rb
99
100
  - lib/a2z/requests/response_group.rb
100
101
  - lib/a2z/responses.rb
102
+ - lib/a2z/responses/image.rb
103
+ - lib/a2z/responses/image_set.rb
101
104
  - lib/a2z/responses/item.rb
102
105
  - lib/a2z/responses/item_link.rb
103
106
  - lib/a2z/responses/item_lookup.rb
@@ -108,6 +111,8 @@ files:
108
111
  - spec/a2z/requests/item_lookup_spec.rb
109
112
  - spec/a2z/requests/item_search_spec.rb
110
113
  - spec/a2z/requests/response_group_spec.rb
114
+ - spec/a2z/responses/image_set_spec.rb
115
+ - spec/a2z/responses/image_spec.rb
111
116
  - spec/a2z/responses/item_link_spec.rb
112
117
  - spec/a2z/responses/item_lookup_spec.rb
113
118
  - spec/a2z/responses/item_search_spec.rb
@@ -155,6 +160,8 @@ test_files:
155
160
  - spec/a2z/requests/item_lookup_spec.rb
156
161
  - spec/a2z/requests/item_search_spec.rb
157
162
  - spec/a2z/requests/response_group_spec.rb
163
+ - spec/a2z/responses/image_set_spec.rb
164
+ - spec/a2z/responses/image_spec.rb
158
165
  - spec/a2z/responses/item_link_spec.rb
159
166
  - spec/a2z/responses/item_lookup_spec.rb
160
167
  - spec/a2z/responses/item_search_spec.rb