a2z 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,10 @@
1
+ ## A2z 0.1.0 (Jan 3, 2012)
2
+
3
+ * Add `editorial_reviews` accessor on `Item`, populating them when present in
4
+ an item lookup or item search API response. *Matt Huggins*
5
+
6
+ * Fix issue with browse node response data being empty. *Matt Huggins*
7
+
1
8
  ## A2z 0.0.4 (Jan 2, 2012)
2
9
 
3
10
  * Implement Amazon's BrowseNodeLookup operation, accessible through
data/README.md CHANGED
@@ -116,7 +116,7 @@ would make the following calls possible.
116
116
  response.total_pages # => 44
117
117
  response.items.size # => 10
118
118
  response.items.first # => #<A2z::Responses::Item ...>
119
- response.more_search_results_url # => "http://www.amazon.com/gp/redirect.html?camp=2025&creative=386001&location=..."
119
+ response.more_search_results_url # => "http://www.amazon.com/gp/redirect.html?camp=2025&creative=386001..."
120
120
  response.operation_request # => #<A2z::Responses::OperationRequest ...>
121
121
 
122
122
  For more information on interacting with `A2z::Responses::Item` and
@@ -226,7 +226,9 @@ For example:
226
226
  item.artist # => "Dave Matthews Band"
227
227
  item.manufacturer # => "RCA"
228
228
  item.product_group # => "Music"
229
- item.detail_page_url # => ""http://www.amazon.com/Away-From-World-Deluxe-Version/dp/B008FERRFO..."
229
+ item.editorial_reviews.size # => 1
230
+ item.editorial_reviews.first # => #<A2z::Responses::EditorialReview ...>
231
+ item.detail_page_url # => "http://www.amazon.com/Away-From-World-Deluxe-Version/dp/B008FERRFO..."
230
232
 
231
233
  When an item lookup or item search includes the "Images" response group, items
232
234
  will also have their `small_image`, `medium_image`, `large_image`, and
@@ -290,6 +292,16 @@ For example:
290
292
  image.width # => 297
291
293
  image.height # => 500
292
294
 
295
+ ### Editorial Reviews
296
+
297
+ Editorial reviews are accessible on items when the "EditorialResponse" response
298
+ group is included as part of an item lookup or item search request. Editorial
299
+ response objects only include the source and the content.
300
+
301
+ review = item.editorial_reviews.first # => #<A2z::Responses::EditorialReview ...>
302
+ review.source # => "Product Description"
303
+ review.content # => "Breakout pop sensation Carly Rae Jepsen releases her..."
304
+
293
305
  ### Operation Requests
294
306
 
295
307
  Item lookup and item search response objects include an
@@ -14,5 +14,9 @@ module A2z
14
14
  word.downcase!
15
15
  end
16
16
  end
17
+
18
+ def array_wrap(value)
19
+ value.kind_of?(Array) ? value : [value].compact
20
+ end
17
21
  end
18
22
  end
@@ -1,5 +1,6 @@
1
1
  require 'a2z/responses/browse_node'
2
2
  require 'a2z/responses/browse_node_lookup'
3
+ require 'a2z/responses/editorial_review'
3
4
  require 'a2z/responses/image'
4
5
  require 'a2z/responses/image_set'
5
6
  require 'a2z/responses/item'
@@ -1,6 +1,8 @@
1
1
  module A2z
2
2
  module Responses
3
3
  class BrowseNode
4
+ include Helpers
5
+
4
6
  attr_accessor :id, :name, :ancestors, :children
5
7
 
6
8
  def initialize
@@ -23,20 +25,20 @@ module A2z
23
25
 
24
26
  def self.from_response(data)
25
27
  new.tap do |browse_node|
26
- browse_node.id = data['BrowseNodeId']
27
- browse_node.name = data['Name']
28
- browse_node.root = data['IsCategoryRoot'] == '1' rescue false
29
-
30
- if data['Children'] && data['Children']['BrowseNode']
31
- children = data['Children']['BrowseNode']
32
- children = [children] unless children.kind_of?(Array)
33
- browse_node.children = children.collect { |child| BrowseNode.from_response(child) }
34
- end
35
-
36
- if data['Ancestors'] && data['Ancestors']['BrowseNode']
37
- ancestors = data['Ancestors']['BrowseNode']
38
- ancestors = [ancestors] unless ancestors.kind_of?(Array)
39
- browse_node.ancestors = ancestors.collect { |ancestor| BrowseNode.from_response(ancestor) }
28
+ if data
29
+ browse_node.id = data['BrowseNodeId']
30
+ browse_node.name = data['Name']
31
+ browse_node.root = data['IsCategoryRoot'] == '1' rescue false
32
+
33
+ if data['Children'] && data['Children']['BrowseNode']
34
+ children = array_wrap(data['Children']['BrowseNode'])
35
+ browse_node.children = children.collect { |child| BrowseNode.from_response(child) }
36
+ end
37
+
38
+ if data['Ancestors'] && data['Ancestors']['BrowseNode']
39
+ ancestors = array_wrap(data['Ancestors']['BrowseNode'])
40
+ browse_node.ancestors = ancestors.collect { |ancestor| BrowseNode.from_response(ancestor) }
41
+ end
40
42
  end
