saorin 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/lib/saorin.rb +1 -0
- data/lib/saorin/client.rb +1 -0
- data/lib/saorin/client/base.rb +9 -9
- data/lib/saorin/client/faraday.rb +1 -0
- data/lib/saorin/dumpable.rb +10 -0
- data/lib/saorin/error.rb +3 -6
- data/lib/saorin/formatter.rb +11 -0
- data/lib/saorin/request.rb +3 -6
- data/lib/saorin/response.rb +3 -6
- data/lib/saorin/server.rb +1 -0
- data/lib/saorin/server/base.rb +6 -4
- data/lib/saorin/test.rb +2 -2
- data/lib/saorin/version.rb +1 -1
- data/spec/server/base_spec.rb +0 -1
- data/spec/server/rack_spec.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc3152fea207123c2b0babcc3e7b09067eaf63c4
|
4
|
+
data.tar.gz: a42b9af27a59e05304e70e39db95cd671ba1702e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b04131232693dd6d87c73a5a844fb88ee407ca60579af48d17af751726e813a0b82e47815397e51f338e5579cc6576400ea0f914a6ebfa4968d5ac22b3993014
|
7
|
+
data.tar.gz: 16b6b406fe99842586234e1473ac11c66eb8dfe89367aa34f107a7c9f6584ad2b1a305a060e73ef6ffed8f6ab7446d97ca7df966d6efab31943665f481bf5f9c
|
data/Rakefile
CHANGED
data/lib/saorin.rb
CHANGED
data/lib/saorin/client.rb
CHANGED
data/lib/saorin/client/base.rb
CHANGED
@@ -1,15 +1,18 @@
|
|
1
|
+
require 'saorin/error'
|
1
2
|
require 'saorin/request'
|
2
3
|
require 'saorin/response'
|
4
|
+
require 'saorin/formatter'
|
3
5
|
require 'saorin/client'
|
4
|
-
require 'multi_json'
|
5
|
-
require 'securerandom'
|
6
6
|
|
7
7
|
module Saorin
|
8
8
|
module Client
|
9
9
|
module Base
|
10
|
-
|
10
|
+
include Formatter
|
11
|
+
|
12
|
+
attr_reader :options
|
11
13
|
|
12
14
|
def initialize(options = {})
|
15
|
+
@options = options
|
13
16
|
end
|
14
17
|
|
15
18
|
def call(method, *args)
|
@@ -40,20 +43,16 @@ module Saorin
|
|
40
43
|
else
|
41
44
|
handle_response response
|
42
45
|
end
|
43
|
-
rescue Saorin::InvalidResponse => e
|
44
|
-
raise e
|
45
46
|
rescue => e
|
46
47
|
raise Saorin::InvalidResponse, e.to_s
|
47
48
|
end
|
48
49
|
|
49
50
|
def parse_response(content)
|
50
|
-
|
51
|
-
rescue MultiJson::LoadError => e
|
52
|
-
raise Saorin::InvalidResponse, e.to_s
|
51
|
+
formatter.load content
|
53
52
|
end
|
54
53
|
|
55
54
|
def dump_request(request)
|
56
|
-
|
55
|
+
formatter.dump request
|
57
56
|
end
|
58
57
|
|
59
58
|
def to_content(response)
|
@@ -76,6 +75,7 @@ module Saorin
|
|
76
75
|
end
|
77
76
|
|
78
77
|
def uuid
|
78
|
+
require 'securerandom'
|
79
79
|
SecureRandom.uuid
|
80
80
|
end
|
81
81
|
end
|
data/lib/saorin/error.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
-
require '
|
1
|
+
require 'saorin/dumpable'
|
2
2
|
|
3
3
|
module Saorin
|
4
4
|
class Error < StandardError
|
5
5
|
end
|
6
6
|
|
7
7
|
class RPCError < Error
|
8
|
+
include Dumpable
|
9
|
+
|
8
10
|
attr_reader :code, :data
|
9
11
|
|
10
12
|
def initialize(message, options = {})
|
@@ -20,11 +22,6 @@ module Saorin
|
|
20
22
|
h['data'] = data if data
|
21
23
|
h
|
22
24
|
end
|
23
|
-
|
24
|
-
def to_json(*args)
|
25
|
-
options = Saorin::Utility.extract_options!(args)
|
26
|
-
MultiJson.dump to_h, options
|
27
|
-
end
|
28
25
|
end
|
29
26
|
|
30
27
|
# code message meaning
|
data/lib/saorin/request.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
require 'saorin'
|
2
2
|
require 'saorin/error'
|
3
|
+
require 'saorin/dumpable'
|
3
4
|
require 'saorin/utility'
|
4
|
-
require 'multi_json'
|
5
5
|
|
6
6
|
module Saorin
|
7
7
|
class Request
|
8
|
+
include Dumpable
|
9
|
+
|
8
10
|
attr_accessor :version, :method, :params, :id
|
9
11
|
|
10
12
|
def initialize(method, params, options = {})
|
@@ -43,11 +45,6 @@ module Saorin
|
|
43
45
|
h
|
44
46
|
end
|
45
47
|
|
46
|
-
def to_json(*args)
|
47
|
-
options = Saorin::Utility.extract_options!(args)
|
48
|
-
MultiJson.dump to_h, options
|
49
|
-
end
|
50
|
-
|
51
48
|
def self.symbolized_keys(hash)
|
52
49
|
hash.each do |k, v|
|
53
50
|
if k.is_a? ::String
|
data/lib/saorin/response.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
require 'saorin'
|
2
2
|
require 'saorin/error'
|
3
|
+
require 'saorin/dumpable'
|
3
4
|
require 'saorin/utility'
|
4
|
-
require 'multi_json'
|
5
5
|
|
6
6
|
module Saorin
|
7
7
|
class Response
|
8
|
+
include Dumpable
|
9
|
+
|
8
10
|
attr_accessor :version, :result, :error, :id
|
9
11
|
|
10
12
|
def initialize(options = {})
|
@@ -41,11 +43,6 @@ module Saorin
|
|
41
43
|
h
|
42
44
|
end
|
43
45
|
|
44
|
-
def to_json(*args)
|
45
|
-
options = Saorin::Utility.extract_options!(args)
|
46
|
-
MultiJson.dump to_h, options
|
47
|
-
end
|
48
|
-
|
49
46
|
def self.from_hash(hash)
|
50
47
|
raise Saorin::InvalidResponse unless hash.is_a?(::Hash)
|
51
48
|
new Saorin::Utility.symbolized_keys(hash)
|
data/lib/saorin/server.rb
CHANGED
data/lib/saorin/server/base.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
require 'saorin/error'
|
2
2
|
require 'saorin/request'
|
3
3
|
require 'saorin/response'
|
4
|
+
require 'saorin/formatter'
|
4
5
|
require 'saorin/server'
|
5
|
-
require 'multi_json'
|
6
6
|
|
7
7
|
module Saorin
|
8
8
|
module Server
|
9
9
|
module Base
|
10
|
+
include Formatter
|
11
|
+
|
10
12
|
attr_reader :handler, :allowed_methods
|
11
13
|
attr_reader :options
|
12
14
|
|
@@ -39,13 +41,13 @@ module Saorin
|
|
39
41
|
end
|
40
42
|
|
41
43
|
def parse_request(content)
|
42
|
-
|
43
|
-
rescue
|
44
|
+
formatter.load content
|
45
|
+
rescue
|
44
46
|
raise Saorin::ParseError
|
45
47
|
end
|
46
48
|
|
47
49
|
def dump_response(response)
|
48
|
-
|
50
|
+
formatter.dump response
|
49
51
|
end
|
50
52
|
|
51
53
|
def handle_request(hash)
|
data/lib/saorin/test.rb
CHANGED
@@ -80,8 +80,8 @@ module Saorin
|
|
80
80
|
|
81
81
|
shared_context 'setup rpc server client' do |options|
|
82
82
|
before(:all) do
|
83
|
-
create_test_server
|
84
|
-
create_test_client
|
83
|
+
create_test_server options[:server] || {}
|
84
|
+
create_test_client options[:client] || {}
|
85
85
|
end
|
86
86
|
after(:all) do
|
87
87
|
shutdown_test_server
|
data/lib/saorin/version.rb
CHANGED
data/spec/server/base_spec.rb
CHANGED
data/spec/server/rack_spec.rb
CHANGED
@@ -4,6 +4,6 @@ require 'saorin/server/rack'
|
|
4
4
|
|
5
5
|
describe Saorin::Server::Rack do
|
6
6
|
include Saorin::Test
|
7
|
-
include_context 'setup rpc server client', :server => :rack
|
7
|
+
include_context 'setup rpc server client', :server => {:adapter => :rack}
|
8
8
|
it_should_behave_like 'rpc communicatable'
|
9
9
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: saorin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mashiro
|
@@ -97,7 +97,9 @@ files:
|
|
97
97
|
- lib/saorin/client.rb
|
98
98
|
- lib/saorin/client/base.rb
|
99
99
|
- lib/saorin/client/faraday.rb
|
100
|
+
- lib/saorin/dumpable.rb
|
100
101
|
- lib/saorin/error.rb
|
102
|
+
- lib/saorin/formatter.rb
|
101
103
|
- lib/saorin/registerable.rb
|
102
104
|
- lib/saorin/request.rb
|
103
105
|
- lib/saorin/response.rb
|