jsonrpc2.0 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/jsonrpc2.0.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'jsonrpc2.0'
3
- s.version = '0.1.1'
3
+ s.version = '0.1.2'
4
4
  s.summary = 'A server and client implementation of the JsonRpc 2.0 protocol.'
5
5
  s.authors = ['Jannik Theiß']
6
6
  s.email = 'dev@coldsun.org'
@@ -1,7 +1,7 @@
1
1
  require 'json'
2
2
 
3
3
  module JsonRpcErrors
4
- ERRORS = {'ParseError' => -32700, 'InvalidRequest' => -32600, 'MethodNotFound' => -32601, 'InvalidParams' => -32602, 'InternalError' => -32603}
4
+ ERRORS = {'ParseError' => -32700, 'InvalidRequest' => -32600, 'MethodNotFound' => -32601, 'InvalidParams' => -32602, 'InternalError' => -32603, 'MethodNotAllowed' => -32099}
5
5
 
6
6
  class Error < StandardError
7
7
  CODE = nil
@@ -6,7 +6,7 @@ class JsonRpcServer
6
6
  include JsonRpcConstants
7
7
  include JsonRpcErrors
8
8
 
9
- def handle_message(inMessage)
9
+ def handle_message(inMessage, restrictMethod = nil)
10
10
  begin
11
11
  begin
12
12
  message = JSON.parse inMessage
@@ -18,7 +18,7 @@ class JsonRpcServer
18
18
  response = message.map{ |e| handle_request(e) }.to_json
19
19
  response.compact!
20
20
  else
21
- response = handle_request(message).to_json
21
+ response = handle_request(message, restrictMethod).to_json
22
22
  end
23
23
  rescue Error => e
24
24
  id = nil
@@ -34,13 +34,18 @@ class JsonRpcServer
34
34
 
35
35
  private
36
36
 
37
- def handle_request(inRequest)
37
+ def handle_request(inRequest, restrictMethod = nil)
38
38
  raise InvalidRequest if (inRequest.class != Hash)
39
39
  raise InvalidRequest if (inRequest['jsonrpc'] != VERSION)
40
40
  raise InvalidRequest if (!inRequest.key?('method'))
41
41
 
42
42
  begin
43
43
  method = method('r_' + inRequest['method'])
44
+
45
+ unless method == restrictMethod
46
+ raise MethodNotAllowed
47
+ end
48
+
44
49
  params = inRequest['params']
45
50
  result = method.call(*params)
46
51
  rescue NameError => e
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsonrpc2.0
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-06-07 00:00:00.000000000Z
12
+ date: 2011-06-21 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description:
15
15
  email: dev@coldsun.org