41
43
 
42
44
  browse_node.freeze
@@ -0,0 +1,15 @@
1
+ module A2z
2
+ module Responses
3
+ class EditorialReview
4
+ attr_accessor :source, :content
5
+
6
+ def self.from_response(data)
7
+ new.tap do |editorial_review|
8
+ editorial_review.source = data['Source']
9
+ editorial_review.content = data['Content']
10
+ editorial_review.freeze
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -3,6 +3,11 @@ module A2z
3
3
  class Image
4
4
  attr_accessor :url, :width, :height
5
5
 
6
+ def initialize
7
+ @width = 0
8
+ @height = 0
9
+ end
10
+
6
11
  def width=(value)
7
12
  @width = value.to_i
8
13
  end
@@ -4,12 +4,13 @@ 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
7
+ :small_image, :medium_image, :large_image, :editorial_reviews
8
8
 
9
9
  def initialize
10
10
  @links = []
11
11
  @attrs = {}
12
12
  @image_sets = {}
13
+ @editorial_reviews = []
13
14
  end
14
15
 
15
16
  def keys
@@ -23,7 +24,7 @@ module A2z
23
24
  def method_missing(name, *args, &block)
24
25
  method_name = name.to_s
25
26
 
26
- if method_name.end_with?('?') # && method_name != 'has_key?'
27
+ if method_name.end_with?('?')
27
28
  has_key?(method_name.sub(/\?$/, ''))
28
29
  elsif has_key?(method_name)
29
30
  self[method_name]
@@ -50,8 +51,13 @@ module A2z
50
51
  item.parent_asin = data['ParentASIN']
51
52
  item.detail_page_url = data['DetailPageURL']
52
53
 
54
+ item.small_image = Image.from_response(data['SmallImage']) if data['SmallImage']
55
+ item.medium_image = Image.from_response(data['MediumImage']) if data['MediumImage']
56
+ item.large_image = Image.from_response(data['LargeImage']) if data['LargeImage']
57
+
53
58
  if data['ItemLinks']
54
- item.links = data['ItemLinks']['ItemLink'].collect { |link| ItemLink.from_response(link) }
59
+ item_links = array_wrap(data['ItemLinks']['ItemLink'])
60
+ item.links = item_links.collect { |link| ItemLink.from_response(link) }
55
61
  end
56
62
 
57
63
  if data['ItemAttributes']
@@ -59,18 +65,17 @@ module A2z
59
65
  end
60
66
 
61
67
  if data['ImageSets'] && data['ImageSets']['ImageSet']
62
- image_sets = data['ImageSets']['ImageSet']
63
- image_sets = [image_sets] unless image_sets.kind_of?(Array)
64
-
68
+ image_sets = array_wrap(data['ImageSets']['ImageSet'])
65
69
  image_sets.each do |image_set|
66
70
  image_set = ImageSet.from_response(image_set)
67
71
  item.image_sets[image_set.category.to_sym] = image_set
68
72
  end
69
73
  end
70
74
 
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']
75
+ if data['EditorialReviews'] && data['EditorialReviews']['EditorialReview']
76
+ reviews = array_wrap(data['EditorialReviews']['EditorialReview'])
77
+ item.editorial_reviews = reviews.collect { |review| EditorialReview.from_response(review) }
78
+ end
74
79
 
75
80
  item.freeze
76
81
  end
@@ -1,6 +1,8 @@
1
1
  module A2z
2
2
  module Responses
3
3
  class ItemSearch
4
+ include Helpers
5
+
4
6
  attr_accessor :operation_request, :items, :total_results, :total_pages, :more_search_results_url
5
7
 
6
8
  def initialize
@@ -35,8 +37,7 @@ module A2z
35
37
  private
36
38
 
37
39
  def self.items_from_response(data)
38
- items = data['Items']['Item'] rescue []
39
- items = [items].compact unless items.kind_of?(Array)
40
+ items = array_wrap(data['Items']['Item']) rescue []
40
41
  items.collect { |item| Item.from_response(item) }
41
42
  end
