rpc_client 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fc00eaa96330da9debbf7464b0feb32ccc4d5d91f043392dcad385960cbc02c3
4
- data.tar.gz: 2c0e9514562bfda0a65496cd23bfef0efe002aee86bdce3bf52a7f9bff365641
3
+ metadata.gz: 70ef21204717b2343dab88b3ffbacce0161a6fbf4bdd85abd1547fee7d8993dd
4
+ data.tar.gz: 970c100751fb99ee2ce37921c6bcce2673f441d49992c5f0467c20b0feaaf85b
5
5
  SHA512:
6
- metadata.gz: a040d87089cc6fa4f5c8429249761f9f84c2663b359debfb82f3c5b5d6815ee39be03787c4ccfecfd2a76b83efd28f5596a948c21f4792e0f5bf123565951545
7
- data.tar.gz: 467f2b0e938fa1ce97ff1e06f197da2d50d96700273f4f73c9368bf7a521ffb4b95af01178613763afeae17c8d3e6742aa10b555000e08f06172ac08036c797a
6
+ metadata.gz: 3a19fdc59d5c1182327b0c63c246423cc24774151cb1d3bfdf7f9d34736b90071ba36a8bf6d2834e889cfd82fa7cba2bff1a1d2947224abbf3b97b0336125799
7
+ data.tar.gz: e5cff967a5f25532b4940725b983eb7ff0ade99ea897cb309f317911f3ea8a6e86919ecbc3767514111a33a85b6365789e6db4dabb31251275390341f350c8e0
data/README.md CHANGED
@@ -1,8 +1,18 @@
1
- RPC Client for Ruby
2
- ===================
1
+ <p align="center">
2
+ <a href="https://www.alibabacloud.com"><img src="https://aliyunsdk-pages.alicdn.com/icons/AlibabaCloud.svg"></a>
3
+ </p>
4
+
5
+ <h1 align="center">RPC Client for Ruby</h1>
6
+
7
+ <p align="center">
8
+ <a href="https://badge.fury.io/rb/rpc_client"><img src="https://badge.fury.io/rb/rpc_client.svg" alt="Gem Version"></a>
9
+ <a href="https://travis-ci.org/aliyun/rpc-client-ruby"><img src="https://travis-ci.org/aliyun/rpc-client-ruby.svg?branch=master" alt="Build Status"></a>
10
+ <a href="https://ci.appveyor.com/project/aliyun/rpc-client-ruby/branch/master"><img src="https://ci.appveyor.com/api/projects/status/lm54sril8a9t77bp/branch/master?svg=true" alt="Build status"></a>
11
+ <a href="https://codecov.io/gh/aliyun/rpc-client-ruby"><img src="https://codecov.io/gh/aliyun/rpc-client-ruby/branch/master/graph/badge.svg" alt="codecov"></a>
12
+ </p>
3
13
 
4
14
  This is a Client that used by Alibaba Cloud RPC OpenAPI.
5
15
 
6
16
  ## License
7
17
 
8
- The Apache License 2.0
18
+ The Apache License 2.0
@@ -7,9 +7,9 @@ require 'json'
7
7
 
8
8
  # The AliyunSDK module
9
9
  module AliyunSDK
10
- VERSION = '0.0.2'
10
+ VERSION = '0.0.3'
11
11
 
12
- def replace_repeat_list(target, key, repeat)
12
+ def self.replace_repeat_list(target, key, repeat)
13
13
  repeat.each_with_index do |item, index|
14
14
  if item&.instance_of?(Hash)
15
15
  item.each_key do |k|
@@ -52,7 +52,7 @@ module AliyunSDK
52
52
 
53
53
  # The RPCClient class
54
54
  class RPCClient
55
- attr_accessor :__access_key_id, :__access_key_secret, :__region_id,
55
+ attr_accessor :__access_key_id, :__access_key_secret, :__region_id, :__protocol,
56
56
  :__endpoint, :__version, :credential, :codes
57
57
 
58
58
  def initialize(config)
@@ -62,6 +62,7 @@ module AliyunSDK
62
62
  self.credential = config[:credential]
63
63
  self.__endpoint = config[:endpoint]
64
64
  self.__region_id = config[:regionId]
65
+ self.__protocol = config[:protocol]
65
66
  self.codes = Set.new [200, '200', 'OK', 'Success']
66
67
  codes.merge config[:codes] if config[:codes]
67
68
  end
@@ -106,7 +107,7 @@ module AliyunSDK
106
107
  target = {}
107
108
  query.each do |key, value|
108
109
  if value.instance_of?(Array)
109
- replace_repeat_list(target, key, value)
110
+ AliyunSDK.replace_repeat_list(target, key, value)
110
111
  else
