vacuum 3.0.0 → 3.4.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.
- checksums.yaml +4 -4
- data/README.md +65 -24
- data/lib/vacuum.rb +5 -0
- data/lib/vacuum/locale.rb +50 -39
- data/lib/vacuum/matcher.rb +34 -1
- data/lib/vacuum/operation.rb +75 -0
- data/lib/vacuum/request.rb +59 -73
- data/lib/vacuum/response.rb +27 -4
- data/lib/vacuum/version.rb +1 -1
- data/test/cassettes/vacuum.yml +834 -253
- data/test/helper.rb +10 -0
- data/test/integration/test_requests.rb +105 -0
- data/test/integration_helper.rb +2 -4
- data/test/locales.yml.example +8 -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/{vacuum → unit}/test_response.rb +5 -1
- metadata +41 -20
- data/test/locales.yml +0 -28
- data/test/vacuum/test_locale.rb +0 -35
- data/test/vacuum/test_request.rb +0 -44
data/test/helper.rb
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'integration_helper'
|
4
|
+
|
5
|
+
module Vacuum
|
6
|
+
class TestRequests < IntegrationTest
|
7
|
+
def test_get_browse_nodes
|
8
|
+
requests.each do |request|
|
9
|
+
response = request.get_browse_nodes(browse_node_ids: ['3045'])
|
10
|
+
assert_equal 200, response.status
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_get_items
|
15
|
+
requests.each do |request|
|
16
|
+
response = request.get_items(item_ids: ['B07212L4G2'])
|
17
|
+
assert_equal 200, response.status
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
RESOURCE_ALL = %w[BrowseNodeInfo.BrowseNodes
|
22
|
+
BrowseNodeInfo.BrowseNodes.Ancestor
|
23
|
+
BrowseNodeInfo.BrowseNodes.SalesRank
|
24
|
+
BrowseNodeInfo.WebsiteSalesRank
|
25
|
+
Images.Primary.Small
|
26
|
+
Images.Primary.Medium
|
27
|
+
Images.Primary.Large
|
28
|
+
Images.Variants.Small
|
29
|
+
Images.Variants.Medium
|
30
|
+
Images.Variants.Large
|
31
|
+
ItemInfo.ByLineInfo
|
32
|
+
ItemInfo.Classifications
|
33
|
+
ItemInfo.ContentInfo
|
34
|
+
ItemInfo.ContentRating
|
35
|
+
ItemInfo.ExternalIds
|
36
|
+
ItemInfo.Features
|
37
|
+
ItemInfo.ManufactureInfo
|
38
|
+
ItemInfo.ProductInfo
|
39
|
+
ItemInfo.TechnicalInfo
|
40
|
+
ItemInfo.Title
|
41
|
+
ItemInfo.TradeInInfo
|
42
|
+
Offers.Listings.Availability.MaxOrderQuantity
|
43
|
+
Offers.Listings.Availability.Message
|
44
|
+
Offers.Listings.Availability.MinOrderQuantity
|
45
|
+
Offers.Listings.Availability.Type
|
46
|
+
Offers.Listings.Condition
|
47
|
+
Offers.Listings.Condition.SubCondition
|
48
|
+
Offers.Listings.DeliveryInfo.IsAmazonFulfilled
|
49
|
+
Offers.Listings.DeliveryInfo.IsFreeShippingEligible
|
50
|
+
Offers.Listings.DeliveryInfo.IsPrimeEligible
|
51
|
+
Offers.Listings.IsBuyBoxWinner
|
52
|
+
Offers.Listings.LoyaltyPoints.Points
|
53
|
+
Offers.Listings.MerchantInfo
|
54
|
+
Offers.Listings.Price
|
55
|
+
Offers.Listings.ProgramEligibility.IsPrimeExclusive
|
56
|
+
Offers.Listings.ProgramEligibility.IsPrimePantry
|
57
|
+
Offers.Listings.Promotions
|
58
|
+
Offers.Listings.SavingBasis
|
59
|
+
Offers.Summaries.HighestPrice
|
60
|
+
Offers.Summaries.LowestPrice
|
61
|
+
Offers.Summaries.OfferCount
|
62
|
+
ParentASIN].freeze
|
63
|
+
|
64
|
+
def test_get_items_with_all_resources
|
65
|
+
requests.each do |request|
|
66
|
+
response = request.get_items(item_ids: 'B07212L4G2',
|
67
|
+
resources: RESOURCE_ALL)
|
68
|
+
assert_equal 200, response.status
|
69
|
+
item = response.dig('ItemsResult', 'Items').first
|
70
|
+
assert item.key?('BrowseNodeInfo')
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_get_variations
|
75
|
+
requests.each do |request|
|
76
|
+
response = request.get_variations(asin: 'B07212L4G2')
|
77
|
+
assert_equal 200, response.status
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_search_items
|
82
|
+
requests.each do |request|
|
83
|
+
response = request.search_items(keywords: 'Harry Potter')
|
84
|
+
assert_equal 200, response.status
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_persistent
|
89
|
+
request = requests.sample
|
90
|
+
refute request.client.persistent?
|
91
|
+
request.persistent
|
92
|
+
assert request.client.persistent?
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_logging
|
96
|
+
require 'logger'
|
97
|
+
logdev = StringIO.new
|
98
|
+
logger = Logger.new(logdev)
|
99
|
+
request = requests.sample
|
100
|
+
request.use(logging: { logger: logger })
|
101
|
+
request.search_items(keywords: 'Harry Potter')
|
102
|
+
refute_empty logdev.string
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
data/test/integration_helper.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'helper'
|
4
4
|
require 'vcr'
|
5
5
|
|
6
6
|
require 'locales'
|
@@ -27,8 +27,6 @@ VCR.configure do |c|
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
HTTPI.log = false
|
31
|
-
|
32
30
|
module Vacuum
|
33
31
|
class IntegrationTest < Minitest::Test
|
34
32
|
def setup
|
@@ -47,7 +45,7 @@ module Vacuum
|
|
47
45
|
private
|
48
46
|
|
49
47
|
def requests
|
50
|
-
Locales.map { |credentials| Vacuum.new(credentials) }.shuffle
|
48
|
+
Locales.map { |credentials| Vacuum.new(**credentials) }.shuffle
|
51
49
|
end
|
52
50
|
end
|
53
51
|
end
|
data/test/locales.yml.example
CHANGED
@@ -10,6 +10,14 @@
|
|
10
10
|
:access_key: access_key
|
11
11
|
:secret_key: secret_key
|
12
12
|
:partner_tag: partner_tag
|
13
|
+
- :marketplace: FR
|
14
|
+
:access_key: access_key
|
15
|
+
:secret_key: secret_key
|
16
|
+
:partner_tag: partner_tag
|
17
|
+
- :marketplace: IT
|
18
|
+
:access_key: access_key
|
19
|
+
:secret_key: secret_key
|
20
|
+
:partner_tag: partner_tag
|
13
21
|
- :marketplace: GB
|
14
22
|
:access_key: access_key
|
15
23
|
:secret_key: secret_key
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'helper'
|
4
|
+
require 'vacuum/locale'
|
5
|
+
|
6
|
+
module Vacuum
|
7
|
+
class TestLocale < Minitest::Test
|
8
|
+
def test_host
|
9
|
+
locale = Locale.new(:us, **credentials)
|
10
|
+
assert locale.host
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_region
|
14
|
+
locale = Locale.new(:us, **credentials)
|
15
|
+
assert locale.region
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_partner_type_default
|
19
|
+
locale = Locale.new(:us, **credentials)
|
20
|
+
assert locale.partner_type
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_upcased_marketplace
|
24
|
+
Locale.new('US', **credentials) # does not raise
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_uk
|
28
|
+
Locale.new(:uk, **credentials) # does not raise
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_not_found
|
32
|
+
assert_raises Locale::NotFound do
|
33
|
+
Locale.new(:foo, **credentials)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def credentials
|
40
|
+
{ access_key: '123', secret_key: '123', partner_tag: 'xyz-20' }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'helper'
|
4
|
+
require 'vacuum/locale'
|
5
|
+
require 'vacuum/operation'
|
6
|
+
|
7
|
+
module Vacuum
|
8
|
+
class TestOperation < Minitest::Test
|
9
|
+
def setup
|
10
|
+
@operation = Operation.new('Action', params: { foo: 1 }, locale: locale)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_body
|
14
|
+
assert @operation.body
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_url
|
18
|
+
assert @operation.url
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_headers
|
22
|
+
assert @operation.headers
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def locale
|
28
|
+
Locale.new(:us, access_key: '123', secret_key: '123', partner_tag: 'xyz')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'helper'
|
4
|
+
require 'vacuum/request'
|
5
|
+
|
6
|
+
module Vacuum
|
7
|
+
class TestRequest < Minitest::Test
|
8
|
+
def test_search_keywords
|
9
|
+
err = assert_raises(ArgumentError) do
|
10
|
+
api.search_items(keywords: ['Harry Potter'])
|
11
|
+
end
|
12
|
+
|
13
|
+
assert_equal ':keyword argument expects a String', err.message
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_search_resources
|
17
|
+
err = assert_raises(ArgumentError) do
|
18
|
+
api.search_items(
|
19
|
+
keywords: 'Harry Potter',
|
20
|
+
resources: %w[Images.Primary.Large ItemInfo.ExternalIds Offer.Listings.Price]
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
assert_equal 'There is not such resource: Offer.Listings.Price', err.message
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_get_items_wrong_resource
|
28
|
+
err = assert_raises(ArgumentError) do
|
29
|
+
api.get_items(
|
30
|
+
item_ids: :B07212L4G2,
|
31
|
+
resources: %w[BrowseNodeInfo.BrowseNode.SalesRank]
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
assert_equal 'There is not such resource: BrowseNodeInfo.BrowseNode.SalesRank', err.message
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_get_variations_wrong_resource
|
39
|
+
err = assert_raises(ArgumentError) do
|
40
|
+
api.get_variations(asin: 'B07212L4G2', resources: %w[BrowseNodeInfo.BrowseNode.SalesRank])
|
41
|
+
end
|
42
|
+
|
43
|
+
assert_equal 'There is not such resource: BrowseNodeInfo.BrowseNode.SalesRank', err.message
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_resource_not_array
|
47
|
+
err = assert_raises(ArgumentError) do
|
48
|
+
api.get_items(item_ids: :B07212L4G2, resources: 'foo')
|
49
|
+
end
|
50
|
+
|
51
|
+
assert_equal ':resources argument expects an Array', err.message
|
52
|
+
end
|
53
|
+
|
54
|
+
def api
|
55
|
+
@api ||= Vacuum::Request.new(marketplace: 'US',
|
56
|
+
access_key: 'key',
|
57
|
+
secret_key: 'secret',
|
58
|
+
partner_tag: 'tag')
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'helper'
|
4
4
|
require 'vacuum/response'
|
5
5
|
|
6
6
|
module Vacuum
|
@@ -11,6 +11,10 @@ module Vacuum
|
|
11
11
|
@response = Response.new(mock)
|
12
12
|
end
|
13
13
|
|
14
|
+
def test_parse
|
15
|
+
assert @response.parse
|
16
|
+
end
|
17
|
+
|
14
18
|
def test_cast_to_hash
|
15
19
|
assert_kind_of Hash, @response.to_h
|
16
20
|
end
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vacuum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hakan Ensari
|
8
|
-
|
8
|
+
- Stanislav Katkov
|
9
|
+
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2020-10-07 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: aws-sigv4
|
@@ -25,19 +26,19 @@ dependencies:
|
|
25
26
|
- !ruby/object:Gem::Version
|
26
27
|
version: '1.0'
|
27
28
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
29
|
+
name: http
|
29
30
|
requirement: !ruby/object:Gem::Requirement
|
30
31
|
requirements:
|
31
32
|
- - "~>"
|
32
33
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
34
|
+
version: '4.0'
|
34
35
|
type: :runtime
|
35
36
|
prerelease: false
|
36
37
|
version_requirements: !ruby/object:Gem::Requirement
|
37
38
|
requirements:
|
38
39
|
- - "~>"
|
39
40
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
41
|
+
version: '4.0'
|
41
42
|
- !ruby/object:Gem::Dependency
|
42
43
|
name: minitest
|
43
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,6 +81,20 @@ dependencies:
|
|
80
81
|
- - ">="
|
81
82
|
- !ruby/object:Gem::Version
|
82
83
|
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: simplecov
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - '='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 0.17.1
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - '='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: 0.17.1
|
83
98
|
- !ruby/object:Gem::Dependency
|
84
99
|
name: vcr
|
85
100
|
requirement: !ruby/object:Gem::Requirement
|
@@ -125,6 +140,7 @@ dependencies:
|
|
125
140
|
description: A wrapper to the Amazon Product Advertising API
|
126
141
|
email:
|
127
142
|
- me@hakanensari.com
|
143
|
+
- sk@skylup.com
|
128
144
|
executables: []
|
129
145
|
extensions: []
|
130
146
|
extra_rdoc_files: []
|
@@ -134,22 +150,25 @@ files:
|
|
134
150
|
- lib/vacuum.rb
|
135
151
|
- lib/vacuum/locale.rb
|
136
152
|
- lib/vacuum/matcher.rb
|
153
|
+
- lib/vacuum/operation.rb
|
137
154
|
- lib/vacuum/request.rb
|
138
155
|
- lib/vacuum/response.rb
|
139
156
|
- lib/vacuum/version.rb
|
140
157
|
- test/cassettes/vacuum.yml
|
158
|
+
- test/helper.rb
|
159
|
+
- test/integration/test_requests.rb
|
141
160
|
- test/integration_helper.rb
|
142
161
|
- test/locales.rb
|
143
|
-
- test/locales.yml
|
144
162
|
- test/locales.yml.example
|
145
|
-
- test/
|
146
|
-
- test/
|
147
|
-
- test/
|
163
|
+
- test/unit/test_locale.rb
|
164
|
+
- test/unit/test_operation.rb
|
165
|
+
- test/unit/test_request.rb
|
166
|
+
- test/unit/test_response.rb
|
148
167
|
homepage: https://github.com/hakanensari/vacuum
|
149
168
|
licenses:
|
150
169
|
- MIT
|
151
170
|
metadata: {}
|
152
|
-
post_install_message:
|
171
|
+
post_install_message:
|
153
172
|
rdoc_options: []
|
154
173
|
require_paths:
|
155
174
|
- lib
|
@@ -157,23 +176,25 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
157
176
|
requirements:
|
158
177
|
- - ">="
|
159
178
|
- !ruby/object:Gem::Version
|
160
|
-
version: '2.
|
179
|
+
version: '2.5'
|
161
180
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
162
181
|
requirements:
|
163
182
|
- - ">="
|
164
183
|
- !ruby/object:Gem::Version
|
165
184
|
version: '0'
|
166
185
|
requirements: []
|
167
|
-
rubygems_version: 3.
|
168
|
-
signing_key:
|
186
|
+
rubygems_version: 3.1.2
|
187
|
+
signing_key:
|
169
188
|
specification_version: 4
|
170
189
|
summary: Amazon Product Advertising in Ruby
|
171
190
|
test_files:
|
172
|
-
- test/
|
173
|
-
- test/
|
174
|
-
- test/
|
191
|
+
- test/unit/test_operation.rb
|
192
|
+
- test/unit/test_request.rb
|
193
|
+
- test/unit/test_locale.rb
|
194
|
+
- test/unit/test_response.rb
|
195
|
+
- test/helper.rb
|
196
|
+
- test/locales.yml.example
|
175
197
|
- test/cassettes/vacuum.yml
|
176
|
-
- test/integration_helper.rb
|
177
198
|
- test/locales.rb
|
178
|
-
- test/
|
179
|
-
- test/
|
199
|
+
- test/integration_helper.rb
|
200
|
+
- test/integration/test_requests.rb
|