asin 0.6.0 → 0.6.1
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/CHANGELOG.rdoc +12 -0
- data/README.rdoc +2 -3
- data/lib/asin/client.rb +9 -9
- data/lib/asin/configuration.rb +9 -1
- data/lib/asin/version.rb +1 -1
- data/spec/search_spec.rb +6 -3
- metadata +24 -25
- data/cassettes/bad_configuration.yml +0 -29
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
== 0.6.1
|
2
|
+
|
3
|
+
* fix error when passing nil to config values
|
4
|
+
|
5
|
+
== 0.6.0
|
6
|
+
|
7
|
+
* change lookup method - pull request https://github.com/phoet/asin/pull/8
|
8
|
+
|
9
|
+
== 0.5.1
|
10
|
+
|
11
|
+
* fix for https://github.com/phoet/asin/issues/7
|
12
|
+
|
1
13
|
== 0.5.0
|
2
14
|
|
3
15
|
* move client to own file
|
data/README.rdoc
CHANGED
@@ -5,7 +5,7 @@ Build: http://travis-ci.org/phoet/asin.png
|
|
5
5
|
|
6
6
|
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).
|
7
7
|
|
8
|
-
For more information on the REST calls, have a look at the whole Amazon E-Commerce-API[http://docs.amazonwebservices.com/AWSECommerceService/
|
8
|
+
For more information on the REST calls, have a look at the whole Amazon E-Commerce-API[http://docs.amazonwebservices.com/AWSECommerceService/latest/DG/index.html].
|
9
9
|
|
10
10
|
Have a look at the RDOC[http://rdoc.info/projects/phoet/asin] for this project, if you like browsing some docs.
|
11
11
|
|
@@ -54,14 +54,13 @@ With the latest version of the Product Advertising API you need to include your
|
|
54
54
|
config.associate_tag = 'your-tag'
|
55
55
|
end
|
56
56
|
|
57
|
-
|
58
57
|
== Usage
|
59
58
|
|
60
59
|
ASIN is designed as a module, so you can include it into any object you like:
|
61
60
|
|
62
61
|
# require and include
|
63
62
|
require 'asin'
|
64
|
-
include ASIN
|
63
|
+
include ASIN::Client
|
65
64
|
|
66
65
|
# lookup an ASIN
|
67
66
|
lookup '1430218150'
|
data/lib/asin/client.rb
CHANGED
@@ -47,7 +47,7 @@ require 'base64'
|
|
47
47
|
# == Further Configuration
|
48
48
|
#
|
49
49
|
# If you need more controll over the request that is sent to the
|
50
|
-
# Amazon API (http://docs.amazonwebservices.com/AWSECommerceService/
|
50
|
+
# Amazon API (http://docs.amazonwebservices.com/AWSECommerceService/latest/DG/index.html),
|
51
51
|
# you can override some defaults or add additional query-parameters to the REST calls:
|
52
52
|
#
|
53
53
|
# configure :host => 'webservices.amazon.de'
|
@@ -165,7 +165,7 @@ module ASIN
|
|
165
165
|
#
|
166
166
|
# search_keywords('nirvana', 'never mind', :SearchIndex => :Music)
|
167
167
|
#
|
168
|
-
# Have a look at the different search index values on the Amazon-Documentation[http://docs.amazonwebservices.com/AWSECommerceService/
|
168
|
+
# Have a look at the different search index values on the Amazon-Documentation[http://docs.amazonwebservices.com/AWSECommerceService/latest/DG/index.html]
|
169
169
|
#
|
170
170
|
def search_keywords(*keywords)
|
171
171
|
params = keywords.last.is_a?(Hash) ? keywords.pop : {:SearchIndex => :Books, :ResponseGroup => :Medium}
|
@@ -185,7 +185,7 @@ module ASIN
|
|
185
185
|
#
|
186
186
|
# search(:Keywords => 'nirvana', :SearchIndex => :Music)
|
187
187
|
#
|
188
|
-
# Have a look at the different search index values on the Amazon-Documentation[http://docs.amazonwebservices.com/AWSECommerceService/
|
188
|
+
# Have a look at the different search index values on the Amazon-Documentation[http://docs.amazonwebservices.com/AWSECommerceService/latest/DG/index.html]
|
189
189
|
#
|
190
190
|
def search(params={:SearchIndex => :Books, :ResponseGroup => :Medium})
|
191
191
|
response = call(params.merge(:Operation => :ItemSearch))
|
@@ -204,7 +204,7 @@ module ASIN
|
|
204
204
|
#
|
205
205
|
# browse_node('163357', :ResponseGroup => :TopSellers)
|
206
206
|
#
|
207
|
-
# Have a look at the different browse node values on the Amazon-Documentation[http://docs.amazonwebservices.com/AWSECommerceService/
|
207
|
+
# Have a look at the different browse node values on the Amazon-Documentation[http://docs.amazonwebservices.com/AWSECommerceService/latest/DG/index.html]
|
208
208
|
#
|
209
209
|
def browse_node(node_id, params={:ResponseGroup => :BrowseNodeInfo})
|
210
210
|
response = call(params.merge(:Operation => :BrowseNodeLookup, :BrowseNodeId => node_id))
|
@@ -223,7 +223,7 @@ module ASIN
|
|
223
223
|
#
|
224
224
|
# create_cart({:asin => '1430218150', :quantity => 1}, {:asin => '1430216263', :quantity => 1, :action => :SaveForLater})
|
225
225
|
#
|
226
|
-
# Have a look at the different cart item operation values on the Amazon-Documentation[http://docs.amazonwebservices.com/AWSECommerceService/
|
226
|
+
# Have a look at the different cart item operation values on the Amazon-Documentation[http://docs.amazonwebservices.com/AWSECommerceService/latest/DG/index.html]
|
227
227
|
#
|
228
228
|
def create_cart(*items)
|
229
229
|
cart(:CartCreate, create_item_params(items))
|
@@ -251,7 +251,7 @@ module ASIN
|
|
251
251
|
#
|
252
252
|
# add_items(cart, {:asin => '1430218150', :quantity => 1}, {:asin => '1430216263', :quantity => 1, :action => :SaveForLater})
|
253
253
|
#
|
254
|
-
# Have a look at the different cart item operation values on the Amazon-Documentation[http://docs.amazonwebservices.com/AWSECommerceService/
|
254
|
+
# Have a look at the different cart item operation values on the Amazon-Documentation[http://docs.amazonwebservices.com/AWSECommerceService/latest/DG/index.html]
|
255
255
|
#
|
256
256
|
def add_items(cart, *items)
|
257
257
|
cart(:CartAdd, create_item_params(items).merge({:CartId => cart.cart_id, :HMAC => cart.hmac}))
|
@@ -269,7 +269,7 @@ module ASIN
|
|
269
269
|
#
|
270
270
|
# update_items(cart, {:cart_item_id => cart.items.first.CartItemId, :action => :SaveForLater}, {:cart_item_id => cart.items.first.CartItemId, :quantity => 7})
|
271
271
|
#
|
272
|
-
# Have a look at the different cart item operation values on the Amazon-Documentation[http://docs.amazonwebservices.com/AWSECommerceService/
|
272
|
+
# Have a look at the different cart item operation values on the Amazon-Documentation[http://docs.amazonwebservices.com/AWSECommerceService/latest/DG/index.html]
|
273
273
|
#
|
274
274
|
def update_items(cart, *items)
|
275
275
|
cart(:CartModify, create_item_params(items).merge({:CartId => cart.cart_id, :HMAC => cart.hmac}))
|
@@ -361,8 +361,8 @@ module ASIN
|
|
361
361
|
params[:Service] = :AWSECommerceService
|
362
362
|
params[:AWSAccessKeyId] = Configuration.key
|
363
363
|
|
364
|
-
params[:Version] = Configuration.version unless Configuration.version
|
365
|
-
params[:AssociateTag] = Configuration.associate_tag unless Configuration.associate_tag
|
364
|
+
params[:Version] = Configuration.version unless Configuration.blank? :version
|
365
|
+
params[:AssociateTag] = Configuration.associate_tag unless Configuration.blank? :associate_tag
|
366
366
|
|
367
367
|
# utc timestamp needed for signing
|
368
368
|
params[:Timestamp] = Time.now.utc.strftime('%Y-%m-%dT%H:%M:%SZ')
|
data/lib/asin/configuration.rb
CHANGED
@@ -68,7 +68,8 @@ module ASIN
|
|
68
68
|
# Checks if given credentials are valid and raises an error if not.
|
69
69
|
#
|
70
70
|
def validate_credentials!
|
71
|
-
raise "you have to configure ASIN: 'configure :secret => 'your-secret', :key => 'your-key'
|
71
|
+
raise "you have to configure ASIN: 'configure :secret => 'your-secret', :key => 'your-key'" if blank?(:secret) || blank?(:key)
|
72
|
+
[:host, :item_type, :cart_type, :node_type, :version, :associate_tag].each { |item| raise "nil is not a valid value for #{item}" unless self.send item }
|
72
73
|
end
|
73
74
|
|
74
75
|
# Resets configuration to defaults
|
@@ -77,6 +78,13 @@ module ASIN
|
|
77
78
|
init_config(true)
|
78
79
|
end
|
79
80
|
|
81
|
+
# Check if a key is set
|
82
|
+
#
|
83
|
+
def blank?(key)
|
84
|
+
val = self.send :key
|
85
|
+
val.nil? || val.empty?
|
86
|
+
end
|
87
|
+
|
80
88
|
private()
|
81
89
|
|
82
90
|
def init_config(force=false)
|
data/lib/asin/version.rb
CHANGED
data/spec/search_spec.rb
CHANGED
@@ -14,9 +14,12 @@ module ASIN
|
|
14
14
|
|
15
15
|
context "configuration" do
|
16
16
|
it "should fail without secret and key" do
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
lambda { @helper.lookup 'bla' }.should raise_error(RuntimeError, "you have to configure ASIN: 'configure :secret => 'your-secret', :key => 'your-key'")
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should fail with configuration key set to nil" do
|
21
|
+
@helper.configure :secret => @secret, :key => @key, :associate_tag => nil
|
22
|
+
lambda { @helper.lookup 'bla' }.should raise_error(RuntimeError, "nil is not a valid value for associate_tag")
|
20
23
|
end
|
21
24
|
|
22
25
|
it "should fail with wrong configuration key" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,12 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-08-
|
12
|
+
date: 2011-08-24 00:00:00.000000000 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: crack
|
17
|
-
requirement: &
|
17
|
+
requirement: &2153661220 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: 0.1.8
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *2153661220
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: hashie
|
28
|
-
requirement: &
|
28
|
+
requirement: &2153660720 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: 1.0.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *2153660720
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: httpi
|
39
|
-
requirement: &
|
39
|
+
requirement: &2153660260 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ~>
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: 0.9.5
|
45
45
|
type: :runtime
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *2153660260
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: httpclient
|
50
|
-
requirement: &
|
50
|
+
requirement: &2153659800 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ~>
|
@@ -55,10 +55,10 @@ dependencies:
|
|
55
55
|
version: 2.2.1
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *2153659800
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: rash
|
61
|
-
requirement: &
|
61
|
+
requirement: &2153659340 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - ~>
|
@@ -66,10 +66,10 @@ dependencies:
|
|
66
66
|
version: 0.3.0
|
67
67
|
type: :development
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *2153659340
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: rake
|
72
|
-
requirement: &
|
72
|
+
requirement: &2153658880 !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
74
74
|
requirements:
|
75
75
|
- - ~>
|
@@ -77,10 +77,10 @@ dependencies:
|
|
77
77
|
version: 0.9.2
|
78
78
|
type: :development
|
79
79
|
prerelease: false
|
80
|
-
version_requirements: *
|
80
|
+
version_requirements: *2153658880
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
82
|
name: httpclient
|
83
|
-
requirement: &
|
83
|
+
requirement: &2153658420 !ruby/object:Gem::Requirement
|
84
84
|
none: false
|
85
85
|
requirements:
|
86
86
|
- - ~>
|
@@ -88,10 +88,10 @@ dependencies:
|
|
88
88
|
version: 2.2.1
|
89
89
|
type: :development
|
90
90
|
prerelease: false
|
91
|
-
version_requirements: *
|
91
|
+
version_requirements: *2153658420
|
92
92
|
- !ruby/object:Gem::Dependency
|
93
93
|
name: vcr
|
94
|
-
requirement: &
|
94
|
+
requirement: &2153657960 !ruby/object:Gem::Requirement
|
95
95
|
none: false
|
96
96
|
requirements:
|
97
97
|
- - ~>
|
@@ -99,10 +99,10 @@ dependencies:
|
|
99
99
|
version: 1.10.3
|
100
100
|
type: :development
|
101
101
|
prerelease: false
|
102
|
-
version_requirements: *
|
102
|
+
version_requirements: *2153657960
|
103
103
|
- !ruby/object:Gem::Dependency
|
104
104
|
name: webmock
|
105
|
-
requirement: &
|
105
|
+
requirement: &2153657500 !ruby/object:Gem::Requirement
|
106
106
|
none: false
|
107
107
|
requirements:
|
108
108
|
- - ~>
|
@@ -110,10 +110,10 @@ dependencies:
|
|
110
110
|
version: 1.6.4
|
111
111
|
type: :development
|
112
112
|
prerelease: false
|
113
|
-
version_requirements: *
|
113
|
+
version_requirements: *2153657500
|
114
114
|
- !ruby/object:Gem::Dependency
|
115
115
|
name: rspec
|
116
|
-
requirement: &
|
116
|
+
requirement: &2153657040 !ruby/object:Gem::Requirement
|
117
117
|
none: false
|
118
118
|
requirements:
|
119
119
|
- - ~>
|
@@ -121,10 +121,10 @@ dependencies:
|
|
121
121
|
version: 2.6.0
|
122
122
|
type: :development
|
123
123
|
prerelease: false
|
124
|
-
version_requirements: *
|
124
|
+
version_requirements: *2153657040
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: fuubar
|
127
|
-
requirement: &
|
127
|
+
requirement: &2153656580 !ruby/object:Gem::Requirement
|
128
128
|
none: false
|
129
129
|
requirements:
|
130
130
|
- - ~>
|
@@ -132,7 +132,7 @@ dependencies:
|
|
132
132
|
version: 0.0.5
|
133
133
|
type: :development
|
134
134
|
prerelease: false
|
135
|
-
version_requirements: *
|
135
|
+
version_requirements: *2153656580
|
136
136
|
description: Amazon Simple INterface.
|
137
137
|
email:
|
138
138
|
- phoetmail@googlemail.com
|
@@ -150,7 +150,6 @@ files:
|
|
150
150
|
- README.rdoc
|
151
151
|
- asin.gemspec
|
152
152
|
- cassettes/add_items1430216263.yml
|
153
|
-
- cassettes/bad_configuration.yml
|
154
153
|
- cassettes/browse_node_599826.yml
|
155
154
|
- cassettes/clear_cart.yml
|
156
155
|
- cassettes/create_cart_with_asin_1430218150_and_other_asin_1430216263.yml
|
@@ -1,29 +0,0 @@
|
|
1
|
-
---
|
2
|
-
- !ruby/struct:VCR::HTTPInteraction
|
3
|
-
request: !ruby/struct:VCR::Request
|
4
|
-
method: :get
|
5
|
-
uri: http://webservices.amazon.com:80/onca/xml?AWSAccessKeyId=&ItemId=bla&Operation=ItemLookup&ResponseGroup=Medium&Service=AWSECommerceService&Signature=MXy86F4AyavpzBqeo2e4LHZRzhlBxe/3XS7zXcp0wTQ=&Timestamp=2011-08-02T14:48:00Z&Version=2010-11-01
|
6
|
-
body: !!null
|
7
|
-
headers: !!null
|
8
|
-
response: !ruby/struct:VCR::Response
|
9
|
-
status: !ruby/struct:VCR::ResponseStatus
|
10
|
-
code: 403
|
11
|
-
message: Forbidden
|
12
|
-
headers:
|
13
|
-
date:
|
14
|
-
- Tue, 02 Aug 2011 14:49:25 GMT
|
15
|
-
server:
|
16
|
-
- Server
|
17
|
-
vary:
|
18
|
-
- Accept-Encoding,User-Agent
|
19
|
-
cneonction:
|
20
|
-
- close
|
21
|
-
transfer-encoding:
|
22
|
-
- chunked
|
23
|
-
content-type:
|
24
|
-
- text/plain
|
25
|
-
body: ! '<?xml version="1.0"?>
|
26
|
-
|
27
|
-
<ItemLookupErrorResponse xmlns="http://ecs.amazonaws.com/doc/2010-11-01/"><Error><Code>MissingClientTokenId</Code><Message>Request
|
28
|
-
must contain AWSAccessKeyId or X.509 certificate.</Message></Error><RequestID>a0fca4f4-04b1-489c-a021-0737753cfcab</RequestID></ItemLookupErrorResponse>'
|
29
|
-
http_version: '1.1'
|