42
43
  end
@@ -1,6 +1,8 @@
1
1
  module A2z
2
2
  module Responses
3
3
  class OperationRequest
4
+ include Helpers
5
+
4
6
  attr_accessor :request_id, :request_processing_time, :headers, :arguments
5
7
 
6
8
  def initialize
@@ -13,16 +15,14 @@ module A2z
13
15
  operation_request.request_id = data['RequestId']
14
16
  operation_request.request_processing_time = data['RequestProcessingTime'].to_f
15
17
 
16
- if data['HTTPHeaders']
17
- headers = data['HTTPHeaders']['Header']
18
- headers = [headers] unless headers.kind_of?(Array)
18
+ if data['HTTPHeaders'] && data['HTTPHeaders']['Header']
19
+ headers = array_wrap(data['HTTPHeaders']['Header'])
19
20
  headers = headers.collect { |h| [ h['Name'], h['Value'] ] }
20
21
  operation_request.headers = Hash[headers]
21
22
  end
22
23
 
23
- if data['Arguments']
24
- arguments = data['Arguments']['Argument']
25
- arguments = [arguments] unless arguments.kind_of?(Array)
24
+ if data['Arguments'] && data['Arguments']['Argument']
25
+ arguments = array_wrap(data['Arguments']['Argument'])
26
26
  arguments = arguments.collect { |a| [ a['Name'], a['Value'] ] }
27
27
  operation_request.arguments = Hash[arguments]
28
28
  end
@@ -1,3 +1,3 @@
1
1
  module A2z
2
- VERSION = '0.0.4'
2
+ VERSION = '0.1.0'
3
3
  end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe A2z::Responses::EditorialReview do
4
+ subject do
5
+ A2z::Responses::EditorialReview.from_response(editorial_review_hash)
6
+ end
7
+
8
+ let(:editorial_review_hash) { Hash.new }
9
+
10
+ describe '.from_response' do
11
+ it 'should return an editorial review object'
12
+ end
13
+ end
@@ -3,5 +3,5 @@ require 'spec_helper'
3
3
  describe A2z do
4
4
  subject { A2z }
5
5
 
6
- specify { subject::VERSION.should == '0.0.4' }
6
+ specify { subject::VERSION.should == '0.1.0' }
7
7
  end
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.0.4
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-02 00:00:00.000000000 Z
12
+ date: 2013-01-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: crack
16
- requirement: &2156589140 !ruby/object:Gem::Requirement
16
+ requirement: &2152624760 !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: *2156589140
24
+ version_requirements: *2152624760
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: jeff
27
- requirement: &2156588160 !ruby/object:Gem::Requirement
27
+ requirement: &2152623600 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2156588160
35
+ version_requirements: *2152623600
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &2156587300 !ruby/object:Gem::Requirement
38
+ requirement: &2152623080 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2156587300
46
+ version_requirements: *2152623080
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &2156586640 !ruby/object:Gem::Requirement
49
+ requirement: &2152622440 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2156586640
57
+ version_requirements: *2152622440
58
58
  description: Ruby DSL for Amazon Product Advertising API
59
59
  email: matt.huggins@gmail.com
60
60
  executables: []
@@ -81,6 +81,7 @@ files:
81
81
  - lib/a2z/responses.rb
82
82
  - lib/a2z/responses/browse_node.rb
83
83
  - lib/a2z/responses/browse_node_lookup.rb
84
+ - lib/a2z/responses/editorial_review.rb
84
85
  - lib/a2z/responses/image.rb
85
86
  - lib/a2z/responses/image_set.rb
86
87
  - lib/a2z/responses/item.rb
@@ -96,6 +97,7 @@ files:
96
97
  - spec/a2z/requests/response_group_spec.rb
97
98
  - spec/a2z/responses/browse_node_lookup_spec.rb
98
99
  - spec/a2z/responses/browse_node_spec.rb
100
+ - spec/a2z/responses/editorial_review_spec.rb
99
101
  - spec/a2z/responses/image_set_spec.rb
100
102
  - spec/a2z/responses/image_spec.rb
101
103
  - spec/a2z/responses/item_link_spec.rb
@@ -138,6 +140,7 @@ test_files:
138
140
  - spec/a2z/requests/response_group_spec.rb
139
141
  - spec/a2z/responses/browse_node_lookup_spec.rb
140
142
  - spec/a2z/responses/browse_node_spec.rb
143
+ - spec/a2z/responses/editorial_review_spec.rb
141
144
  - spec/a2z/responses/image_set_spec.rb
142
145
  - spec/a2z/responses/image_spec.rb
143
146
  - spec/a2z/responses/item_link_spec.rb