asin 1.1.2 → 2.0.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: abef77f2e50d6a015876901fb59472be004cce65
4
- data.tar.gz: c754d67ee4606e8391b6b664335ab88da865caef
3
+ metadata.gz: 00b2605291551bb77e09ebf2bf7f60fa0d7ec6c3
4
+ data.tar.gz: 63d7a88fffc477049a4e1419e3d761133f35cc5f
5
5
  SHA512:
6
- metadata.gz: 078a4412405820ee2950741ee800611e42e39abf9f026c14d4704466ee4079d6fdca5e2897570a14fd334fba2ee65cce0445d765ded0a93858d93af7819970c3
7
- data.tar.gz: b33aac2017be20aac7bd6946e0ff407ab5ef01469e77f76516d4b64225e662983cfcffe89a21315014537166434e587eacb01d3ccc774f05bfcfa61495d1d4bf
6
+ metadata.gz: 0250269c613eca2fc754638bedeb58b5b05719d954e2e57534e76fb16863972bff9bce3e3604808060ad9108b2039b66d7d447d76b4c4ac2d6c18c3f9743084a
7
+ data.tar.gz: 4bcb447e52f21214adb88c0e3b19d96399e3305fa02a1b95352f98a0eab394b55fc974d164c5d536d54f1e5a149301ce54a6b2d752f9298e29c1c6481b9db657
data/.gitignore CHANGED
@@ -4,3 +4,4 @@ pkg
4
4
  .DS_Store
5
5
  .bundle
6
6
  .rvmrc
7
+ coverage
data/.irbrc ADDED
@@ -0,0 +1,12 @@
1
+ $:.unshift File.expand_path('lib')
2
+
3
+ require 'asin'
4
+
5
+ ASIN::Configuration.configure do |config|
6
+ config.secret = ENV['ASIN_SECRET']
7
+ config.key = ENV['ASIN_KEY']
8
+ config.associate_tag = ENV['ASIN_TAG']
9
+ end
10
+
11
+ @client = ASIN::Client.instance
12
+
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -1,6 +1,5 @@
1
1
  script: "bundle exec rake"
2
2
  rvm:
3
- - 1.9.3
3
+ - 2.0.0
4
+ - 2.1.0
4
5
  - jruby-19mode
5
- - rbx-19mode
6
- - ruby-head
@@ -1,3 +1,11 @@
1
+ ## 2.0.0
2
+
3
+ * configurable items are no longer supported, in favor of Hashie::Rash, see upgrading instructions
4
+
5
+ ## 1.2.0
6
+
7
+ * Added more methods to simplify accessing certain nodes. (kyletcarlson) https://github.com/phoet/asin/pull/30
8
+
1
9
  ## 1.1.2
2
10
 
3
11
  * compatibility update https://github.com/phoet/asin/issues/22
data/Gemfile CHANGED
@@ -2,3 +2,8 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in asin.gemspec
4
4
  gemspec
5
+
6
+ group :development do
7
+ gem 'pry-plus', platforms: :ruby
8
+ gem 'coveralls'
9
+ end
@@ -1,36 +1,84 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- asin (1.1.0)
4
+ asin (1.2.0)
5
5
  confiture (>= 0.1)
6
6
  crack (>= 0.3)
7
7
  hashie (>= 1.1)
8
8
  httpi (>= 0.9)
9
+ rash (>= 0.4)
9
10
 
10
11
  GEM
11
12
  remote: http://rubygems.org/
12
13
  specs:
13
14
  addressable (2.3.2)
14
- coderay (1.0.8)
15
+ binding_of_caller (0.7.2)
16
+ debug_inspector (>= 0.0.1)
17
+ bond (0.5.1)
18
+ coderay (1.1.0)
19
+ colorize (0.5.8)
20
+ columnize (0.3.6)
15
21
  confiture (0.1.4)
22
+ coveralls (0.6.7)
23
+ colorize
24
+ multi_json (~> 1.3)
25
+ rest-client
26
+ simplecov (>= 0.7)
27
+ thor
16
28
  crack (0.3.1)
29
+ debug_inspector (0.0.2)
30
+ debugger (1.6.6)
31
+ columnize (>= 0.3.1)
32
+ debugger-linecache (~> 1.2.0)
33
+ debugger-ruby_core_source (~> 1.3.2)
34
+ debugger-linecache (1.2.0)
35
+ debugger-ruby_core_source (1.3.2)
17
36
  diff-lcs (1.1.3)
