saorin 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +18 -0
- data/README.md +1 -1
- data/lib/saorin/client.rb +1 -1
- data/lib/saorin/client/base.rb +36 -5
- data/lib/saorin/error.rb +9 -3
- data/lib/saorin/server.rb +1 -1
- data/lib/saorin/server/base.rb +2 -0
- data/lib/saorin/test.rb +100 -31
- data/lib/saorin/version.rb +1 -1
- data/saorin.gemspec +4 -4
- data/spec/{request_spec.rb → saorin/request_spec.rb} +1 -1
- data/spec/{response_spec.rb → saorin/response_spec.rb} +1 -1
- data/spec/{server → saorin/server}/base_spec.rb +0 -0
- data/spec/{server → saorin/server}/rack_spec.rb +0 -0
- data/spec/spec_helper.rb +3 -0
- metadata +34 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9790f4170f9f9740a494ce87226a6f67d0e1a613
|
4
|
+
data.tar.gz: 4bf5efd3af1127f67e420a69e2ecd1587474d102
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bcef4861617f4ceeeeddcc0aa41d373d98a897b125de545a8835ea4d0db8565cc289bda0125272a07d9cfc14fac28e0b3dffba430c83b24799565c405ef8bcaa
|
7
|
+
data.tar.gz: ffdc00163550c32c3a39102e1ad9299da7a4d5a4cfcdebda4ad7ddfdf2a4a729135d6a8ce0ab8e6ec6dd9d74633a167db7381b18aed131739107a08e54edcbda
|
data/.travis.yml
ADDED
data/README.md
CHANGED
data/lib/saorin/client.rb
CHANGED
data/lib/saorin/client/base.rb
CHANGED
@@ -7,6 +7,14 @@ require 'saorin/client'
|
|
7
7
|
module Saorin
|
8
8
|
module Client
|
9
9
|
module Base
|
10
|
+
module UUID
|
11
|
+
def uuid
|
12
|
+
require 'securerandom'
|
13
|
+
SecureRandom.uuid
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
include UUID
|
10
18
|
include Formatter
|
11
19
|
|
12
20
|
attr_reader :options
|
@@ -30,6 +38,33 @@ module Saorin
|
|
30
38
|
content
|
31
39
|
end
|
32
40
|
|
41
|
+
class Batch < ::Array
|
42
|
+
include UUID
|
43
|
+
attr_reader :client
|
44
|
+
|
45
|
+
def initialize(client)
|
46
|
+
super()
|
47
|
+
@client = client
|
48
|
+
end
|
49
|
+
|
50
|
+
def call(method, *args)
|
51
|
+
push Saorin::Request.new(method, args, :id => uuid)
|
52
|
+
end
|
53
|
+
|
54
|
+
def notify(method, *args)
|
55
|
+
push Saorin::Request.new(method, args)
|
56
|
+
end
|
57
|
+
|
58
|
+
def apply
|
59
|
+
return [] if empty?
|
60
|
+
@client.apply(self) || []
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def batch
|
65
|
+
Batch.new self
|
66
|
+
end
|
67
|
+
|
33
68
|
protected
|
34
69
|
|
35
70
|
def send_request(content)
|
@@ -48,6 +83,7 @@ module Saorin
|
|
48
83
|
end
|
49
84
|
|
50
85
|
def parse_response(content)
|
86
|
+
return nil if content.nil? || content.empty?
|
51
87
|
formatter.load content
|
52
88
|
end
|
53
89
|
|
@@ -73,11 +109,6 @@ module Saorin
|
|
73
109
|
response.validate
|
74
110
|
to_content response
|
75
111
|
end
|
76
|
-
|
77
|
-
def uuid
|
78
|
-
require 'securerandom'
|
79
|
-
SecureRandom.uuid
|
80
|
-
end
|
81
112
|
end
|
82
113
|
end
|
83
114
|
end
|
data/lib/saorin/error.rb
CHANGED
@@ -58,13 +58,19 @@ module Saorin
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
+
class UserDefinedError < RPCError
|
62
|
+
end
|
63
|
+
|
61
64
|
class << self
|
62
65
|
def code_to_error(code)
|
63
|
-
|
66
|
+
case code
|
67
|
+
when nil
|
68
|
+
nil
|
69
|
+
when (-32099..-32000)
|
64
70
|
ServerError
|
65
71
|
else
|
66
|
-
@
|
67
|
-
@
|
72
|
+
@error_code_map ||= Hash[JSON_RPC_ERRORS.map { |c, n, m| [c, const_get(n)] }]
|
73
|
+
@error_code_map[code] || UserDefinedError
|
68
74
|
end
|
69
75
|
end
|
70
76
|
end
|
data/lib/saorin/server.rb
CHANGED
data/lib/saorin/server/base.rb
CHANGED
data/lib/saorin/test.rb
CHANGED
@@ -78,6 +78,10 @@ module Saorin
|
|
78
78
|
@client.notify *args
|
79
79
|
end
|
80
80
|
|
81
|
+
def test_batch
|
82
|
+
@client.batch
|
83
|
+
end
|
84
|
+
|
81
85
|
shared_context 'setup rpc server client' do |options|
|
82
86
|
before(:all) do
|
83
87
|
create_test_server options[:server] || {}
|
@@ -89,37 +93,102 @@ module Saorin
|
|
89
93
|
end
|
90
94
|
|
91
95
|
shared_examples 'rpc communicatable' do
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
96
|
+
describe '#call' do
|
97
|
+
it 'string' do
|
98
|
+
v = '123'
|
99
|
+
expect(test_call('identity', v)).to eq v
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'number' do
|
103
|
+
v = 123
|
104
|
+
expect(test_call('identity', v)).to eq v
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'array' do
|
108
|
+
v = [1, 2, 3]
|
109
|
+
expect(test_call('identity', v)).to eq v
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'hash' do
|
113
|
+
v = {'foo' => 1, 'bar' => 2}
|
114
|
+
expect(test_call('identity', v)).to eq v
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'nil' do
|
118
|
+
v = nil
|
119
|
+
expect(test_call('identity', v)).to eq v
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'not found' do
|
123
|
+
expect { test_call('xx') }.to raise_error MethodNotFound
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'invalid params' do
|
127
|
+
expect { test_call('identity', 1, 2, 3, 4, 5) }.to raise_error InvalidParams
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
describe '#notify' do
|
132
|
+
it 'string' do
|
133
|
+
v = '123'
|
134
|
+
expect(test_notify('identity', v)).to eq nil
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'not found' do
|
138
|
+
expect(test_notify('xxx')).to eq nil
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'invalid params' do
|
142
|
+
expect(test_notify('identity', 1, 2, 3, 4, 5)).to eq nil
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
describe '#batch' do
|
147
|
+
it 'batch call' do
|
148
|
+
b = test_batch
|
149
|
+
b.call 'identity', 1
|
150
|
+
b.call 'identity', '2'
|
151
|
+
b.call 'identity', [3]
|
152
|
+
b.call 'xxx'
|
153
|
+
|
154
|
+
ret = b.apply
|
155
|
+
expect(ret).to have(4).items
|
156
|
+
expect(ret[0]).to eq 1
|
157
|
+
expect(ret[1]).to eq '2'
|
158
|
+
expect(ret[2]).to eq [3]
|
159
|
+
expect(ret[3]).to be_instance_of MethodNotFound
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'batch call with notify' do
|
163
|
+
b = test_batch
|
164
|
+
b.call 'identity', 1
|
165
|
+
b.notify 'identity', '2'
|
166
|
+
b.call 'identity', [3]
|
167
|
+
b.notify 'xxx'
|
168
|
+
|
169
|
+
ret = b.apply
|
170
|
+
expect(ret).to have(2).items
|
171
|
+
expect(ret[0]).to eq 1
|
172
|
+
expect(ret[1]).to eq [3]
|
173
|
+
end
|
174
|
+
|
175
|
+
it 'all notify' do
|
176
|
+
b = test_batch
|
177
|
+
b.notify 'identity', 1
|
178
|
+
b.notify 'identity', '2'
|
179
|
+
b.notify 'identity', [3]
|
180
|
+
b.notify 'xxx'
|
181
|
+
|
182
|
+
ret = b.apply
|
183
|
+
expect(ret).to have(0).items
|
184
|
+
end
|
185
|
+
|
186
|
+
it 'empty' do
|
187
|
+
b = test_batch
|
188
|
+
|
189
|
+
ret = b.apply
|
190
|
+
expect(ret).to have(0).items
|
191
|
+
end
|
123
192
|
end
|
124
193
|
end
|
125
194
|
end
|
data/lib/saorin/version.rb
CHANGED
data/saorin.gemspec
CHANGED
@@ -19,8 +19,8 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
21
|
spec.add_dependency 'multi_json'
|
22
|
-
spec.add_development_dependency 'rake'
|
23
|
-
spec.add_development_dependency 'rspec'
|
24
|
-
spec.add_development_dependency 'rack'
|
25
|
-
spec.add_development_dependency 'faraday'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.4.2'
|
23
|
+
spec.add_development_dependency 'rspec', '~> 2.14.1'
|
24
|
+
spec.add_development_dependency 'rack', '~> 1.5.2'
|
25
|
+
spec.add_development_dependency 'faraday', '~> 0.9.0'
|
26
26
|
end
|
File without changes
|
File without changes
|
data/spec/spec_helper.rb
CHANGED
@@ -9,6 +9,9 @@ RSpec.configure do |config|
|
|
9
9
|
config.treat_symbols_as_metadata_keys_with_true_values = true
|
10
10
|
config.run_all_when_everything_filtered = true
|
11
11
|
config.filter_run :focus
|
12
|
+
config.expect_with :rspec do |c|
|
13
|
+
c.syntax = [:should, :expect]
|
14
|
+
end
|
12
15
|
|
13
16
|
# Run specs in random order to surface order dependencies. If you find an
|
14
17
|
# order dependency and want to debug it, you can fix the order by providing
|
metadata
CHANGED
@@ -1,85 +1,85 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: saorin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mashiro
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 10.4.2
|
34
34
|
type: :development
|
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:
|
40
|
+
version: 10.4.2
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 2.14.1
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 2.14.1
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rack
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 1.5.2
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 1.5.2
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: faraday
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 0.9.0
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 0.9.0
|
83
83
|
description: JSON-RPC 2.0 implementation
|
84
84
|
email:
|
85
85
|
- mail@mashiro.org
|
@@ -87,8 +87,9 @@ executables: []
|
|
87
87
|
extensions: []
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
|
-
- .gitignore
|
91
|
-
- .rspec
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".travis.yml"
|
92
93
|
- Gemfile
|
93
94
|
- LICENSE.txt
|
94
95
|
- README.md
|
@@ -110,10 +111,10 @@ files:
|
|
110
111
|
- lib/saorin/utility.rb
|
111
112
|
- lib/saorin/version.rb
|
112
113
|
- saorin.gemspec
|
113
|
-
- spec/request_spec.rb
|
114
|
-
- spec/response_spec.rb
|
115
|
-
- spec/server/base_spec.rb
|
116
|
-
- spec/server/rack_spec.rb
|
114
|
+
- spec/saorin/request_spec.rb
|
115
|
+
- spec/saorin/response_spec.rb
|
116
|
+
- spec/saorin/server/base_spec.rb
|
117
|
+
- spec/saorin/server/rack_spec.rb
|
117
118
|
- spec/spec_helper.rb
|
118
119
|
- spec/support/response.rb
|
119
120
|
- spec/support/utils.rb
|
@@ -127,25 +128,25 @@ require_paths:
|
|
127
128
|
- lib
|
128
129
|
required_ruby_version: !ruby/object:Gem::Requirement
|
129
130
|
requirements:
|
130
|
-
- -
|
131
|
+
- - ">="
|
131
132
|
- !ruby/object:Gem::Version
|
132
133
|
version: '0'
|
133
134
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
135
|
requirements:
|
135
|
-
- -
|
136
|
+
- - ">="
|
136
137
|
- !ruby/object:Gem::Version
|
137
138
|
version: '0'
|
138
139
|
requirements: []
|
139
140
|
rubyforge_project:
|
140
|
-
rubygems_version: 2.
|
141
|
+
rubygems_version: 2.2.2
|
141
142
|
signing_key:
|
142
143
|
specification_version: 4
|
143
144
|
summary: JSON-RPC 2.0 server and client implementation for any protocols
|
144
145
|
test_files:
|
145
|
-
- spec/request_spec.rb
|
146
|
-
- spec/response_spec.rb
|
147
|
-
- spec/server/base_spec.rb
|
148
|
-
- spec/server/rack_spec.rb
|
146
|
+
- spec/saorin/request_spec.rb
|
147
|
+
- spec/saorin/response_spec.rb
|
148
|
+
- spec/saorin/server/base_spec.rb
|
149
|
+
- spec/saorin/server/rack_spec.rb
|
149
150
|
- spec/spec_helper.rb
|
150
151
|
- spec/support/response.rb
|
151
152
|
- spec/support/utils.rb
|