saorin 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/saorin/client/base.rb +11 -20
- data/lib/saorin/error.rb +1 -1
- data/lib/saorin/request.rb +1 -1
- data/lib/saorin/response.rb +1 -1
- data/lib/saorin/server/base.rb +7 -2
- data/lib/saorin/test.rb +5 -8
- data/lib/saorin/utility.rb +4 -0
- data/lib/saorin/version.rb +1 -1
- data/spec/server/base_spec.rb +3 -2
- data/spec/server/rack_spec.rb +2 -4
- data/spec/support/{rpc_call.rb → response.rb} +1 -2
- data/spec/support/utils.rb +3 -3
- metadata +19 -37
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5d731d83b57e3aa94b1496a35d8d635ac7f0e4b1
|
4
|
+
data.tar.gz: 58702ec40e1322e327f8813da93c36e87345d27d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ee7f2206ee8092b8549961d0d517dc792dcddd5e23c4b06c6ad045b6a4668e84ed594d66aade15b7b3b202deaef0367a7968e706909167d810fdc70701dfc31a
|
7
|
+
data.tar.gz: a0e9be370c67bf3d7bd589941a7a9d7bc3d2b1b1ebc08bad9ff17707b1895496081e17d5053cf94e7f6d46e5c2f7400de2f9ce85273901c5c3de4f2d0cba30dc
|
data/lib/saorin/client/base.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
require 'multi_json'
|
2
1
|
require 'saorin/request'
|
3
2
|
require 'saorin/response'
|
4
3
|
require 'saorin/client'
|
4
|
+
require 'multi_json'
|
5
|
+
require 'securerandom'
|
5
6
|
|
6
7
|
module Saorin
|
7
8
|
module Client
|
@@ -12,7 +13,7 @@ module Saorin
|
|
12
13
|
end
|
13
14
|
|
14
15
|
def call(method, *args)
|
15
|
-
apply Saorin::Request.new(method, args, :id =>
|
16
|
+
apply Saorin::Request.new(method, args, :id => uuid)
|
16
17
|
end
|
17
18
|
|
18
19
|
def notify(method, *args)
|
@@ -20,7 +21,7 @@ module Saorin
|
|
20
21
|
end
|
21
22
|
|
22
23
|
def apply(request)
|
23
|
-
response = send_request request
|
24
|
+
response = send_request dump_request(request)
|
24
25
|
content = process_response response
|
25
26
|
raise content if content.is_a?(Saorin::RPCError)
|
26
27
|
content
|
@@ -42,17 +43,19 @@ module Saorin
|
|
42
43
|
rescue Saorin::InvalidResponse => e
|
43
44
|
raise e
|
44
45
|
rescue => e
|
45
|
-
p e
|
46
|
-
print e.backtrace.join("\t\n")
|
47
46
|
raise Saorin::InvalidResponse, e.to_s
|
48
47
|
end
|
49
48
|
|
50
49
|
def parse_response(content)
|
51
|
-
MultiJson.
|
50
|
+
MultiJson.load content
|
52
51
|
rescue MultiJson::LoadError => e
|
53
52
|
raise Saorin::InvalidResponse, e.to_s
|
54
53
|
end
|
55
54
|
|
55
|
+
def dump_request(request)
|
56
|
+
MultiJson.dump request
|
57
|
+
end
|
58
|
+
|
56
59
|
def to_content(response)
|
57
60
|
return nil if response.nil?
|
58
61
|
if response.error?
|
@@ -72,20 +75,8 @@ module Saorin
|
|
72
75
|
to_content response
|
73
76
|
end
|
74
77
|
|
75
|
-
def
|
76
|
-
|
77
|
-
end
|
78
|
-
|
79
|
-
def seqid=(value)
|
80
|
-
@@seqid = value
|
81
|
-
@@seqid = 0 if @@seqid >= (1 << 31)
|
82
|
-
@@seqid
|
83
|
-
end
|
84
|
-
|
85
|
-
def seqid!
|
86
|
-
id = self.seqid
|
87
|
-
self.seqid += 1
|
88
|
-
id
|
78
|
+
def uuid
|
79
|
+
SecureRandom.uuid
|
89
80
|
end
|
90
81
|
end
|
91
82
|
end
|
data/lib/saorin/error.rb
CHANGED
data/lib/saorin/request.rb
CHANGED
data/lib/saorin/response.rb
CHANGED
data/lib/saorin/server/base.rb
CHANGED
@@ -2,6 +2,7 @@ require 'saorin/error'
|
|
2
2
|
require 'saorin/request'
|
3
3
|
require 'saorin/response'
|
4
4
|
require 'saorin/server'
|
5
|
+
require 'multi_json'
|
5
6
|
|
6
7
|
module Saorin
|
7
8
|
module Server
|
@@ -34,15 +35,19 @@ module Saorin
|
|
34
35
|
Response.new(:error => e)
|
35
36
|
end
|
36
37
|
|
37
|
-
response
|
38
|
+
dump_response response if response
|
38
39
|
end
|
39
40
|
|
40
41
|
def parse_request(content)
|
41
|
-
MultiJson.
|
42
|
+
MultiJson.load content
|
42
43
|
rescue MultiJson::LoadError
|
43
44
|
raise Saorin::ParseError
|
44
45
|
end
|
45
46
|
|
47
|
+
def dump_response(response)
|
48
|
+
MultiJson.dump response
|
49
|
+
end
|
50
|
+
|
46
51
|
def handle_request(hash)
|
47
52
|
begin
|
48
53
|
request = Request.from_hash(hash)
|
data/lib/saorin/test.rb
CHANGED
@@ -57,12 +57,11 @@ module Saorin
|
|
57
57
|
}.merge(options))
|
58
58
|
@server.start
|
59
59
|
end
|
60
|
-
sleep
|
60
|
+
sleep 1
|
61
61
|
end
|
62
62
|
|
63
63
|
def shutdown_test_server
|
64
64
|
Process.kill :INT, @pid
|
65
|
-
sleep 2
|
66
65
|
end
|
67
66
|
|
68
67
|
def create_test_client(options = {})
|
@@ -79,19 +78,17 @@ module Saorin
|
|
79
78
|
@client.notify *args
|
80
79
|
end
|
81
80
|
|
82
|
-
shared_context 'setup rpc server client' do
|
83
|
-
let(:server_adapter) {}
|
84
|
-
let(:client_adapter) {}
|
81
|
+
shared_context 'setup rpc server client' do |options|
|
85
82
|
before(:all) do
|
86
|
-
create_test_server :adapter =>
|
87
|
-
create_test_client :adapter =>
|
83
|
+
create_test_server :adapter => options[:server]
|
84
|
+
create_test_client :adapter => options[:client]
|
88
85
|
end
|
89
86
|
after(:all) do
|
90
87
|
shutdown_test_server
|
91
88
|
end
|
92
89
|
end
|
93
90
|
|
94
|
-
shared_examples 'rpc
|
91
|
+
shared_examples 'rpc communicatable' do
|
95
92
|
it 'string' do
|
96
93
|
value = '123'
|
97
94
|
test_call('identity', value).should eq value
|
data/lib/saorin/utility.rb
CHANGED
data/lib/saorin/version.rb
CHANGED
data/spec/server/base_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
require 'saorin/server/base'
|
3
3
|
|
4
4
|
describe Saorin::Server::Base do
|
5
|
-
it_should_behave_like '
|
5
|
+
it_should_behave_like 'returning valid response' do
|
6
6
|
let(:process) do
|
7
7
|
handler = Saorin::Test::Handler.new
|
8
8
|
class VanillaServer
|
@@ -10,7 +10,8 @@ describe Saorin::Server::Base do
|
|
10
10
|
end
|
11
11
|
server = VanillaServer.new handler
|
12
12
|
proc do |input|
|
13
|
-
server.process_request input
|
13
|
+
data = server.process_request input
|
14
|
+
data && JSON.load(data)
|
14
15
|
end
|
15
16
|
end
|
16
17
|
end
|
data/spec/server/rack_spec.rb
CHANGED
@@ -4,8 +4,6 @@ require 'saorin/server/rack'
|
|
4
4
|
|
5
5
|
describe Saorin::Server::Rack do
|
6
6
|
include Saorin::Test
|
7
|
-
|
8
|
-
|
9
|
-
include_context 'setup rpc server client'
|
10
|
-
it_should_behave_like 'rpc server client'
|
7
|
+
include_context 'setup rpc server client', :server => :rack
|
8
|
+
it_should_behave_like 'rpc communicatable'
|
11
9
|
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'support/utils'
|
2
|
-
require 'json'
|
3
2
|
|
4
3
|
shared_examples 'rpc call with positional parameters' do
|
5
4
|
it 'rpc call with positional parameters' do
|
@@ -142,7 +141,7 @@ shared_examples 'rpc call Batch (all notifications)' do
|
|
142
141
|
end
|
143
142
|
end
|
144
143
|
|
145
|
-
shared_examples '
|
144
|
+
shared_examples 'returning valid response' do
|
146
145
|
let(:inputs) { [] }
|
147
146
|
let(:answers) { [] }
|
148
147
|
include_examples 'rpc call with positional parameters'
|
data/spec/support/utils.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'saorin/test'
|
2
2
|
|
3
|
-
def
|
3
|
+
def json_decode(data)
|
4
4
|
data && JSON.load(data)
|
5
5
|
end
|
6
6
|
|
7
7
|
def validates(process, inputs, answers)
|
8
8
|
inputs.zip(answers).each do |input, answer|
|
9
|
-
output =
|
10
|
-
answer =
|
9
|
+
output = process.call(input)
|
10
|
+
answer = json_decode answer
|
11
11
|
output.should eq answer
|
12
12
|
end
|
13
13
|
end
|
metadata
CHANGED
@@ -1,94 +1,83 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: saorin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.4.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- mashiro
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-05-09 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: multi_json
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rake
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: rspec
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - '>='
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - '>='
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: rack
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - '>='
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '0'
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - '>='
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '0'
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: faraday
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
|
-
- -
|
73
|
+
- - '>='
|
84
74
|
- !ruby/object:Gem::Version
|
85
75
|
version: '0'
|
86
76
|
type: :development
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
|
-
- -
|
80
|
+
- - '>='
|
92
81
|
- !ruby/object:Gem::Version
|
93
82
|
version: '0'
|
94
83
|
description: JSON-RPC 2.0 implementation
|
@@ -124,37 +113,30 @@ files:
|
|
124
113
|
- spec/server/base_spec.rb
|
125
114
|
- spec/server/rack_spec.rb
|
126
115
|
- spec/spec_helper.rb
|
127
|
-
- spec/support/
|
116
|
+
- spec/support/response.rb
|
128
117
|
- spec/support/utils.rb
|
129
118
|
homepage: ''
|
130
119
|
licenses: []
|
120
|
+
metadata: {}
|
131
121
|
post_install_message:
|
132
122
|
rdoc_options: []
|
133
123
|
require_paths:
|
134
124
|
- lib
|
135
125
|
required_ruby_version: !ruby/object:Gem::Requirement
|
136
|
-
none: false
|
137
126
|
requirements:
|
138
|
-
- -
|
127
|
+
- - '>='
|
139
128
|
- !ruby/object:Gem::Version
|
140
129
|
version: '0'
|
141
|
-
segments:
|
142
|
-
- 0
|
143
|
-
hash: 2282161111462653130
|
144
130
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
|
-
none: false
|
146
131
|
requirements:
|
147
|
-
- -
|
132
|
+
- - '>='
|
148
133
|
- !ruby/object:Gem::Version
|
149
134
|
version: '0'
|
150
|
-
segments:
|
151
|
-
- 0
|
152
|
-
hash: 2282161111462653130
|
153
135
|
requirements: []
|
154
136
|
rubyforge_project:
|
155
|
-
rubygems_version:
|
137
|
+
rubygems_version: 2.0.0
|
156
138
|
signing_key:
|
157
|
-
specification_version:
|
139
|
+
specification_version: 4
|
158
140
|
summary: JSON-RPC 2.0 server and client implementation for any protocols
|
159
141
|
test_files:
|
160
142
|
- spec/request_spec.rb
|
@@ -162,5 +144,5 @@ test_files:
|
|
162
144
|
- spec/server/base_spec.rb
|
163
145
|
- spec/server/rack_spec.rb
|
164
146
|
- spec/spec_helper.rb
|
165
|
-
- spec/support/
|
147
|
+
- spec/support/response.rb
|
166
148
|
- spec/support/utils.rb
|