json-rpc-objects 0.1.0
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/.document +5 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +29 -0
- data/LICENSE.txt +20 -0
- data/README.md +118 -0
- data/Rakefile +37 -0
- data/VERSION +1 -0
- data/json-rpc-objects.gemspec +106 -0
- data/lib/json-rpc-objects/error.rb +29 -0
- data/lib/json-rpc-objects/generic.rb +144 -0
- data/lib/json-rpc-objects/request.rb +76 -0
- data/lib/json-rpc-objects/response.rb +73 -0
- data/lib/json-rpc-objects/v10/error.rb +2 -0
- data/lib/json-rpc-objects/v10/fakes/error.rb +69 -0
- data/lib/json-rpc-objects/v10/request.rb +168 -0
- data/lib/json-rpc-objects/v10/response.rb +189 -0
- data/lib/json-rpc-objects/v10/tests/test.rb +20 -0
- data/lib/json-rpc-objects/v11/alt/error.rb +58 -0
- data/lib/json-rpc-objects/v11/alt/fakes/request.rb +33 -0
- data/lib/json-rpc-objects/v11/alt/fakes/response.rb +33 -0
- data/lib/json-rpc-objects/v11/alt/procedure-call.rb +81 -0
- data/lib/json-rpc-objects/v11/alt/procedure-parameter-description.rb +39 -0
- data/lib/json-rpc-objects/v11/alt/procedure-return.rb +45 -0
- data/lib/json-rpc-objects/v11/alt/request.rb +2 -0
- data/lib/json-rpc-objects/v11/alt/response.rb +2 -0
- data/lib/json-rpc-objects/v11/alt/service-description.rb +45 -0
- data/lib/json-rpc-objects/v11/alt/service-procedure-description.rb +58 -0
- data/lib/json-rpc-objects/v11/alt/tests/test.rb +39 -0
- data/lib/json-rpc-objects/v11/generic-types.rb +52 -0
- data/lib/json-rpc-objects/v11/wd/error.rb +172 -0
- data/lib/json-rpc-objects/v11/wd/extensions.rb +76 -0
- data/lib/json-rpc-objects/v11/wd/fakes/request.rb +33 -0
- data/lib/json-rpc-objects/v11/wd/fakes/response.rb +33 -0
- data/lib/json-rpc-objects/v11/wd/procedure-call.rb +205 -0
- data/lib/json-rpc-objects/v11/wd/procedure-parameter-description.rb +179 -0
- data/lib/json-rpc-objects/v11/wd/procedure-return.rb +155 -0
- data/lib/json-rpc-objects/v11/wd/request.rb +2 -0
- data/lib/json-rpc-objects/v11/wd/response.rb +2 -0
- data/lib/json-rpc-objects/v11/wd/service-description.rb +251 -0
- data/lib/json-rpc-objects/v11/wd/service-procedure-description.rb +234 -0
- data/lib/json-rpc-objects/v11/wd/tests/test.rb +39 -0
- data/lib/json-rpc-objects/v20/error.rb +78 -0
- data/lib/json-rpc-objects/v20/request.rb +127 -0
- data/lib/json-rpc-objects/v20/response.rb +107 -0
- data/lib/json-rpc-objects/v20/tests/test.rb +24 -0
- data/lib/json-rpc-objects/version.rb +98 -0
- metadata +230 -0
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
$:.push("../../..")
|
3
|
+
|
4
|
+
require "../request"
|
5
|
+
req = JsonRpcObjects::V10::Request::create(:alfa, [:beta], :id => 12345)
|
6
|
+
puts req.to_json
|
7
|
+
|
8
|
+
require "../response"
|
9
|
+
res = JsonRpcObjects::V10::Response::create(true, nil, :id => 12345)
|
10
|
+
puts res.to_json
|
11
|
+
|
12
|
+
require "../response"
|
13
|
+
res = JsonRpcObjects::V10::Response::create(nil, "some problem", :id => 12345)
|
14
|
+
puts res.to_json
|
15
|
+
|
16
|
+
|
17
|
+
require "../../request"
|
18
|
+
puts JsonRpcObjects::Request::parse(req.to_json).inspect
|
19
|
+
require "../../response"
|
20
|
+
puts JsonRpcObjects::Response::parse(res.to_json).inspect
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "json-rpc-objects/v11/wd/error"
|
3
|
+
|
4
|
+
##
|
5
|
+
# Main JSON-RPC Objects module.
|
6
|
+
#
|
7
|
+
|
8
|
+
module JsonRpcObjects
|
9
|
+
|
10
|
+
##
|
11
|
+
# General module of JSON-RPC 1.1.
|
12
|
+
#
|
13
|
+
|
14
|
+
module V11
|
15
|
+
|
16
|
+
##
|
17
|
+
# Module of JSON-RPC 1.1 Alternative.
|
18
|
+
# @see http://groups.google.com/group/json-rpc/web/json-rpc-1-1-alt
|
19
|
+
#
|
20
|
+
|
21
|
+
module Alt
|
22
|
+
|
23
|
+
##
|
24
|
+
# Error description object class for ProcedureReturn.
|
25
|
+
#
|
26
|
+
|
27
|
+
class Error < JsonRpcObjects::V11::WD::Error
|
28
|
+
|
29
|
+
##
|
30
|
+
# Holds link to its version module.
|
31
|
+
#
|
32
|
+
|
33
|
+
VERSION = JsonRpcObjects::V11::Alt
|
34
|
+
|
35
|
+
##
|
36
|
+
# Checks correctness of the data.
|
37
|
+
#
|
38
|
+
|
39
|
+
def check!
|
40
|
+
self.normalize!
|
41
|
+
end
|
42
|
+
|
43
|
+
##
|
44
|
+
# Renders data to output hash.
|
45
|
+
# @return [Hash] with data of error
|
46
|
+
#
|
47
|
+
|
48
|
+
def output
|
49
|
+
result = super()
|
50
|
+
result.delete(:name)
|
51
|
+
|
52
|
+
return result
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "json-rpc-objects/v11/alt/procedure-call"
|
3
|
+
|
4
|
+
##
|
5
|
+
# Main JSON-RPC Objects module.
|
6
|
+
#
|
7
|
+
|
8
|
+
module JsonRpcObjects
|
9
|
+
|
10
|
+
##
|
11
|
+
# General module of JSON-RPC 1.1.
|
12
|
+
#
|
13
|
+
|
14
|
+
module V11
|
15
|
+
|
16
|
+
##
|
17
|
+
# Module of JSON-RPC 1.1 Alternative.
|
18
|
+
# @see http://groups.google.com/group/json-rpc/web/json-rpc-1-1-alt
|
19
|
+
#
|
20
|
+
|
21
|
+
module Alt
|
22
|
+
|
23
|
+
##
|
24
|
+
# Fake procedure call (request) class.
|
25
|
+
#
|
26
|
+
|
27
|
+
class Request < JsonRpcObjects::V11::Alt::ProcedureCall
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "json-rpc-objects/v11/alt/procedure-return"
|
3
|
+
|
4
|
+
##
|
5
|
+
# Main JSON-RPC Objects module.
|
6
|
+
#
|
7
|
+
|
8
|
+
module JsonRpcObjects
|
9
|
+
|
10
|
+
##
|
11
|
+
# General module of JSON-RPC 1.1.
|
12
|
+
#
|
13
|
+
|
14
|
+
module V11
|
15
|
+
|
16
|
+
##
|
17
|
+
# Module of JSON-RPC 1.1 Alternative.
|
18
|
+
# @see http://groups.google.com/group/json-rpc/web/json-rpc-1-1-alt
|
19
|
+
#
|
20
|
+
|
21
|
+
module Alt
|
22
|
+
|
23
|
+
##
|
24
|
+
# Fake procedure return (response) class.
|
25
|
+
#
|
26
|
+
|
27
|
+
class Response < JsonRpcObjects::V11::Alt::ProcedureReturn
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "hash-utils/hash"
|
3
|
+
require "json-rpc-objects/v11/wd/procedure-call"
|
4
|
+
|
5
|
+
##
|
6
|
+
# Main JSON-RPC Objects module.
|
7
|
+
#
|
8
|
+
|
9
|
+
module JsonRpcObjects
|
10
|
+
|
11
|
+
##
|
12
|
+
# General module of JSON-RPC 1.1.
|
13
|
+
#
|
14
|
+
|
15
|
+
module V11
|
16
|
+
|
17
|
+
##
|
18
|
+
# Module of JSON-RPC 1.1 Alternative.
|
19
|
+
# @see http://groups.google.com/group/json-rpc/web/json-rpc-1-1-alt
|
20
|
+
#
|
21
|
+
|
22
|
+
module Alt
|
23
|
+
|
24
|
+
##
|
25
|
+
# Procedure call (request) class.
|
26
|
+
#
|
27
|
+
|
28
|
+
class ProcedureCall < JsonRpcObjects::V11::WD::ProcedureCall
|
29
|
+
|
30
|
+
##
|
31
|
+
# Holds link to its version module.
|
32
|
+
#
|
33
|
+
|
34
|
+
VERSION = JsonRpcObjects::V11::Alt
|
35
|
+
|
36
|
+
|
37
|
+
protected
|
38
|
+
|
39
|
+
##
|
40
|
+
# Assigns request data.
|
41
|
+
#
|
42
|
+
|
43
|
+
def data=(value, mode = nil)
|
44
|
+
data = __convert_data(value, mode)
|
45
|
+
super(data, :converted)
|
46
|
+
|
47
|
+
data.delete(:kwparams)
|
48
|
+
end
|
49
|
+
|
50
|
+
##
|
51
|
+
# Gets params from input.
|
52
|
+
#
|
53
|
+
|
54
|
+
def __get_params(data)
|
55
|
+
@params = data[:params]
|
56
|
+
|
57
|
+
# For alternative specification merges with 'kwparams'
|
58
|
+
# property.
|
59
|
+
if data.include? :kwparams
|
60
|
+
@keyword_params = data[:kwparams]
|
61
|
+
@keyword_params.map_keys! { |k| k.to_sym }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
##
|
66
|
+
# Assigns the parameters settings.
|
67
|
+
#
|
68
|
+
|
69
|
+
def __assign_params(data, version = :wd)
|
70
|
+
if not @params.nil? and not @params.empty?
|
71
|
+
data[:params] = @params
|
72
|
+
end
|
73
|
+
if not @keyword_params.nil? and not @keyword_params.empty?
|
74
|
+
data[:kwparams] = @keyword_params
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "json-rpc-objects/v11/wd/procedure-parameter-description"
|
3
|
+
|
4
|
+
##
|
5
|
+
# Main JSON-RPC Objects module.
|
6
|
+
#
|
7
|
+
|
8
|
+
module JsonRpcObjects
|
9
|
+
|
10
|
+
##
|
11
|
+
# General module of JSON-RPC 1.1.
|
12
|
+
#
|
13
|
+
|
14
|
+
module V11
|
15
|
+
|
16
|
+
##
|
17
|
+
# Module of JSON-RPC 1.1 Alternative.
|
18
|
+
# @see http://groups.google.com/group/json-rpc/web/json-rpc-1-1-alt
|
19
|
+
#
|
20
|
+
|
21
|
+
module Alt
|
22
|
+
|
23
|
+
##
|
24
|
+
# Description of one procedure parameter.
|
25
|
+
#
|
26
|
+
|
27
|
+
class ProcedureParameterDescription < JsonRpcObjects::V11::WD::ProcedureParameterDescription
|
28
|
+
|
29
|
+
##
|
30
|
+
# Holds link to its version module.
|
31
|
+
#
|
32
|
+
|
33
|
+
VERSION = JsonRpcObjects::V11::Alt
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "json-rpc-objects/v11/alt/error"
|
3
|
+
require "json-rpc-objects/v11/wd/procedure-return"
|
4
|
+
|
5
|
+
##
|
6
|
+
# Main JSON-RPC Objects module.
|
7
|
+
#
|
8
|
+
|
9
|
+
module JsonRpcObjects
|
10
|
+
|
11
|
+
##
|
12
|
+
# General module of JSON-RPC 1.1.
|
13
|
+
#
|
14
|
+
|
15
|
+
module V11
|
16
|
+
|
17
|
+
##
|
18
|
+
# Module of JSON-RPC 1.1 Alternative.
|
19
|
+
# @see http://groups.google.com/group/json-rpc/web/json-rpc-1-1-alt
|
20
|
+
#
|
21
|
+
|
22
|
+
module Alt
|
23
|
+
|
24
|
+
##
|
25
|
+
# Procedure return (response) class.
|
26
|
+
#
|
27
|
+
|
28
|
+
class ProcedureReturn < JsonRpcObjects::V11::WD::ProcedureReturn
|
29
|
+
|
30
|
+
##
|
31
|
+
# Holds link to its version module.
|
32
|
+
#
|
33
|
+
|
34
|
+
VERSION = JsonRpcObjects::V11::Alt
|
35
|
+
|
36
|
+
##
|
37
|
+
# Identified the error object class.
|
38
|
+
#
|
39
|
+
|
40
|
+
ERROR_CLASS = JsonRpcObjects::V11::Alt::Error
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "json-rpc-objects/v11/alt/service-procedure-description"
|
3
|
+
require "json-rpc-objects/v11/wd/service-description"
|
4
|
+
|
5
|
+
##
|
6
|
+
# Main JSON-RPC Objects module.
|
7
|
+
#
|
8
|
+
|
9
|
+
module JsonRpcObjects
|
10
|
+
|
11
|
+
##
|
12
|
+
# General module of JSON-RPC 1.1.
|
13
|
+
#
|
14
|
+
|
15
|
+
module V11
|
16
|
+
|
17
|
+
##
|
18
|
+
# Module of JSON-RPC 1.1 Alternative.
|
19
|
+
# @see http://groups.google.com/group/json-rpc/web/json-rpc-1-1-alt
|
20
|
+
#
|
21
|
+
|
22
|
+
module Alt
|
23
|
+
|
24
|
+
##
|
25
|
+
# Service description object class.
|
26
|
+
#
|
27
|
+
|
28
|
+
class ServiceDescription < JsonRpcObjects::V11::WD::ServiceDescription
|
29
|
+
|
30
|
+
##
|
31
|
+
# Holds link to its version module.
|
32
|
+
#
|
33
|
+
|
34
|
+
VERSION = JsonRpcObjects::V11::Alt
|
35
|
+
|
36
|
+
##
|
37
|
+
# Indicates the procedure parameter description class.
|
38
|
+
#
|
39
|
+
|
40
|
+
PROCEDURE_DESCRIPTION_CLASS = JsonRpcObjects::V11::Alt::ServiceProcedureDescription
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "hash-utils/array"
|
3
|
+
require "json-rpc-objects/v11/alt/procedure-parameter-description"
|
4
|
+
require "json-rpc-objects/v11/wd/service-procedure-description"
|
5
|
+
|
6
|
+
##
|
7
|
+
# Main JSON-RPC Objects module.
|
8
|
+
#
|
9
|
+
|
10
|
+
module JsonRpcObjects
|
11
|
+
|
12
|
+
##
|
13
|
+
# General module of JSON-RPC 1.1.
|
14
|
+
#
|
15
|
+
|
16
|
+
module V11
|
17
|
+
|
18
|
+
##
|
19
|
+
# Module of JSON-RPC 1.1 Alternative.
|
20
|
+
# @see http://groups.google.com/group/json-rpc/web/json-rpc-1-1-alt
|
21
|
+
#
|
22
|
+
|
23
|
+
module Alt
|
24
|
+
|
25
|
+
##
|
26
|
+
# Description of one procedure of the service.
|
27
|
+
#
|
28
|
+
|
29
|
+
class ServiceProcedureDescription < JsonRpcObjects::V11::WD::ServiceProcedureDescription
|
30
|
+
|
31
|
+
##
|
32
|
+
# Holds link to its version module.
|
33
|
+
#
|
34
|
+
|
35
|
+
VERSION = JsonRpcObjects::V11::Alt
|
36
|
+
|
37
|
+
##
|
38
|
+
# Indicates the service procedure description class.
|
39
|
+
#
|
40
|
+
|
41
|
+
PARAMETER_DESCRIPTION_CLASS = JsonRpcObjects::V11::Alt::ProcedureParameterDescription
|
42
|
+
|
43
|
+
##
|
44
|
+
# Checks correctness of the data.
|
45
|
+
#
|
46
|
+
|
47
|
+
def check!
|
48
|
+
super()
|
49
|
+
|
50
|
+
if (@params.kind_of? Array) and (not @params.all? { |v| v.type != JsonRpcObjects::V11::GenericTypes::Nil })
|
51
|
+
raise Exception::new("Nil return type isn't allowed for parameters.")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
$:.push("../../../..")
|
3
|
+
|
4
|
+
require "../procedure-call"
|
5
|
+
req = JsonRpcObjects::V11::Alt::ProcedureCall::create(:alfa, [:foo, :bar], :kwparams => {"0" => :beta, "something" => :alfa}, :id => 12345, :"$whatever" => false)
|
6
|
+
puts req.to_json
|
7
|
+
|
8
|
+
require "../error"
|
9
|
+
err = JsonRpcObjects::V11::Alt::Error::create(200, "some problem")
|
10
|
+
|
11
|
+
require "../procedure-return"
|
12
|
+
res = JsonRpcObjects::V11::Alt::ProcedureReturn::create(nil, err, :id => 12345)
|
13
|
+
puts res.to_json
|
14
|
+
res = JsonRpcObjects::V11::Alt::ProcedureReturn::create(true, nil, :id => 12345)
|
15
|
+
puts res.to_json
|
16
|
+
|
17
|
+
require "../service-description"
|
18
|
+
sdesc = JsonRpcObjects::V11::Alt::ServiceDescription::create(:alfa, 100)
|
19
|
+
puts sdesc.to_json
|
20
|
+
|
21
|
+
require "../service-procedure-description"
|
22
|
+
sproc = JsonRpcObjects::V11::Alt::ServiceProcedureDescription::create(:some_proc)
|
23
|
+
sdesc << sproc
|
24
|
+
puts sdesc.to_json
|
25
|
+
|
26
|
+
require "../procedure-parameter-description"
|
27
|
+
sparam1 = JsonRpcObjects::V11::Alt::ProcedureParameterDescription::create(:param1, :type => :str)
|
28
|
+
sparam2 = JsonRpcObjects::V11::Alt::ProcedureParameterDescription::create(:param2, :type => JsonRpcObjects)
|
29
|
+
sproc << sparam1
|
30
|
+
sproc << sparam2
|
31
|
+
puts sdesc.to_json
|
32
|
+
|
33
|
+
|
34
|
+
require "../../../request"
|
35
|
+
puts JsonRpcObjects::Request::parse(req.to_json).inspect
|
36
|
+
require "../../../response"
|
37
|
+
puts JsonRpcObjects::Response::parse(res.to_json, :alt).inspect
|
38
|
+
|
39
|
+
puts req.class::version.response::create(25)
|