vacuum 2.2.0 → 3.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +96 -128
- data/lib/vacuum.rb +8 -2
- data/lib/vacuum/locale.rb +64 -0
- data/lib/vacuum/matcher.rb +71 -0
- data/lib/vacuum/operation.rb +75 -0
- data/lib/vacuum/request.rb +165 -98
- data/lib/vacuum/resource.rb +62 -0
- data/lib/vacuum/response.rb +21 -9
- data/lib/vacuum/version.rb +1 -1
- data/test/cassettes/vacuum.yml +1904 -765
- data/test/helper.rb +10 -0
- data/test/integration/test_requests.rb +62 -0
- data/test/integration_helper.rb +51 -0
- data/test/locales.rb +23 -0
- data/test/locales.yml +28 -0
- data/test/locales.yml.example +28 -0
- data/test/unit/test_locale.rb +43 -0
- data/test/unit/test_operation.rb +31 -0
- data/test/unit/test_request.rb +61 -0
- data/test/unit/test_resource.rb +12 -0
- data/test/unit/test_response.rb +26 -0
- metadata +58 -20
- data/test/test_integration.rb +0 -69
- data/test/test_unit.rb +0 -106
data/test/test_integration.rb
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'minitest/autorun'
|
4
|
-
require 'vcr'
|
5
|
-
require_relative '../lib/vacuum'
|
6
|
-
|
7
|
-
ENV['AWS_ACCESS_KEY_ID'] ||= 'key'
|
8
|
-
ENV['AWS_SECRET_ACCESS_KEY'] ||= 'secret'
|
9
|
-
|
10
|
-
VCR.configure do |c|
|
11
|
-
c.hook_into :excon
|
12
|
-
c.cassette_library_dir = 'test/cassettes'
|
13
|
-
c.default_cassette_options = {
|
14
|
-
match_requests_on: [VCR.request_matchers.uri_without_param(
|
15
|
-
'AWSAccessKeyId', 'AssociateTag', 'Signature', 'Timestamp', 'Version'
|
16
|
-
)],
|
17
|
-
record: :new_episodes
|
18
|
-
}
|
19
|
-
end
|
20
|
-
|
21
|
-
class TestIntegration < Minitest::Test
|
22
|
-
include Vacuum
|
23
|
-
|
24
|
-
def setup
|
25
|
-
VCR.insert_cassette('vacuum')
|
26
|
-
end
|
27
|
-
|
28
|
-
def teardown
|
29
|
-
VCR.eject_cassette
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_happy_path
|
33
|
-
req = Vacuum.new
|
34
|
-
req.associate_tag = 'foo'
|
35
|
-
params = { 'SearchIndex' => 'All', 'Keywords' => 'vacuum' }
|
36
|
-
res = req.item_search(query: params)
|
37
|
-
assert res.dig('ItemSearchResponse', 'Items', 'Item')
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_encoding_issues
|
41
|
-
params = { 'SearchIndex' => 'All', 'Keywords' => 'google' }
|
42
|
-
titles = locales.flat_map do |locale|
|
43
|
-
req = Vacuum.new(locale)
|
44
|
-
req.associate_tag = 'foo'
|
45
|
-
res = req.item_search(query: params)
|
46
|
-
items = res.dig('ItemSearchResponse', 'Items', 'Item') || []
|
47
|
-
items.map { |item| item['ItemAttributes']['Title'] }
|
48
|
-
end
|
49
|
-
encodings = titles.map { |t| t.encoding.name }.uniq
|
50
|
-
|
51
|
-
# Newer JRuby now appears to return both US-ASCII and UTF-8, depending on
|
52
|
-
# whether the string has non-ASCII characters. MRI will only return latter.
|
53
|
-
assert(encodings.any? { |encoding| encoding == 'UTF-8' })
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_unauthorized_errors
|
57
|
-
req = Vacuum.new
|
58
|
-
req.associate_tag = 'foo'
|
59
|
-
params = { 'SearchIndex' => 'All', 'Keywords' => 'amazon' }
|
60
|
-
res = req.item_search(query: params)
|
61
|
-
assert_equal 'InvalidClientTokenId', res.dig('ItemSearchErrorResponse', 'Error', 'Code')
|
62
|
-
end
|
63
|
-
|
64
|
-
private
|
65
|
-
|
66
|
-
def locales
|
67
|
-
Request::HOSTS.keys
|
68
|
-
end
|
69
|
-
end
|
data/test/test_unit.rb
DELETED
@@ -1,106 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'minitest/autorun'
|
4
|
-
require_relative '../lib/vacuum'
|
5
|
-
|
6
|
-
class TestVacuum < Minitest::Test
|
7
|
-
include Vacuum
|
8
|
-
|
9
|
-
def setup
|
10
|
-
@req = Request.new
|
11
|
-
end
|
12
|
-
|
13
|
-
def teardown
|
14
|
-
Excon.stubs.clear
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_requires_valid_locale
|
18
|
-
assert_raises(Request::BadLocale) { Request.new('foo') }
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_defaults_to_us_endpoint
|
22
|
-
assert_equal 'http://webservices.amazon.com/onca/xml', @req.aws_endpoint
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_defaults_to_latest_api_version
|
26
|
-
assert_equal Request::LATEST_VERSION, @req.version
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_accepts_uk_as_locale
|
30
|
-
Request.new('UK')
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_accepts_mx_as_locale
|
34
|
-
Request.new('MX')
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_fetches_parsable_response
|
38
|
-
Excon.stub({}, body: '<foo/>')
|
39
|
-
res = @req.item_lookup({}, mock: true)
|
40
|
-
refute_empty res.parse
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_alternative_query_syntax
|
44
|
-
Excon.stub({}, body: '<foo/>')
|
45
|
-
res = @req.item_lookup(query: {}, mock: true)
|
46
|
-
refute_empty res.parse
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_force_encodes_body
|
50
|
-
res = Object.new
|
51
|
-
def res.body
|
52
|
-
(+'').force_encoding(Encoding::ASCII_8BIT)
|
53
|
-
end
|
54
|
-
assert_equal 'UTF-8', Response.new(res).body.encoding.name
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_sets_custom_parser_on_class_level
|
58
|
-
original_parser = Response.parser
|
59
|
-
Excon.stub({}, body: '<foo/>')
|
60
|
-
parser = MiniTest::Mock.new
|
61
|
-
parser.expect(:parse, '123', ['<foo/>'])
|
62
|
-
Response.parser = parser
|
63
|
-
res = @req.item_lookup(query: {}, mock: true)
|
64
|
-
assert_equal '123', res.parse
|
65
|
-
Response.parser = original_parser # clean up
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_sets_custom_parser_on_instance_level
|
69
|
-
Excon.stub({}, body: '<foo/>')
|
70
|
-
res = @req.item_lookup(query: {}, mock: true)
|
71
|
-
parser = MiniTest::Mock.new
|
72
|
-
parser.expect(:parse, '123', ['<foo/>'])
|
73
|
-
res.parser = parser
|
74
|
-
assert_equal '123', res.parse
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_casts_to_hash
|
78
|
-
Excon.stub({}, body: '<foo/>')
|
79
|
-
parser = MiniTest::Mock.new
|
80
|
-
res = @req.item_lookup(query: {}, mock: true)
|
81
|
-
assert_kind_of Hash, res.to_h
|
82
|
-
res.parser = parser
|
83
|
-
assert_kind_of Hash, res.to_h
|
84
|
-
end
|
85
|
-
|
86
|
-
def test_digs
|
87
|
-
Excon.stub({}, body: '<foo><bar>baz</bar></foo>')
|
88
|
-
parser = MiniTest::Mock.new
|
89
|
-
res = @req.item_lookup(query: {}, mock: true)
|
90
|
-
assert_equal 'baz', res.dig('foo', 'bar')
|
91
|
-
res.parser = parser
|
92
|
-
assert_equal 'baz', res.dig('foo', 'bar')
|
93
|
-
end
|
94
|
-
|
95
|
-
def test_handles_authorisation_errors
|
96
|
-
Excon.stub({}, status: 400)
|
97
|
-
res = @req.item_lookup(query: {}, mock: true)
|
98
|
-
assert_equal 400, res.status
|
99
|
-
assert_raises Excon::Error::BadRequest do
|
100
|
-
@req.item_lookup(query: {}, expects: 200, mock: true)
|
101
|
-
end
|
102
|
-
Excon.stub({}, status: 403)
|
103
|
-
res = @req.item_lookup(query: {}, mock: true)
|
104
|
-
assert_equal 403, res.status
|
105
|
-
end
|
106
|
-
end
|