18
- hashie (1.2.0)
37
+ hashie (2.0.5)
19
38
  httpclient (2.3.0.1)
20
- httpi (2.0.0)
39
+ httpi (2.1.0)
21
40
  rack
22
- method_source (0.8.1)
23
- pry (0.9.10)
24
- coderay (~> 1.0.5)
41
+ rubyntlm (~> 0.3.2)
42
+ interception (0.5)
43
+ jist (1.5.1)
44
+ json
45
+ json (1.8.1)
46
+ method_source (0.8.2)
47
+ mime-types (1.23)
48
+ multi_json (1.7.6)
49
+ pry (0.9.12.6)
50
+ coderay (~> 1.0)
25
51
  method_source (~> 0.8)
26
- slop (~> 3.3.1)
27
- pry (0.9.10-java)
28
- coderay (~> 1.0.5)
29
- method_source (~> 0.8)
30
- slop (~> 3.3.1)
31
- spoon (~> 0.0)
32
- rack (1.4.1)
52
+ slop (~> 3.4)
53
+ pry-debugger (0.2.2)
54
+ debugger (~> 1.3)
55
+ pry (~> 0.9.10)
56
+ pry-doc (0.6.0)
57
+ pry (~> 0.9)
58
+ yard (~> 0.8)
59
+ pry-docmore (0.1.1)
60
+ pry
61
+ pry-doc
62
+ pry-plus (1.0.0)
63
+ bond
64
+ jist
65
+ pry-debugger
66
+ pry-doc
67
+ pry-docmore
68
+ pry-rescue
69
+ pry-stack_explorer
70
+ pry-rescue (1.4.0)
71
+ interception (>= 0.4)
72
+ pry
73
+ pry-stack_explorer (0.4.9.1)
74
+ binding_of_caller (>= 0.7)
75
+ pry (>= 0.9.11)
76
+ rack (1.5.2)
33
77
  rake (0.9.2.2)
78
+ rash (0.4.0)
79
+ hashie (~> 2.0.0)
80
+ rest-client (1.6.7)
81
+ mime-types (>= 1.16)
34
82
  rspec (2.11.0)
35
83
  rspec-core (~> 2.11.0)
36
84
  rspec-expectations (~> 2.11.0)
@@ -39,12 +87,18 @@ GEM
39
87
  rspec-expectations (2.11.3)
40
88
  diff-lcs (~> 1.1.3)
41
89
  rspec-mocks (2.11.3)
42
- slop (3.3.3)
43
- spoon (0.0.1)
90
+ rubyntlm (0.3.4)
91
+ simplecov (0.7.1)
92
+ multi_json (~> 1.0)
93
+ simplecov-html (~> 0.7.1)
94
+ simplecov-html (0.7.1)
95
+ slop (3.5.0)
96
+ thor (0.18.1)
44
97
  vcr (2.2.5)
45
98
  webmock (1.8.11)
46
99
  addressable (>= 2.2.7)
47
100
  crack (>= 0.1.7)
101
+ yard (0.8.7.3)
48
102
 
49
103
  PLATFORMS
50
104
  java
@@ -52,8 +106,9 @@ PLATFORMS
52
106
 
53
107
  DEPENDENCIES
54
108
  asin!
109
+ coveralls
55
110
  httpclient (>= 2.2.3)
56
- pry (~> 0.9.9)
111
+ pry-plus
57
112
  rake (~> 0.9.2.2)
58
113
  rspec (~> 2.11.0)
59
114
  vcr (~> 2.2.5)
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  ## Infos
2
2
 
