aliyunsdkcore 0.0.6 → 0.0.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 581d5102e54082d1ca78dc3d44b6bd726c9a5f80975429c5bdb1475c3f6e765f
4
- data.tar.gz: ad731df5501c98b5e041dbeda8919d3373ddc93dba736b8d7775b8eea4b75aa2
3
+ metadata.gz: 75c66f7b9d52d1d4018fcf7a7c1ab5e30642b7ad7136f119209e1703d8b529a9
4
+ data.tar.gz: ebe5ab5cc9d7be04ecdb1b14985d90054041943cf68825b97a046e0aca4e0402
5
5
  SHA512:
6
- metadata.gz: 8758835e68a3c9aa352f2d07a2d954b7645faae7165c02e1923535f2c8565f05a4f444a3511dcb6dc62d1d4bf3f15e4e2e59d6e48c531d44c58dce02bf3486ba
7
- data.tar.gz: b4aaa9363a1edaca92d3106beccb3dbadb6adb37d0b12803a7aab63631b69ff8e700fd5fa8d2400544451a4d79a012afc7499e01b5988248fb06b8e949465c5d
6
+ metadata.gz: cdf0d90f0e936a2fd34ece59b8699bc0ab628f09daf9fd75af29ab8db8b52ec6d018dc09f834326132db54665eaeece67cb9de60485f427dcf5316dd076d5c80
7
+ data.tar.gz: 7f54b1754aa69036f777802c6b10e4de55b682858f59987699561c687c9d34f3a9a8aee35735bd513b794529b5a6f598af400d2409505ec7222bfd23e7853ed2
data/README.md CHANGED
@@ -47,10 +47,9 @@ response = client.request(
47
47
  opts: request_option
48
48
  )
49
49
 
50
- print JSON.parse(response.body)
50
+ print response
51
51
  ```
52
52
 
53
-
54
53
  The ROA demo:
55
54
 
56
55
  ```ruby
@@ -71,10 +70,9 @@ response = client.request(
71
70
  }
72
71
  )
73
72
 
