aliyunsdkcore 0.0.5 → 0.0.6
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/lib/aliyunsdkcore.rb +1 -1
- data/lib/rpc_client.rb +10 -4
- data/spec/rpc_client_integration_spec.rb +13 -6
- data/spec/rpc_client_spec.rb +5 -13
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 581d5102e54082d1ca78dc3d44b6bd726c9a5f80975429c5bdb1475c3f6e765f
|
4
|
+
data.tar.gz: ad731df5501c98b5e041dbeda8919d3373ddc93dba736b8d7775b8eea4b75aa2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8758835e68a3c9aa352f2d07a2d954b7645faae7165c02e1923535f2c8565f05a4f444a3511dcb6dc62d1d4bf3f15e4e2e59d6e48c531d44c58dce02bf3486ba
|
7
|
+
data.tar.gz: b4aaa9363a1edaca92d3106beccb3dbadb6adb37d0b12803a7aab63631b69ff8e700fd5fa8d2400544451a4d79a012afc7499e01b5988248fb06b8e949465c5d
|
data/lib/aliyunsdkcore.rb
CHANGED
data/lib/rpc_client.rb
CHANGED
@@ -36,18 +36,23 @@ class RPCClient
|
|
36
36
|
signature = Base64.encode64(OpenSSL::HMAC.digest('sha1', key, string_to_sign)).strip
|
37
37
|
normalized.push(['Signature', encode(signature)])
|
38
38
|
|
39
|
-
|
39
|
+
querystring = canonicalize(normalized)
|
40
|
+
|
41
|
+
uri = opts[:method] == 'POST' ? '/' : "/?#{querystring}"
|
42
|
+
|
40
43
|
response = connection.send(method.downcase, uri) do |request|
|
41
44
|
if opts[:method] == 'POST'
|
42
45
|
request.headers['Content-Type'] = 'application/x-www-form-urlencoded'
|
43
|
-
request.body =
|
46
|
+
request.body = querystring
|
44
47
|
end
|
45
48
|
end
|
49
|
+
|
46
50
|
response_body = JSON.parse(response.body)
|
47
51
|
if response_body['Code'] && !self.codes.include?(response_body['Code'])
|
48
52
|
raise StandardError, "#{response_body['Message']}, URL: #{uri}"
|
49
53
|
end
|
50
|
-
|
54
|
+
|
55
|
+
response_body
|
51
56
|
end
|
52
57
|
|
53
58
|
private
|
@@ -71,7 +76,8 @@ class RPCClient
|
|
71
76
|
end
|
72
77
|
|
73
78
|
def encode(string)
|
74
|
-
CGI.escape string
|
79
|
+
encoded = CGI.escape string
|
80
|
+
encoded.gsub(/[\+]/, '%20')
|
75
81
|
end
|
76
82
|
|
77
83
|
def format_params(param_hash)
|
@@ -19,17 +19,24 @@ describe 'rpc request' do
|
|
19
19
|
params = { key: (1..11).to_a.map(&:to_s) }
|
20
20
|
request_option = { method: 'POST', timeout: 15000 }
|
21
21
|
response = rpc_client.request(action: 'DescribeRegions', params: params, opts: request_option)
|
22
|
-
|
23
|
-
expect(
|
24
|
-
expect(response_body.keys.include?('RequestId')).to be true
|
22
|
+
expect(response.keys.include?('Regions')).to be true
|
23
|
+
expect(response.keys.include?('RequestId')).to be true
|
25
24
|
end
|
26
25
|
|
27
26
|
it 'should ok with repeat list less 10 item' do
|
28
27
|
params = { key: (1..9).to_a.map(&:to_s) }
|
29
28
|
request_option = { method: 'POST', timeout: 15000 }
|
30
29
|
response = rpc_client.request(action: 'DescribeRegions', params: params, opts: request_option)
|
31
|
-
|
32
|
-
expect(
|
33
|
-
expect(response_body.keys.include?('RequestId')).to be true
|
30
|
+
expect(response.keys.include?('Regions')).to be true
|
31
|
+
expect(response.keys.include?('RequestId')).to be true
|
34
32
|
end
|
33
|
+
|
34
|
+
it 'should ok with space' do
|
35
|
+
params = { key: 'the string with spaces' }
|
36
|
+
request_option = { method: 'POST', timeout: 15000 }
|
37
|
+
response = rpc_client.request(action: 'DescribeRegions', params: params, opts: request_option)
|
38
|
+
expect(response.keys.include?('Regions')).to be true
|
39
|
+
expect(response.keys.include?('RequestId')).to be true
|
40
|
+
end
|
41
|
+
|
35
42
|
end
|
data/spec/rpc_client_spec.rb
CHANGED
@@ -108,7 +108,7 @@ describe 'rpc core' do
|
|
108
108
|
access_key_secret: 'access_key_secret',
|
109
109
|
)
|
110
110
|
stub_request(:get, /https:\/\/ecs.aliyuncs.com/).to_return(status: 200, body: {}.to_json)
|
111
|
-
expect(rpc_client.request(action: 'action')
|
111
|
+
expect(rpc_client.request(action: 'action')).to eql({})
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
@@ -126,33 +126,25 @@ describe 'rpc core' do
|
|
126
126
|
|
127
127
|
it 'should ok' do
|
128
128
|
stub_request(:get, /https:\/\/ecs.aliyuncs.com/).to_return(status: 200, body: {}.to_json)
|
129
|
-
expect(rpc_client.request(action: 'action')
|
129
|
+
expect(rpc_client.request(action: 'action')).to eql({})
|
130
130
|
end
|
131
131
|
|
132
132
|
it 'should ok with format_action' do
|
133
133
|
stub_request(:get, /https:\/\/ecs.aliyuncs.com/).to_return(status: 200, body: {}.to_json)
|
134
134
|
response = rpc_client.request(action: 'action', opts: { format_action: false })
|
135
|
-
expect(response
|
135
|
+
expect(response).to eql({})
|
136
136
|
end
|
137
137
|
|
138
138
|
it 'should ok with format_params' do
|
139
139
|
stub_request(:get, /https:\/\/ecs.aliyuncs.com/).to_return(status: 200, body: {}.to_json)
|
140
140
|
response = rpc_client.request(action: 'action', opts: { format_params: false })
|
141
|
-
expect(response
|
141
|
+
expect(response).to eql({})
|
142
142
|
end
|
143
143
|
|
144
144
|
it 'get with raw body should ok' do
|
145
145
|
stub_request(:post, "https://ecs.aliyuncs.com").to_return(status: 200, body: {}.to_json)
|
146
146
|
response = rpc_client.request(action: 'action', opts: { method: 'POST' })
|
147
|
-
expect(response
|
148
|
-
end
|
149
|
-
|
150
|
-
it 'get with verbose should ok' do
|
151
|
-
stub_request(:get, /https:\/\/ecs.aliyuncs.com/).to_return(status: 200, body: {}.to_json)
|
152
|
-
response = rpc_client.request(action: 'action')
|
153
|
-
expect(response.status).to eq 200
|
154
|
-
expect(response.success?).to be true
|
155
|
-
expect(response.body).to eq({}.to_json)
|
147
|
+
expect(response).to eql({})
|
156
148
|
end
|
157
149
|
end
|
158
150
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aliyunsdkcore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alibaba Cloud SDK
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|