3
- [![Build Status](https://secure.travis-ci.org/phoet/asin.png)](http://travis-ci.org/phoet/asin)
3
+ [![Build Status](https://img.shields.io/travis/phoet/asin/master.svg)](https://travis-ci.org/phoet/asin)
4
+ [![Code Climate](https://img.shields.io/codeclimate/github/phoet/asin.svg)](https://codeclimate.com/github/phoet/asin)
5
+ [![Coverage Status](https://img.shields.io/coveralls/phoet/asin/master.svg)](https://coveralls.io/r/phoet/asin?branch=master)
4
6
 
5
7
  ASIN is a simple, extensible wrapper for parts of the REST-API of Amazon Product Advertising API (aka Associates Web Service aka Amazon E-Commerce Service).
6
8
 
@@ -10,6 +12,19 @@ Have a look at the [RDOC](http://rdoc.info/projects/phoet/asin) for this project
10
12
 
11
13
  The gem runs smoothly with Rails 3 and is tested against multiple rubies. See *.travis.yml* for details.
12
14
 
15
+
16
+ ## Upgrading from Version 1.x
17
+
18
+ Version 2 removes all the SimpleXXX classes in favor of Hashie::Rash.
19
+
20
+ The old api is available if you require the ASIN::Adapter
21
+
22
+ require 'asin'
23
+ require 'asin/adapter'
24
+
25
+ It's also a good starting point for looking into writing your own API adapter.
26
+
27
+
13
28
  ## Installation
14
29
 
15
30
  gem install asin
@@ -20,6 +35,7 @@ or in your Gemfile:
20
35
  gem 'asin'
21
36
  gem 'httpclient' # optional, see HTTPI
22
37
 
38
+
23
39
  ## Configuration
24
40
 
25
41
  Rails style initializer (config/initializers/asin.rb):
@@ -32,6 +48,7 @@ Rails style initializer (config/initializers/asin.rb):
32
48
 
33
49
  Have a look at ASIN::Configuration class for all the details.
34
50
 
51
+
35
52
  ## Usage
36
53
 
37
54
  ASIN is designed as a module, so you can include it into any object you like:
@@ -58,23 +75,19 @@ But you can also use the *instance* method to get a proxy-object:
58
75
  items = client.lookup '1430218150'
59
76
 
60
77
  # have a look at the title of the item
61
- items.first.title
78
+ items.first.item_attributes.title
62
79
  => Learn Objective-C on the Mac (Learn Series)
63
80
 
64
81
  # search for any kind of stuff on amazon with keywords
65
82
  items = search_keywords 'Learn', 'Objective-C'
66
- items.first.title
83
+ items.first.item_attributes.title
67
84
  => "Learn Objective-C on the Mac (Learn Series)"
68
85
 
69
86
  # search for any kind of stuff on amazon with custom parameters
70
87
  search :Keywords => 'Learn Objective-C', :SearchIndex => :Books
71
- items.first.title
88
+ items.first.item_attributes.title
72
89
  => "Learn Objective-C on the Mac (Learn Series)"
73
90
 
74
- # access the internal data representation (Hashie::Mash)
75
- item.raw.ItemAttributes.ListPrice.FormattedPrice
76
- => $39.99
77
-
78
91
  # search for similar items like the one you already have
79
92
  items = client.similar '1430218150'
80
93
 
@@ -84,51 +97,31 @@ There is an additional set of methods to support AWS cart operations:
84
97
 
85
98
  # create a cart with an item
86
99
  cart = client.create_cart({:asin => '1430218150', :quantity => 1})
87
- cart.items
88
- => [<#Hashie::Mash ASIN="1430218150" CartItemId="U3G241HVLLB8N6" ... >]
89
-
90
- # get an already existing cart from a CartId and HMAC
91
- cart = client.get_cart('176-9182855-2326919', 'KgeVCA0YJTbuN/7Ibakrk/KnHWA=')
92
- cart.empty?
93
- => false
100
+ cart.cart_items.cart_item
101
+ => [<#Hashie::Rash ASIN="1430218150" CartItemId="U3G241HVLLB8N6" ... >]
94
102
 
95
103
  # clear everything from the cart
96
104
  cart = client.clear_cart(cart)
97
- cart.empty?
98
- => true
99
-
100
- # add items to the cart
101
- cart = client.add_items(cart, {:asin => '1430216263', :quantity => 2})
102
- cart.empty?
103
- => false
105
+ cart.cart_items.cart_item
106
+ => []
104
107
 
105
108
  # update items in the cart
106
109
  cart = client.update_items(cart, {:cart_item_id => cart.items.first.CartItemId, :action => :SaveForLater}, {:cart_item_id => cart.items.first.CartItemId, :quantity => 7})
107
- cart.saved_items
108
- => [<#Hashie::Mash ASIN="1430218150" CartItemId="U3G241HVLLB8N6" ... >]
110
+ cart.saved_for_later_items.saved_for_later_item
111
+ => [<#Hashie::Rash ASIN="1430218150" CartItemId="U3G241HVLLB8N6" ... >]
109
112
 
110
113
  It's also possible to access browse nodes:
111
114
 
112
115
  client = ASIN::Client.instance
113
116
 
114
117
  # create a cart with an item
115
- node = client.browse_node('163357', :ResponseGroup => :TopSellers)
116
- node.node_id
118
+ node = client.browse_node('17', :ResponseGroup => :TopSellers)
119
+ node.first.browse_node_id
117
120
  => '163357'
118
- node.name
119
- => 'Comedy'
121
+ node.first.name
122
+ => 'Literature & Fiction'
120
123
 
121
- ## Response Configuration
122
124
 
123
- ASIN is customizable in the way it returns Responses from Amazon.
124
- By default it will return *SimpleItem*, *SimpleCart* or *SimpleNode* instances,
125
- but you can override this behavior for using your custom Classes:
126
-
127
- client.configure :item_type => YourItemClass
128
- client.configure :cart_type => YourCartClass
129
- client.configure :node_type => YourNodeClass
130
-
131
- You can also use built-in *:raw*, *:mash* types.
132
125
  ## HTTPI
133
126
 
134
127
  ASIN uses [HTTPI](https://github.com/rubiii/httpi) as a HTTP-Client adapter.
@@ -137,11 +130,13 @@ As a default HTTPI uses _httpclient_ so you should add that dependency to your p
137
130
 
138
131
  gem 'httpclient'
139
132
 
133
+
140
134
  ## Confiture
141
135
 
142
136
  ASIN uses [Confiture](https://github.com/phoet/confiture) as a Configuration gem.
143
137
  See the Confiture documentation for different configuration styles.
144
138
 
139
+
145
140
  ## License
146
141
 
147
142
  "THE BEER-WARE LICENSE" (Revision 42):
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
20
20
 
21
21
  s.add_dependency('crack', '>= 0.3')
22
22
  s.add_dependency('hashie', '>= 1.1')
23
+ s.add_dependency('rash', '>= 0.4')
23
24
  s.add_dependency('httpi', '>= 0.9')
24
25
  s.add_dependency('confiture', '>= 0.1')
25
26
 
@@ -31,5 +32,4 @@ Gem::Specification.new do |s|
31
32
  s.add_development_dependency('vcr', '~> 2.2.5')
32
33
  s.add_development_dependency('webmock', '~> 1.8.7')
33
34
  s.add_development_dependency('rspec', '~> 2.11.0')
34
- s.add_development_dependency('pry', '~> 0.9.9')
35
35
  end
@@ -1,8 +1,5 @@
1
1
  module ASIN
2
- autoload :Client, 'asin/client'
3
- autoload :SimpleItem, 'asin/simple_item'
4
- autoload :SimpleCart, 'asin/simple_cart'
5
- autoload :SimpleNode, 'asin/simple_node'
6
- autoload :Version, 'asin/version'
7
- autoload :Configuration, 'asin/configuration'
8
- end
2
+ require 'asin/client'
3
+ require 'asin/version'
4
+ require 'asin/configuration'
5
+ end
@@ -0,0 +1,222 @@
1
+ module ASIN
2
+ module Adapter
3
+ def handle_type(data, type)
4
+ Hashie::Rash.new(data).tap do |rash|
5
+ rash.instance_eval do
6
+ case type
7
+ when :cart
8
+ def url
9
+ purchase_url
10
+ end
11
+
12
+ def price
13
+ sub_total.formatted_price
14
+ end
15
+
16
+ def items
17
+ return [] unless cart_items
18
+ cart_items.cart_item.is_a?(Array) ? cart_items.cart_item : [cart_items.cart_item]
19
+ end
20
+
21
+ def saved_items
22
+ return [] unless saved_for_later_items
23
+ saved_for_later_items.saved_for_later_item.is_a?(Array) ? saved_for_later_items.saved_for_later_item : [saved_for_later_items.saved_for_later_item]
24
+ end
25
+
26
+ def valid?
27
+ request.is_valid == 'True'
28
+ end
29
+
30
+ def empty?
31
+ cart_items.nil?
32
+ end
33
+
34
+ when :item
35
+ def title
36
+ item_attributes!.title
37
+ end
38
+
39
+ def amount
40
+ item_attributes!.list_price!.amount.to_i
41
+ end
42
+
43
+ def details_url
44
+ detail_page_url
45
+ end
46
+
47
+ def review
48
+ editorial_reviews!.editorial_review!.content
49
+ end
50
+
51
+ def image_url
52
+ large_image!.url
53
+ end
54
+
55
+ def review
56
+ EditorialReviews!.EditorialReview!.Content
57
+ end
58
+
59
+ def image_url
60
+ LargeImage!.URL
61
+ end
62
+
63
+ # <ItemAttributes>
64
+ def author
65
+ item_attributes!.author
66
+ end
67
+
68
+ def binding
69
+ item_attributes!.binding
70
+ end
71
+
72
+ def brand
73
+ item_attributes!.brand
74
+ end
75
+
76
+ def ean
77
+ item_attributes!.ean
78
+ end
79
+
80
+ def edition
81
+ item_attributes!.edition
82
+ end
83
+
84
+ def isbn
85
+ item_attributes!.isbn
86
+ end
87
+
88
+ def item_dimensions
89
+ item_attributes!.item_dimensions
90
+ end
91
+
92
+ # hundredths of an inch
93
+ def item_height
94
+ item_attributes!.item_dimensions.height
95
+ end
96
+
97
+ # hundredths of an inch
98
+ def item_length
99
+ item_attributes!.item_dimensions[:length]
100
+ end
101
+
102
+ # hundredths of an inch
103
+ def item_width
104
+ item_attributes!.item_dimensions.width
105
+ end
106
+
107
+ # hundredths of a pound
108
+ def item_weight
109
+ item_attributes!.item_dimensions.weight
110
+ end
111
+
112
+ def package_dimensions
113
+ item_attributes!.package_dimensions
114
+ end
115
+
116
+ # hundredths of an inch
117
+ def package_height
118
+ item_attributes!.package_dimensions.height
119
+ end
120
+
121
+ # hundredths of an inch
122
+ def package_length
123
+ item_attributes!.package_dimensions[:length]
124
+ end
125
+
126
+ # hundredths of an inch
127
+ def package_width
128
+ item_attributes!.package_dimensions.width
129
+ end
130
+
131
+ # hundredths of a pound
132
+ def package_weight
133
+ item_attributes!.package_dimensions.weight
134
+ end
135
+
136
+ def label
137
+ item_attributes!.label
138
+ end
139
+
140
+ def language
141
+ item_attributes!.languages.language.first.name
142
+ end
143
+
144
+ def formatted_price
145
+ item_attributes!.list_price.formatted_price
146
+ end
147
+
148
+ def manufacturer
149
+ item_attributes!.manufacturer
150
+ end
151
+
152
+ def mpn
153
+ item_attributes!.mpn
154
+ end
155
+
156
+ def page_count
157
+ item_attributes!.number_of_pages
158
+ end
159
+
160
+ def part_number
161
+ item_attributes!.part_number
162
+ end
163
+
164
+ def product_group
165
+ item_attributes!.product_group
166
+ end
167
+
168
+ def publication_date
169
+ item_attributes!.publication_date
170
+ end
171
+
172
+ def publisher
173
+ item_attributes!.publisher
174
+ end
175
+
176
+ def sku
177
+ item_attributes!.sku
178
+ end
179
+
180
+ def studio
181
+ item_attributes!.studio
182
+ end
183
+
184
+ def total_new
185
+ offer_summary!.total_new
186
+ end
187
+
188
+ def total_used
189
+ offer_summary!.total_used
190
+ end
191
+
192
+ when :node
193
+ def node_id
194
+ browse_node_id
195
+ end
196
+
197
+ def children
198
+ return [] unless children
199
+ children.browse_node.is_a?(Array) ? children.browse_node : [children.browse_node]
200
+ end
201
+
202
+ def ancestors
203
+ return [] unless ancestors
204
+ ancestors.browse_node.is_a?(Array) ? ancestors.browse_node : [ancestors.browse_node]
205
+ end
206
+
207
+ def top_item_set
208
+ return [] unless top_item_set
209
+ top_item_set.top_item.is_a?(Array) ? top_item_set.top_item : [top_item_set.top_item]
210
+ end
211
+ end
212
+ end
213
+ end
214
+ end
215
+ end
216
+
217
+ module Client
218
+ # REM (ps) this is a workaround for jruby, because they don't support Module.prepend https://github.com/jruby/jruby/issues/751
219
+ remove_method :handle_type
220
+ include ASIN::Adapter
221
+ end
222
+ end