74
- print JSON.parse(response.body)
73
+ print response.body
75
74
  ```
76
75
 
77
-
78
76
  ## Issues
79
77
  [Opening an Issue](https://github.com/aliyun/openapi-core-ruby-sdk/issues/new/choose), Issues not conforming to the guidelines may be closed immediately.
80
78
 
data/lib/aliyunsdkcore.rb CHANGED
@@ -2,5 +2,5 @@ require_relative './rpc_client'
2
2
  require_relative './roa_client'
3
3
 
4
4
  module AliyunSDKCore
5
- VERSION = "0.0.6"
5
+ VERSION = "0.0.7"
6
6
  end
data/lib/roa_client.rb CHANGED
@@ -2,6 +2,10 @@ require 'faraday'
2
2
  require 'securerandom'
3
3
  require 'active_support/all'
4
4
 
5
+ def present?(obj)
6
+ obj.respond_to?(:empty?) ? !obj.empty? : obj
7
+ end
8
+
5
9
  class ROAClient
6
10
 
7
11
  attr_accessor :endpoint, :api_version, :access_key_id, :access_key_secret, :security_token, :hostname, :opts
@@ -24,7 +28,7 @@ class ROAClient
24
28
 
25
29
  response = connection.send(method.downcase) do |request|
26
30
  request.url uri, params
27
- if body.present?
31
+ if present?(body)
28
32
  request_body = body.to_json
29
33
  request.body = request_body
30
34
  mix_headers['content-md5'] = Digest::MD5.base64digest request_body
@@ -93,7 +97,6 @@ class ROAClient
93
97
  private
94
98
 
95
99
  def string_to_sign(method, uri, headers, query = {})
96
- headers.stringify_keys!
97
100
  header_string = [
98
101
  method,
99
102
  headers['accept'],
data/lib/rpc_client.rb CHANGED
@@ -3,6 +3,15 @@ require 'openssl'
3
3
  require 'faraday'
4
4
  require 'active_support/all'
5
5
 
6
+ # Converts just the first character to uppercase.
7
+ #
8
+ # upcase_first('what a Lovely Day') # => "What a Lovely Day"
9
+ # upcase_first('w') # => "W"
10
+ # upcase_first('') # => ""
11
+ def upcase_first(string)
12
+ string.length > 0 ? string[0].upcase.concat(string[1..-1]) : ""
13
+ end
14
+
6
15
  class RPCClient
7
16
 
8
17
  attr_accessor :endpoint, :api_version, :access_key_id, :access_key_secret, :security_token, :codes, :opts, :verbose
@@ -24,7 +33,7 @@ class RPCClient
24
33
 
25
34
  def request(action:, params: {}, opts: {})
26
35
  opts = self.opts.merge(opts)
27
- action = action.upcase_first if opts[:format_action]
36
+ action = upcase_first(action) if opts[:format_action]
28
37
  params = format_params(params) unless opts[:format_params]
29
38
  defaults = default_params
30
39
  params = { Action: action }.merge(defaults).merge(params)
@@ -63,15 +72,15 @@ class RPCClient
63
72
 
64
73
  def default_params
65
74
  default_params = {
66
- :Format => 'JSON',
67
- :SignatureMethod => 'HMAC-SHA1',
68
- :SignatureNonce => SecureRandom.hex(16),
69
- :SignatureVersion => '1.0',
70
- :Timestamp => Time.now.utc.strftime('%Y-%m-%dT%H:%M:%SZ'),
71
- :AccessKeyId => self.access_key_id,
72
- :Version => self.api_version,
75
+ 'Format' => 'JSON',
76
+ 'SignatureMethod' => 'HMAC-SHA1',
77
+ 'SignatureNonce' => SecureRandom.hex(16),
78
+ 'SignatureVersion' => '1.0',
79
+ 'Timestamp' => Time.now.utc.strftime('%Y-%m-%dT%H:%M:%SZ'),
80
+ 'AccessKeyId' => self.access_key_id,
81
+ 'Version' => self.api_version,
73
82
  }
74
- default_params.merge!(SecurityToken: self.security_token) if self.security_token
83
+ default_params.merge!('SecurityToken' => self.security_token) if self.security_token
75
84
  default_params
76
85
  end
77
86
 
@@ -81,7 +90,7 @@ class RPCClient
81
90
  end
82
91
 
83
92
  def format_params(param_hash)
84
- param_hash.keys.each { |key| param_hash[key.to_s.upcase_first.to_sym] = param_hash.delete key }
93
+ param_hash.keys.each { |key| param_hash[upcase_first(key.to_s).to_sym] = param_hash.delete key }
85
94
  param_hash
86
95
  end
87
96
 
@@ -102,7 +111,7 @@ class RPCClient
102
111
  if value.instance_of?(Array)
103
112
  replace_repeat_list(target, key, value)
104
113
  else
105
- target[key] = value
114
+ target[key.to_s] = value
106
115
  end
107
116
  end
108
117
  target
@@ -110,7 +119,6 @@ class RPCClient
110
119
 
111
120
  def normalize(params)
112
121
  flat_params(params)
113
- .stringify_keys
114
122
  .sort
115
123
  .to_h
116
124
  .map { |key, value| [encode(key), encode(value)] }
@@ -114,18 +114,6 @@ describe 'roa core' do
114
114
  expect(roa_client.default_headers[:accept]).to eq('application/json')
115
115
  end
116
116
 
117
- it 'request with raw body should ok' do
118
- stub_request(:get, "https://ecs.aliyuncs.com/").to_return(body: 'raw body')
119
- response = roa_client.request(method: 'GET', uri: '/', options: { raw_body: true })
120
- expect(response.body).to eq('raw body')
121
- end
122
-
123
- it 'get request with raw body should ok' do
124
- stub_request(:get, "https://ecs.aliyuncs.com/").to_return(body: 'raw body')
125
- response = roa_client.get(uri: '/', options: { raw_body: true })
126
- expect(response.body).to eq('raw body')
127
- end
128
-
129
117
  describe 'request with json response should ok' do
130
118
  it 'json response should ok' do
131
119
  stub_request(:get, "https://ecs.aliyuncs.com/")
@@ -263,7 +251,7 @@ describe 'roa core' do
263
251
 
264
252
  it 'string_to_sign should ok ' do
265
253
  expect(
266
- roa_client.send(:string_to_sign, 'GET', '/', { accept: 'application/json' })
254
+ roa_client.send(:string_to_sign, 'GET', '/', { 'accept' => 'application/json' })
267
255
  ).to eq("GET\napplication/json\n\n\n\n/")
268
256
  end
269
257
 
@@ -271,15 +259,15 @@ describe 'roa core' do
271
259
  it 'ACSError should ok' do
272
260
  expect {
273
261
  error_info = {
274
- Message: 'error message',
275
- Code: 'errorcode',
276
- HostId: 'hostid',
277
- RequestId: 'requestid',
262
+ 'Message' => 'error message',
263
+ 'Code' => 'errorcode',
264
+ 'HostId' => 'hostid',
265
+ 'RequestId' => 'requestid',
278
266
  }
279
- raise ROAClient::ACSError, error_info.stringify_keys!
267
+ raise ROAClient::ACSError, error_info
280
268
  }.to raise_error(ROAClient::ACSError, 'error message host_id: hostid, request_id: requestid')
281
269
  end
282
270
  end
283
271
 
284
272
 
285
- end
273
+ end
@@ -83,7 +83,7 @@ describe 'rpc core' do
83
83
  access_key_secret: 'access_key_secret',
84
84
  )
85
85
  default_params_keys = %w(Format SignatureMethod SignatureNonce SignatureVersion Timestamp AccessKeyId Version)
86
- expect(rpc_client.send(:default_params).stringify_keys.keys).to match_array default_params_keys
86
+ expect(rpc_client.send(:default_params).keys).to match_array default_params_keys
87
87
  end
88
88
  end
89
89
 
@@ -96,7 +96,7 @@ describe 'rpc core' do
96
96
  security_token: 'security_token'
97
97
  )
98
98
  default_params_keys = %w(Format SignatureMethod SignatureNonce SignatureVersion Timestamp AccessKeyId Version SecurityToken)
99
- expect(rpc_client.send(:default_params).stringify_keys.keys).to match_array default_params_keys
99
+ expect(rpc_client.send(:default_params).keys).to match_array default_params_keys
100
100
  end
101
101
 
102
102
  describe 'request' do
@@ -201,7 +201,7 @@ describe 'rpc core' do
201
201
  it 'flat_params should ok' do
202
202
  expect(rpc_client.send(:flat_params, {})).to eq({})
203
203
  expect(rpc_client.send(:flat_params, { key: ['value'] })).to eq({ 'key.1' => 'value' })
204
- expect(rpc_client.send(:flat_params, { key: 'value' })).to eq({ key: 'value' })
204
+ expect(rpc_client.send(:flat_params, { key: 'value' })).to eq({ 'key' => 'value' })
205
205
  expect(rpc_client.send(:flat_params, { key: [{ Domain: '1.com' }] })).to eq({ 'key.1.Domain' => '1.com' })
206
206
  end
207
207
 
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'simplecov'
2
+
2
3
  SimpleCov.start do
3
4
  add_filter "/spec/"
4
5
  end
@@ -107,4 +108,4 @@ RSpec.configure do |config|
107
108
  # as the one that triggered the failure.
108
109
  Kernel.srand config.seed
109
110
  =end
110
- end
111
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aliyunsdkcore
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alibaba Cloud SDK
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 5.2.2
33
+ version: 4.0.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 5.2.2
40
+ version: 4.0.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: simplecov
43
43
  requirement: !ruby/object:Gem::Requirement