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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 58da2e066be3253ec651b8d669cd2a3a11e43d7a
4
- data.tar.gz: 7537767a94c0a528e0a3566e4b87d917200081a0
3
+ metadata.gz: bc3152fea207123c2b0babcc3e7b09067eaf63c4
4
+ data.tar.gz: a42b9af27a59e05304e70e39db95cd671ba1702e
5
5
  SHA512:
6
- metadata.gz: 97f9611f075af1fbd356fc6f4501d445c38aaa1e4ae1ea33e0ae12b72025c0caac1e37ca33e007136e21719c6c0c37522af4eb1f19fdc52438e3a46057224a4f
7
- data.tar.gz: f01373595fb38d523e5a6569df38dce6d2880e726e9ce1bd1d33b9843d5086e2d7bd4d778040e734aa85433ed6823610f18dd89f3799e4f3e0267dc1b1731f6d
6
+ metadata.gz: b04131232693dd6d87c73a5a844fb88ee407ca60579af48d17af751726e813a0b82e47815397e51f338e5579cc6576400ea0f914a6ebfa4968d5ac22b3993014
7
+ data.tar.gz: 16b6b406fe99842586234e1473ac11c66eb8dfe89367aa34f107a7c9f6584ad2b1a305a060e73ef6ffed8f6ab7446d97ca7df966d6efab31943665f481bf5f9c
data/Rakefile CHANGED
@@ -1,4 +1,4 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
2
  require 'rspec/core/rake_task'
3
3
  RSpec::Core::RakeTask.new(:spec)
4
4
  task :default => :spec
@@ -4,6 +4,7 @@ require 'saorin/request'
4
4
  require 'saorin/response'
5
5
  require 'saorin/server'
6
6
  require 'saorin/client'
7
+ require 'multi_json'
7
8
 
8
9
  module Saorin
9
10
  JSON_RPC_VERSION = '2.0'
@@ -1,4 +1,5 @@
1
1
  require 'saorin/registerable'
2
+ require 'saorin/client/base'
2
3
 
3
4
  module Saorin
4
5
  module Client
@@ -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
- CONTENT_TYPE = 'application/json'.freeze
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
- MultiJson.load content
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
- MultiJson.dump request
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
@@ -6,6 +6,7 @@ module Saorin
6
6
  class Faraday
7
7
  include Base
8
8
 
9
+ CONTENT_TYPE = 'application/json'.freeze
9
10
  attr_reader :connection
10
11
 
11
12
  def initialize(options = {}, &block)
@@ -0,0 +1,10 @@
1
+ require 'saorin/utility'
2
+
3
+ module Saorin
4
+ module Dumpable
5
+ def to_json(*args)
6
+ options = Saorin::Utility.extract_options!(args)
7
+ MultiJson.dump to_h, options
8
+ end
9
+ end
10
+ end
@@ -1,10 +1,12 @@
1
- require 'multi_json'
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
@@ -0,0 +1,11 @@
1
+ module Saorin
2
+ module Formatter
3
+ def default_formatter
4
+ MultiJson
5
+ end
6
+
7
+ def formatter
8
+ @formatter ||= (@options[:formatter] || default_formatter)
9
+ end
10
+ end
11
+ end
@@ -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
@@ -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)
@@ -1,4 +1,5 @@
1
1
  require 'saorin/registerable'
2
+ require 'saorin/server/base'
2
3
 
3
4
  module Saorin
4
5
  module Server
@@ -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
- MultiJson.load content
43
- rescue MultiJson::LoadError
44
+ formatter.load content
45
+ rescue
44
46
  raise Saorin::ParseError
45
47
  end
46
48
 
47
49
  def dump_response(response)
48
- MultiJson.dump response
50
+ formatter.dump response
49
51
  end
50
52
 
51
53
  def handle_request(hash)
@@ -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 :adapter => options[:server]
84
- create_test_client :adapter => options[: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
@@ -1,3 +1,3 @@
1
1
  module Saorin
2
- VERSION = '0.4.1'
2
+ VERSION = '0.5.0'
3
3
  end
@@ -1,5 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'saorin/server/base'
3
2
 
4
3
  describe Saorin::Server::Base do
5
4
  it_should_behave_like 'returning valid response' do
@@ -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.1
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