111
112
  target[key] = value.to_s
112
113
  end
@@ -123,7 +124,7 @@ module AliyunSDK
123
124
  end
124
125
 
125
126
  def __get_signature(request, access_key_secret)
126
- method = (request[:method] || 'GET').upcase
127
+ method = (request['method'] || 'GET').upcase
127
128
  normalized = AliyunSDK.normalize(request['query'])
128
129
  canonicalized = AliyunSDK.canonicalize(normalized)
129
130
  string2sign = "#{method}&#{AliyunSDK.encode('/')}&#{AliyunSDK.encode(canonicalized)}"
@@ -0,0 +1,196 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'net/http'
4
+
5
+ require 'rspec'
6
+
7
+ require 'rpc_client'
8
+
9
+ describe 'RPC client' do
10
+ it 'flat_params should ok' do
11
+ h = {}
12
+ r = AliyunSDK.flat_params(h)
13
+ expect(r).to eql({})
14
+
15
+ h = { 'key': 'value' }
16
+ r = AliyunSDK.flat_params(h)
17
+ expect(r).to eql(
18
+ 'key' => 'value'
19
+ )
20
+
21
+ h = { 'key': %w[1 2] }
22
+ r = AliyunSDK.flat_params(h)
23
+ expect(r).to eql(
24
+ 'key.1' => '1',
25
+ 'key.2' => '2'
26
+ )
27
+
28
+ h = { 'key': [{ 'k2': 'value' }] }
29
+ r = AliyunSDK.flat_params(h)
30
+ expect(r).to eql(
31
+ 'key.1.k2' => 'value'
32
+ )
33
+ end
34
+
35
+ it 'normalize should ok' do
36
+ h = {}
37
+ r = AliyunSDK.normalize(h)
38
+ expect(r).to eql([])
39
+
40
+ h = { 'key': 'value' }
41
+ r = AliyunSDK.normalize(h)
42
+ expect(r).to eql([
43
+ %w[key value]
44
+ ])
45
+
46
+ h = { 'key': %w[1 2] }
47
+ r = AliyunSDK.normalize(h)
48
+ expect(r).to eql([['key.1', '1'], ['key.2', '2']])
49
+
50
+ h = { 'key': [{ 'k2': 'value' }] }
51
+ r = AliyunSDK.normalize(h)
52
+ expect(r).to eql(
53
+ [['key.1.k2', 'value']]
54
+ )
55
+ end
56
+
57
+ it '__get_timestamp should ok' do
58
+ client = AliyunSDK::RPCClient.new({})
59
+ ts = client.__get_timestamp
60
+ expect(ts).to match(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z/)
61
+ end
62
+
63
+ it '__get_nonce should ok' do
64
+ client = AliyunSDK::RPCClient.new({})
65
+ ts = client.__get_nonce
66
+ expect(ts).to match(/[\da-z]{32}/)
67
+ end
68
+
69
+ it '__get_access_key_id should ok' do
70
+ client = AliyunSDK::RPCClient.new(
71
+ accessKeyId: 'accessKeyId'
72
+ )
73
+ akid = client.__get_access_key_id
74
+ expect(akid).to eq('accessKeyId')
75
+ end
76
+
77
+ it '__get_access_key_secret should ok' do
78
+ client = AliyunSDK::RPCClient.new(
79
+ accessKeySecret: 'accessKeySecret'
80
+ )
81
+ aksecret = client.__get_access_key_secret
82
+ expect(aksecret).to eq('accessKeySecret')
83
+ end
84
+
85
+ it '__get_endpoint should ok' do
86
+ client = AliyunSDK::RPCClient.new(
87
+ endpoint: 'endpoint'
88
+ )
89
+
90
+ endpoint = client.__get_endpoint 'product', 'region_id'
91
+ expect(endpoint).to eq('endpoint')
92
+
93
+ client = AliyunSDK::RPCClient.new({})
94
+
95
+ endpoint = client.__get_endpoint 'product', 'region_id'
96
+ expect(endpoint).to eq('product.region_id.aliyuncs.com')
97
+ end
98
+
99
+ it '__query should ok' do
100
+ client = AliyunSDK::RPCClient.new({})
101
+ r = client.__query({})
102
+ expect(r).to eql({})
103
+
104
+ r = client.__query(
105
+ 'key': 'value'
106
+ )
107
+ expect(r).to eql(
108
+ key: 'value'
109
+ )
110
+
111
+ r = client.__query(
112
+ 'key': 'value',
113
+ 'array': %w[1 2]
114
+ )
115
+ expect(r).to eql(
116
+ key: 'value',
117
+ 'array.1' => '1',
118
+ 'array.2' => '2'
119
+ )
120
+ end
121
+
122
+ it '__default_number should ok' do
123
+ client = AliyunSDK::RPCClient.new({})
124
+
125
+ r = client.__default_number nil, 10
126
+ expect(r).to eq(10)
127
+ end
128
+
129
+ it '__default should ok' do
130
+ client = AliyunSDK::RPCClient.new({})
131
+
132
+ r = client.__default nil, 10
133
+ expect(r).to eq(10)
134
+ end
135
+
136
+ it '__get_signature should ok' do
137
+ client = AliyunSDK::RPCClient.new({})
138
+ r = client.__get_signature({
139
+ 'method' => 'GET',
140
+ 'query' => {}
141
+ }, 'access_key_secret')
142
+ expect(r).to eq('uVPjs2GBLHS4BwWRTYNdafss1ho=')
143
+ end
144
+
145
+ it '__json should ok' do
146
+ client = AliyunSDK::RPCClient.new({})
147
+ stub_request(:any, 'www.example.com')
148
+ .to_return(
149
+ body: '{}',
150
+ status: 200,
151
+ headers: { 'Content-Length' => 3 }
152
+ )
153
+
154
+ response = Net::HTTP.get_response('www.example.com', '/')
155
+ r = client.__json(response)
156
+ expect(r).to eql({})
157
+ end
158
+
159
+ it '__is5xx should ok' do
160
+ client = AliyunSDK::RPCClient.new({})
161
+ stub_request(:any, 'www.example.com')
162
+ .to_return(
163
+ body: '{}',
164
+ status: 200,
165
+ headers: { 'Content-Length' => 3 }
166
+ )
167
+
168
+ response = Net::HTTP.get_response('www.example.com', '/')
169
+ r = client.__is5xx(response)
170
+ expect(r).to eq(false)
171
+
172
+ stub_request(:any, 'www.example.com')
173
+ .to_return(
174
+ body: '{}',
175
+ status: 500,
176
+ headers: { 'Content-Length' => 3 }
177
+ )
178
+
179
+ response = Net::HTTP.get_response('www.example.com', '/')
180
+ r = client.__is5xx(response)
181
+ expect(r).to eq(true)
182
+ end
183
+
184
+ it '__has_error should ok' do
185
+ client = AliyunSDK::RPCClient.new({})
186
+ r = client.__has_error(
187
+ 'Code' => '200'
188
+ )
189
+ expect(r).to eq(false)
190
+
191
+ r = client.__has_error(
192
+ 'Code' => '500'
193
+ )
194
+ expect(r).to eq(true)
195
+ end
196
+ end
@@ -0,0 +1,112 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'simplecov'
4
+ SimpleCov.start do
5
+ add_filter '/spec/'
6
+ end
7
+
8
+ if ENV['CI'] == 'true'
9
+ require 'codecov'
10
+ SimpleCov.formatter = SimpleCov::Formatter::Codecov
11
+ end
12
+
13
+ require 'webmock/rspec'
14
+
15
+ # This file was generated by the `rspec --init` command. Conventionally, all
16
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
17
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
18
+ # this file to always be loaded, without a need to explicitly require it in any
19
+ # files.
20
+ #
21
+ # Given that it is always loaded, you are encouraged to keep this file as
22
+ # light-weight as possible. Requiring heavyweight dependencies from this file
23
+ # will add to the boot time of your test suite on EVERY test run, even for an
24
+ # individual file that may not need all of that loaded. Instead, consider making
25
+ # a separate helper file that requires the additional dependencies and performs
26
+ # the additional setup, and require it from the spec files that actually need
27
+ # it.
28
+ #
29
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
30
+ RSpec.configure do |config|
31
+ # rspec-expectations config goes here. You can use an alternate
32
+ # assertion/expectation library such as wrong or the stdlib/minitest
33
+ # assertions if you prefer.
34
+ config.expect_with :rspec do |expectations|
35
+ # This option will default to `true` in RSpec 4. It makes the `description`
36
+ # and `failure_message` of custom matchers include text for helper methods
37
+ # defined using `chain`, e.g.:
38
+ # be_bigger_than(2).and_smaller_than(4).description
39
+ # # => "be bigger than 2 and smaller than 4"
40
+ # ...rather than:
41
+ # # => "be bigger than 2"
42
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
43
+ end
44
+
45
+ # rspec-mocks config goes here. You can use an alternate test double
46
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
47
+ config.mock_with :rspec do |mocks|
48
+ # Prevents you from mocking or stubbing a method that does not exist on
49
+ # a real object. This is generally recommended, and will default to
50
+ # `true` in RSpec 4.
51
+ mocks.verify_partial_doubles = true
52
+ end
53
+
54
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
55
+ # have no way to turn it off -- the option exists only for backwards
56
+ # compatibility in RSpec 3). It causes shared context metadata to be
57
+ # inherited by the metadata hash of host groups and examples, rather than
58
+ # triggering implicit auto-inclusion in groups with matching metadata.
59
+ config.shared_context_metadata_behavior = :apply_to_host_groups
60
+
61
+ # The settings below are suggested to provide a good initial experience
62
+ # with RSpec, but feel free to customize to your heart's content.
63
+ # # This allows you to limit a spec run to individual examples or groups
64
+ # # you care about by tagging them with `:focus` metadata. When nothing
65
+ # # is tagged with `:focus`, all examples get run. RSpec also provides
66
+ # # aliases for `it`, `describe`, and `context` that include `:focus`
67
+ # # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
68
+ # config.filter_run_when_matching :focus
69
+ #
70
+ # # Allows RSpec to persist some state between runs in order to support
71
+ # # the `--only-failures` and `--next-failure` CLI options. We recommend
72
+ # # you configure your source control system to ignore this file.
73
+ # config.example_status_persistence_file_path = "spec/examples.txt"
74
+ #
75
+ # # Limits the available syntax to the non-monkey patched syntax that is
76
+ # # recommended. For more details, see:
77
+ # # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
78
+ # # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
79
+ # # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
80
+ # config.disable_monkey_patching!
81
+ #
82
+ # # This setting enables warnings. It's recommended, but in some cases may
83
+ # # be too noisy due to issues in dependencies.
84
+ # config.warnings = true
85
+ #
86
+ # # Many RSpec users commonly either run the entire suite or an individual
87
+ # # file, and it's useful to allow more verbose output when running an
88
+ # # individual spec file.
89
+ # if config.files_to_run.one?
90
+ # # Use the documentation formatter for detailed output,
91
+ # # unless a formatter has already been configured
92
+ # # (e.g. via a command-line flag).
93
+ # config.default_formatter = "doc"
94
+ # end
95
+ #
96
+ # # Print the 10 slowest examples and example groups at the
97
+ # # end of the spec run, to help surface which specs are running
98
+ # # particularly slow.
99
+ # config.profile_examples = 10
100
+ #
101
+ # # Run specs in random order to surface order dependencies. If you find an
102
+ # # order dependency and want to debug it, you can fix the order by providing
103
+ # # the seed, which is printed after each run.
104
+ # # --seed 1234
105
+ # config.order = :random
106
+ #
107
+ # # Seed global randomization in this process using the `--seed` CLI option.
108
+ # # Setting this allows you to use `--seed` to deterministically reproduce
109
+ # # test failures related to randomization by passing the same `--seed` value
110
+ # # as the one that triggered the failure.
111
+ # Kernel.srand config.seed
112
+ end
metadata CHANGED
@@ -1,15 +1,95 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rpc_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
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-07-23 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2019-08-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: codecov
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.1'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.1.10
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '0.1'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.1.10
33
+ - !ruby/object:Gem::Dependency
34
+ name: rspec
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 3.8.0
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '3.8'
43
+ type: :development
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 3.8.0
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: '3.8'
53
+ - !ruby/object:Gem::Dependency
54
+ name: simplecov
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '0.16'
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 0.16.1
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '0.16'
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 0.16.1
73
+ - !ruby/object:Gem::Dependency
74
+ name: webmock
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: 3.6.2
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 3.6.2
83
+ type: :development
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 3.6.2
90
+ - - "~>"
91
+ - !ruby/object:Gem::Version
92
+ version: 3.6.2
13
93
  description: RPC Core SDK for Ruby
14
94
  email:
15
95
  - sdk-team@alibabacloud.com
@@ -19,10 +99,13 @@ extra_rdoc_files: []
19
99
  files:
20
100
  - README.md
21
101
  - lib/rpc_client.rb
102
+ - spec/rpc_client_spec.rb
103
+ - spec/spec_helper.rb
22
104
  homepage: http://www.alibabacloud.com/
23
105
  licenses:
24
- - MIT
25
- metadata: {}
106
+ - Apache-2.0
107
+ metadata:
108
+ source_code_uri: https://github.com/aliyun/rpc-client-ruby
26
109
  post_install_message:
27
110
  rdoc_options: []
28
111
  require_paths:
@@ -42,4 +125,6 @@ rubygems_version: 3.0.4
42
125
  signing_key:
43
126
  specification_version: 4
44
127
  summary: RPC Core SDK for Ruby
45
- test_files: []
128
+ test_files:
129
+ - spec/rpc_client_spec.rb
130
+ - spec/spec_helper.rb