vacuum 0.4.1 → 0.5.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 +4 -4
- data/README.md +26 -35
- data/lib/vacuum/request.rb +28 -20
- data/lib/vacuum/response.rb +10 -0
- data/lib/vacuum/version.rb +1 -1
- data/lib/vacuum.rb +1 -2
- data/test/test_vacuum.rb +29 -0
- metadata +20 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d688557c2a30832e793deb6f932f78e38f3fe2eb
|
|
4
|
+
data.tar.gz: 762f70ee270015de03c5ba177724bcea03fcac9f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4f4d7fc84ef456bbdc31b6ce81169eb9799ce79c1112ec0a1e9e35cbf6a619dceadda25e4386458b0ecdddec8bd1179216d98dc6451a8de5a511c717bdbfc5ea
|
|
7
|
+
data.tar.gz: c353c71626477896d12385b58c47049cdcdce226bd114c961904a3e3520fc2fcefac383527a3f5b9cc3b52ef5ff0f6abd26042a642c3ea629f688e849be9b0c0
|
data/README.md
CHANGED
|
@@ -12,59 +12,50 @@ Set up a request:
|
|
|
12
12
|
|
|
13
13
|
```ruby
|
|
14
14
|
req = Vacuum.new
|
|
15
|
-
.configure(
|
|
16
|
-
aws_access_key_id: 'foo',
|
|
17
|
-
aws_secret_access_key: 'secret',
|
|
18
|
-
associate_tag: 'biz-val'
|
|
19
|
-
)
|
|
20
15
|
```
|
|
21
16
|
|
|
22
|
-
The locale defaults to the US. If you wish to use another locale,
|
|
23
|
-
ISO-3166 two-letter code
|
|
17
|
+
The locale defaults to the US. If you wish to use another locale, instantiate
|
|
18
|
+
with its ISO-3166 two-letter country code:
|
|
24
19
|
|
|
25
20
|
```ruby
|
|
26
|
-
Vacuum.new('GB')
|
|
21
|
+
req = Vacuum.new('GB')
|
|
27
22
|
```
|
|
28
23
|
|
|
29
|
-
|
|
24
|
+
Configure the request credentials:
|
|
30
25
|
|
|
31
26
|
```ruby
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
27
|
+
req.configure(
|
|
28
|
+
aws_access_key_id: 'key',
|
|
29
|
+
aws_secret_access_key: 'secret',
|
|
30
|
+
associate_tag: 'tag'
|
|
31
|
+
)
|
|
37
32
|
```
|
|
38
33
|
|
|
39
|
-
|
|
40
|
-
method.
|
|
41
|
-
|
|
42
|
-
If you don't mind the performance hit, here is a simplistic solution based on
|
|
43
|
-
[`MultiXml`][5]:
|
|
34
|
+
Make a request:
|
|
44
35
|
|
|
45
36
|
```ruby
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
37
|
+
params = {
|
|
38
|
+
'SearchIndex' => 'Books',
|
|
39
|
+
'Keywords' => 'Architecture'
|
|
40
|
+
}
|
|
41
|
+
res = req.item_search(params)
|
|
42
|
+
```
|
|
51
43
|
|
|
52
|
-
|
|
44
|
+
Parse the response into a Ruby hash:
|
|
53
45
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
46
|
+
```ruby
|
|
47
|
+
res.to_h
|
|
48
|
+
```
|
|
57
49
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
end
|
|
50
|
+
Allowed requests include `browse_node_lookup`, `cart_add`, `cart_clear`,
|
|
51
|
+
`cart_create`, `cart_get`, `cart_modify`, `item_lookup`, `item_search`,
|
|
52
|
+
`similarity_lookup`.
|
|
62
53
|
|
|
63
|
-
|
|
64
|
-
```
|
|
54
|
+
Vacuum is built with [excon][5] and [multi_xml][6].
|
|
65
55
|
|
|
66
56
|
[1]: https://secure.travis-ci.org/hakanensari/vacuum.png
|
|
67
57
|
[2]: http://travis-ci.org/hakanensari/vacuum
|
|
68
58
|
[3]: http://f.cl.ly/items/2k2X0e2u0G3k1c260D2u/vacuum.png
|
|
69
59
|
[4]: https://affiliate-program.amazon.com/gp/advertising/api/detail/main.html
|
|
70
|
-
[5]: https://github.com/
|
|
60
|
+
[5]: https://github.com/geemus/excon
|
|
61
|
+
[6]: https://github.com/sferik/multi_xml
|
data/lib/vacuum/request.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'jeff'
|
|
2
|
+
require 'vacuum/response'
|
|
2
3
|
|
|
3
4
|
module Vacuum
|
|
4
5
|
# An Amazon Product Advertising API request.
|
|
@@ -7,7 +8,6 @@ module Vacuum
|
|
|
7
8
|
|
|
8
9
|
BadLocale = Class.new(ArgumentError)
|
|
9
10
|
|
|
10
|
-
# A list of Amazon Product Advertising API hosts.
|
|
11
11
|
HOSTS = {
|
|
12
12
|
'CA' => 'webservices.amazon.ca',
|
|
13
13
|
'CN' => 'webservices.amazon.cn',
|
|
@@ -21,23 +21,34 @@ module Vacuum
|
|
|
21
21
|
'US' => 'webservices.amazon.com'
|
|
22
22
|
}.freeze
|
|
23
23
|
|
|
24
|
+
OPERATIONS = %w(
|
|
25
|
+
BrowseNodeLookup
|
|
26
|
+
CartAdd
|
|
27
|
+
CartClear
|
|
28
|
+
CartCreate
|
|
29
|
+
CartGet
|
|
30
|
+
CartModify
|
|
31
|
+
ItemLookup
|
|
32
|
+
ItemSearch
|
|
33
|
+
SimilarityLookup
|
|
34
|
+
).freeze
|
|
35
|
+
|
|
24
36
|
params 'AssociateTag' => -> { associate_tag },
|
|
25
37
|
'Service' => 'AWSECommerceService',
|
|
26
38
|
'Version' => '2011-08-01'
|
|
27
39
|
|
|
40
|
+
attr_accessor :associate_tag
|
|
41
|
+
|
|
28
42
|
# Create a new request for given locale.
|
|
29
43
|
#
|
|
30
44
|
# locale - The String Product Advertising API locale (default: US).
|
|
45
|
+
# secure - Whether to use the secure version of the endpoint (default:
|
|
46
|
+
# false)
|
|
31
47
|
#
|
|
32
48
|
# Raises a Bad Locale error if locale is not valid.
|
|
33
|
-
def initialize(locale = nil)
|
|
34
|
-
if locale == 'UK'
|
|
35
|
-
warn '[DEPRECATION] Use GB instead of UK'
|
|
36
|
-
locale = 'GB'
|
|
37
|
-
end
|
|
38
|
-
|
|
49
|
+
def initialize(locale = nil, secure = false)
|
|
39
50
|
host = HOSTS[locale || 'US'] or raise BadLocale
|
|
40
|
-
self.aws_endpoint = "http://#{host}/onca/xml"
|
|
51
|
+
self.aws_endpoint = "#{secure ? 'https' : 'http' }://#{host}/onca/xml"
|
|
41
52
|
end
|
|
42
53
|
|
|
43
54
|
# Configure the Amazon Product Advertising API request.
|
|
@@ -54,24 +65,21 @@ module Vacuum
|
|
|
54
65
|
self
|
|
55
66
|
end
|
|
56
67
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
68
|
+
OPERATIONS.each do |operation|
|
|
69
|
+
method_name = operation.gsub(/(.)([A-Z])/,'\1_\2').downcase
|
|
70
|
+
define_method(method_name) do |params, excon_options = {}|
|
|
71
|
+
Response.new(get(excon_options.merge(query: params.merge('Operation' => operation))))
|
|
72
|
+
end
|
|
73
|
+
end
|
|
62
74
|
|
|
63
75
|
# Build a URL.
|
|
64
76
|
#
|
|
65
|
-
# params - A Hash of Amazon Product Advertising
|
|
77
|
+
# params - A Hash of Amazon Product Advertising request parameters.
|
|
66
78
|
#
|
|
67
79
|
# Returns the built URL String.
|
|
68
80
|
def url(params)
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
query: params
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
[aws_endpoint, build_options(opts).fetch(:query)].join('?')
|
|
81
|
+
options = { method: :get, query: params }
|
|
82
|
+
[aws_endpoint, build_options(options).fetch(:query)].join('?')
|
|
75
83
|
end
|
|
76
84
|
end
|
|
77
85
|
end
|
data/lib/vacuum/version.rb
CHANGED
data/lib/vacuum.rb
CHANGED
data/test/test_vacuum.rb
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require 'minitest/autorun'
|
|
2
|
+
require_relative '../lib/vacuum'
|
|
3
|
+
|
|
4
|
+
class TestVacuum < Minitest::Test
|
|
5
|
+
include Vacuum
|
|
6
|
+
|
|
7
|
+
def test_request_valid_locale
|
|
8
|
+
assert_raises(Request::BadLocale) { Request.new('foo') }
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def test_defaults_to_us_endpoint
|
|
12
|
+
assert_equal 'http://webservices.amazon.com/onca/xml', Request.new.aws_endpoint
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_returns_url
|
|
16
|
+
req = Request.new
|
|
17
|
+
req.configure(aws_access_key_id: 'key', aws_secret_access_key: 'secret', associate_tag: 'tag')
|
|
18
|
+
assert_match(/webservices.amazon.com.*Foo=Bar/, req.url('Foo' => 'Bar'))
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def test_fetches_parsable_response
|
|
22
|
+
Excon.stub({}, { body: '<foo>bar</foo>' })
|
|
23
|
+
req = Request.new
|
|
24
|
+
req.configure(aws_access_key_id: 'key', aws_secret_access_key: 'secret', associate_tag: 'tag')
|
|
25
|
+
res = req.item_lookup({}, mock: true)
|
|
26
|
+
refute_empty res.to_h
|
|
27
|
+
Excon.stubs.clear
|
|
28
|
+
end
|
|
29
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: vacuum
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Hakan Ensari
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2013-
|
|
11
|
+
date: 2013-11-11 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: jeff
|
|
@@ -24,6 +24,20 @@ dependencies:
|
|
|
24
24
|
- - ~>
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
26
|
version: 0.7.0
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: multi_xml
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ~>
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: 0.5.0
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ~>
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: 0.5.0
|
|
27
41
|
- !ruby/object:Gem::Dependency
|
|
28
42
|
name: rake
|
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -46,10 +60,12 @@ extensions: []
|
|
|
46
60
|
extra_rdoc_files: []
|
|
47
61
|
files:
|
|
48
62
|
- lib/vacuum/request.rb
|
|
63
|
+
- lib/vacuum/response.rb
|
|
49
64
|
- lib/vacuum/version.rb
|
|
50
65
|
- lib/vacuum.rb
|
|
51
66
|
- LICENSE
|
|
52
67
|
- README.md
|
|
68
|
+
- test/test_vacuum.rb
|
|
53
69
|
homepage: https://github.com/hakanensari/vacuum
|
|
54
70
|
licenses:
|
|
55
71
|
- MIT
|
|
@@ -74,4 +90,5 @@ rubygems_version: 2.0.3
|
|
|
74
90
|
signing_key:
|
|
75
91
|
specification_version: 4
|
|
76
92
|
summary: Amazon Product Advertising in Ruby
|
|
77
|
-
test_files:
|
|
93
|
+
test_files:
|
|
94
|
+
- test/test_vacuum.rb
|