vacuum 0.1.3 → 0.2.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +69 -27
- data/lib/vacuum/endpoint/base.rb +58 -0
- data/lib/vacuum/endpoint/mws.rb +59 -0
- data/lib/vacuum/endpoint/product_advertising.rb +34 -0
- data/lib/vacuum/mws.rb +8 -0
- data/lib/vacuum/product_advertising.rb +7 -0
- data/lib/vacuum/request/base.rb +96 -0
- data/lib/vacuum/request/mws.rb +24 -0
- data/lib/vacuum/request/product_advertising.rb +90 -0
- data/lib/vacuum/request/signature/authentication.rb +32 -0
- data/lib/vacuum/request/signature/builder.rb +70 -0
- data/lib/vacuum/request/utils.rb +24 -0
- data/lib/vacuum/response/base.rb +57 -0
- data/lib/vacuum/response/mws.rb +7 -0
- data/lib/vacuum/response/product_advertising.rb +19 -0
- data/lib/vacuum/response/utils.rb +48 -0
- data/lib/vacuum/version.rb +1 -1
- data/lib/vacuum.rb +31 -11
- data/spec/fixtures/{http_response → product_advertising} +0 -0
- data/spec/spec_helper.rb +5 -4
- data/spec/support/shared_examples/endpoint.rb +43 -0
- data/spec/support/shared_examples/request.rb +95 -0
- data/spec/support/shared_examples/response.rb +51 -0
- data/spec/vacuum/endpoint/base_spec.rb +19 -0
- data/spec/vacuum/endpoint/mws_spec.rb +47 -0
- data/spec/vacuum/endpoint/product_advertising_spec.rb +25 -0
- data/spec/vacuum/request/base_spec.rb +22 -0
- data/spec/vacuum/request/mws_spec.rb +26 -0
- data/spec/vacuum/request/product_advertising_spec.rb +104 -0
- data/spec/vacuum/request/signature/authentication_spec.rb +30 -0
- data/spec/vacuum/request/signature/builder_spec.rb +76 -0
- data/spec/vacuum/request/utils_spec.rb +23 -0
- data/spec/vacuum/response/base_spec.rb +38 -0
- data/spec/vacuum/response/product_advertising_spec.rb +57 -0
- data/spec/vacuum/response/utils_spec.rb +42 -0
- metadata +107 -21
- data/lib/vacuum/em.rb +0 -21
- data/lib/vacuum/request.rb +0 -119
- data/lib/vacuum/response.rb +0 -63
- data/spec/vacuum/request_spec.rb +0 -130
- data/spec/vacuum/response_spec.rb +0 -80
data/spec/vacuum/request_spec.rb
DELETED
@@ -1,130 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module Vacuum
|
4
|
-
describe Request do
|
5
|
-
let(:req) do
|
6
|
-
Request.new :locale => :us,
|
7
|
-
:key => 'foo',
|
8
|
-
:secret => 'bar',
|
9
|
-
:tag => 'baz'
|
10
|
-
end
|
11
|
-
|
12
|
-
describe ".new" do
|
13
|
-
it 'raises an error if key is missing' do
|
14
|
-
expect do
|
15
|
-
Request.new :secret => 'foo',
|
16
|
-
:tag => 'bar'
|
17
|
-
end.to raise_error MissingKey
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'raises an error if secret is missing' do
|
21
|
-
expect do
|
22
|
-
Request.new :key => 'foo',
|
23
|
-
:tag => 'bar'
|
24
|
-
end.to raise_error MissingSecret
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'raises an error if tag is missing' do
|
28
|
-
expect do
|
29
|
-
Request.new :key => 'foo',
|
30
|
-
:secret => 'bar'
|
31
|
-
end.to raise_error MissingTag
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'raises an error if locale is not valid' do
|
35
|
-
expect do
|
36
|
-
Request.new :key => 'foo',
|
37
|
-
:secret => 'bar',
|
38
|
-
:tag => 'baz',
|
39
|
-
:locale => 'bad'
|
40
|
-
end.to raise_error BadLocale
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
describe '#build' do
|
45
|
-
it 'merges parameters into the query' do
|
46
|
-
req.build 'Key' => 'value'
|
47
|
-
req.params['Key'].should eql 'value'
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'casts values to string' do
|
51
|
-
req.build 'Key' => 1
|
52
|
-
req.params['Key'].should eql '1'
|
53
|
-
|
54
|
-
req.build 'Key' => ['foo', 'bar']
|
55
|
-
req.params['Key'].should eql 'foo,bar'
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'returns self' do
|
59
|
-
req.build({}).should eql req
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
describe '#build!' do
|
64
|
-
it 'clears existing query' do
|
65
|
-
req.build 'Key' => 'value'
|
66
|
-
req.params.should have_key 'Key'
|
67
|
-
|
68
|
-
req.build!.params.should_not have_key 'Key'
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
describe '#get' do
|
73
|
-
it 'returns a response' do
|
74
|
-
req.get.should be_a Response
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
describe '#params' do
|
79
|
-
it 'includes shared request parameters' do
|
80
|
-
req.params['Service'].should eql 'AWSECommerceService'
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'includes credentials' do
|
84
|
-
req.params.should have_key 'AWSAccessKeyId'
|
85
|
-
req.params.should have_key 'AssociateTag'
|
86
|
-
end
|
87
|
-
|
88
|
-
it 'includes a timestamp' do
|
89
|
-
req.params['Timestamp'].should =~ /^\d+-\d+-\d+T\d+:\d+:\d+Z$/
|
90
|
-
end
|
91
|
-
|
92
|
-
context 'when no API version is given' do
|
93
|
-
it 'includes the current API version' do
|
94
|
-
req.params['Version'].should eql Request::CURRENT_API_VERSION
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
context 'when an API version is given' do
|
99
|
-
it 'includes the given API version' do
|
100
|
-
req.build 'Version' => '1'
|
101
|
-
req.params['Version'].should eql '1'
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
describe '#url' do
|
107
|
-
it 'builds a URL' do
|
108
|
-
req.url.should be_a URI::HTTP
|
109
|
-
end
|
110
|
-
|
111
|
-
it 'canonicalizes the request parameters' do
|
112
|
-
req.url.query.should match /\w+=\w+&/
|
113
|
-
end
|
114
|
-
|
115
|
-
it 'sorts the request parameters' do
|
116
|
-
req.build 'A' => 1
|
117
|
-
req.url.query.should match /^A=1&/
|
118
|
-
end
|
119
|
-
|
120
|
-
it 'URL-encodes values' do
|
121
|
-
req.build 'Key' => 'foo,bar'
|
122
|
-
req.url.query.should match /foo%2Cbar/
|
123
|
-
end
|
124
|
-
|
125
|
-
it 'is signed' do
|
126
|
-
req.url.query.should match /&Signature=/
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
@@ -1,80 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module Vacuum
|
4
|
-
describe Response do
|
5
|
-
let(:res) do
|
6
|
-
body = File.read(File.expand_path('../../fixtures/http_response', __FILE__))
|
7
|
-
Response.new(body, '200')
|
8
|
-
end
|
9
|
-
|
10
|
-
describe '#errors' do
|
11
|
-
it 'returns an array of errors' do
|
12
|
-
res.body = <<-EOF.gsub!(/>\s+</, '><').strip!
|
13
|
-
<?xml version=\"1.0\" ?>
|
14
|
-
<Response xmlns="http://example.com">
|
15
|
-
<Errors>
|
16
|
-
<Error>foo</Error>
|
17
|
-
</Errors>
|
18
|
-
</Response>
|
19
|
-
EOF
|
20
|
-
|
21
|
-
res.errors.should =~ ['foo']
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe '#find' do
|
26
|
-
it 'returns an array of matching nodes' do
|
27
|
-
res.find('ASIN').should_not be_empty
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'yields matches to a block if given one' do
|
31
|
-
titles = res.find('Item') { |item| item['ItemAttributes']['Title'] }
|
32
|
-
titles.count.should eql 2
|
33
|
-
titles.each { |title| title.should be_a String }
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe '#has_errors?' do
|
38
|
-
context 'when response does not contain any errors' do
|
39
|
-
it 'returns false' do
|
40
|
-
res.stub!(:errors).and_return([])
|
41
|
-
res.should_not have_errors
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context 'when response contains errors' do
|
46
|
-
it 'returns true' do
|
47
|
-
res.stub!(:errors).and_return([1])
|
48
|
-
res.should have_errors
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
describe '#to_hash' do
|
54
|
-
it 'casts response to a hash' do
|
55
|
-
res.to_hash.should be_a Hash
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
describe '#valid?' do
|
60
|
-
context 'when HTTP status is OK' do
|
61
|
-
it 'returns true' do
|
62
|
-
res.should be_valid
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
context 'when HTTP status is not OK' do
|
67
|
-
it 'returns false' do
|
68
|
-
res.code = 403
|
69
|
-
res.should_not be_valid
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
describe '#xml' do
|
75
|
-
it 'returns a Nokogiri document' do
|
76
|
-
res.xml.should be_an_instance_of Nokogiri::XML::Document
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|