json-rpc-objects 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
gem "multitype-introspection", ">= 0.1.0"
|
5
|
+
gem "hash-utils", ">= 0.3.0"
|
6
|
+
gem "types", ">= 0.1.0"
|
7
|
+
gem "version", ">= 0.9.2"
|
8
|
+
gem "addressable", ">= 2.2.2"
|
9
|
+
gem "yajl-ruby", ">= 0.7.8"
|
10
|
+
|
11
|
+
# Add dependencies to develop your gem here.
|
12
|
+
# Include everything needed to run rake, tests, features, etc.
|
13
|
+
group :development do
|
14
|
+
gem "bundler", "~> 1.0.0"
|
15
|
+
gem "jeweler", "~> 1.5.2"
|
16
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
addressable (2.2.2)
|
5
|
+
git (1.2.5)
|
6
|
+
hash-utils (0.3.0)
|
7
|
+
jeweler (1.5.2)
|
8
|
+
bundler (~> 1.0.0)
|
9
|
+
git (>= 1.2.5)
|
10
|
+
rake
|
11
|
+
multitype-introspection (0.1.0)
|
12
|
+
rake (0.8.7)
|
13
|
+
types (0.1.0)
|
14
|
+
multitype-introspection (>= 0.1.0)
|
15
|
+
version (0.9.2)
|
16
|
+
yajl-ruby (0.7.8)
|
17
|
+
|
18
|
+
PLATFORMS
|
19
|
+
ruby
|
20
|
+
|
21
|
+
DEPENDENCIES
|
22
|
+
addressable (>= 2.2.2)
|
23
|
+
bundler (~> 1.0.0)
|
24
|
+
hash-utils (>= 0.3.0)
|
25
|
+
jeweler (~> 1.5.2)
|
26
|
+
multitype-introspection (>= 0.1.0)
|
27
|
+
types (>= 0.1.0)
|
28
|
+
version (>= 0.9.2)
|
29
|
+
yajl-ruby (>= 0.7.8)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Martin Kozák
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
JSON-RPC Objects
|
2
|
+
================
|
3
|
+
|
4
|
+
**JSON-RPC Objects** are implementation of by [JSON-RPC][1] defined
|
5
|
+
objects with respect to specifications compliance and API backward
|
6
|
+
compatibility. It implements all versions of the protocol and support
|
7
|
+
for ability to communicate by the same protocol version which the
|
8
|
+
other side uses by a transparent way.
|
9
|
+
|
10
|
+
It means, it implements following JSON-RPC versions:
|
11
|
+
|
12
|
+
* [1.0][2] (*original specification*)
|
13
|
+
* [1.1 WD][3] (*working draft*)
|
14
|
+
* [1.1 Alt][4] (*alternative proposal*)
|
15
|
+
* [2.0][5] (*revised specification proposal*)
|
16
|
+
|
17
|
+
### Protocol Versions Compatibility
|
18
|
+
|
19
|
+
All protocols are implemented from points of view of features which must
|
20
|
+
complain to. Some of these aren't encouraged, but it's on will of the
|
21
|
+
user. 2.0 and 1.1 Alt implements some minor additions compared to
|
22
|
+
specification such as object extensions as defined in 1.1 WD, but
|
23
|
+
mainly because of API compatibility and functionallity reasons.
|
24
|
+
|
25
|
+
All classes inherit from previous version so API is homogenous.
|
26
|
+
Application which can deal with 1.0 can deal with 2.0 too without any
|
27
|
+
funcionallity or logic lost.
|
28
|
+
|
29
|
+
### Usage
|
30
|
+
|
31
|
+
All object classes have three creating class methods:
|
32
|
+
|
33
|
+
* `#create(<some arguments>, opts = { })` – which creates new
|
34
|
+
object according to arguments (required members) and options (optional
|
35
|
+
members),
|
36
|
+
* `#parse(string)` – which parses the JSON string,
|
37
|
+
* `#new(data)` – which creates new object from hash.
|
38
|
+
|
39
|
+
All names of both class names and optional arguments are exactly the
|
40
|
+
same as defined in specification.
|
41
|
+
|
42
|
+
It can be used by two ways. You know either concrete version of the
|
43
|
+
protocol which you want to use in your application (typically client)
|
44
|
+
or you process some incoming request which can use whatever of
|
45
|
+
the versions (typically server).
|
46
|
+
|
47
|
+
Concrete version use example (creates call to `subtract` method with
|
48
|
+
ID "a2b3"):
|
49
|
+
|
50
|
+
require "json-rpc-objects/v10/request"
|
51
|
+
require "json-rpc-objects/v11/alt/request"
|
52
|
+
require "json-rpc-objects/v20/request"
|
53
|
+
|
54
|
+
JsonRpcObjects::V10::Request::create(:subtract, ["1", "2"], :id => "a2b3")
|
55
|
+
JsonRpcObjects::V11::Alt::Request::create(:subtract, ["1", "2"], :id => "a2b3")
|
56
|
+
JsonRpcObjects::V20::Request::create(:subtract, ["1", "2"], :id => "a2b3")
|
57
|
+
|
58
|
+
Or incoming data processing request:
|
59
|
+
|
60
|
+
require "json-rpc-objects/request"
|
61
|
+
JsonRpcObjects::Request::parse(string)
|
62
|
+
|
63
|
+
…which will simply return request object of appropriate class according
|
64
|
+
to its version. Be warn, to distinguish between 1.1 Alt and 1.1 WD is
|
65
|
+
impossible in most of cases. It isn't problem for simple use, but it
|
66
|
+
can be problem in some special cases. Default is WD, but Alt can be set
|
67
|
+
as default if it's required.
|
68
|
+
|
69
|
+
### Transparent Processing
|
70
|
+
|
71
|
+
In some cases, for example in case implementing of JSON-RPC server, you
|
72
|
+
need make response to request by the same protocol version. It can be
|
73
|
+
achieved by simple way:
|
74
|
+
|
75
|
+
require "json-rpc-objects/request"
|
76
|
+
|
77
|
+
request = JsonRpcObjects::Request::parse(string)
|
78
|
+
... <data processing>
|
79
|
+
response = request.class::version.response::create(<some args>)
|
80
|
+
|
81
|
+
This code analyzes protocol version of the request and creates response
|
82
|
+
of the same protocol version. It utilizes call handler, so you can call
|
83
|
+
for example `request.class::version.service_procedure_description::create(<arguments>)`
|
84
|
+
for obtaining 1.1 service procedure description object. But be warn
|
85
|
+
again, neither 1.0 nor 2.0 implements these objects, so it can simply
|
86
|
+
cause `LoadError` in that case therefore it really isn't recommended.
|
87
|
+
|
88
|
+
Be limited by `Error`, `Request` and `Response` classes here or check
|
89
|
+
the protocol version using `#VERSION` class constant. Also note,
|
90
|
+
`Request` and `Response` are fake classes for 1.1, and `Error` for 1.0,
|
91
|
+
so correspondent 2.0 classes aren't ancestors of these, but of
|
92
|
+
`ProcedureCall` and `ProcedureReturn`. This may be subject of change in
|
93
|
+
future releases.
|
94
|
+
|
95
|
+
Contributing
|
96
|
+
------------
|
97
|
+
|
98
|
+
1. Fork it.
|
99
|
+
2. Create a branch (`git checkout -b 20101220-my-change`).
|
100
|
+
3. Commit your changes (`git commit -am "Added something"`).
|
101
|
+
4. Push to the branch (`git push origin 20101220-my-change`).
|
102
|
+
5. Create an [Issue][6] with a link to your branch.
|
103
|
+
6. Enjoy a refreshing Diet Coke and wait.
|
104
|
+
|
105
|
+
|
106
|
+
Copyright
|
107
|
+
---------
|
108
|
+
|
109
|
+
Copyright © 2011 [Martin Kozák][7]. See `LICENSE.txt` for
|
110
|
+
further details.
|
111
|
+
|
112
|
+
[1]: http://en.wikipedia.org/wiki/JSON-RPC
|
113
|
+
[2]: http://json-rpc.org/wiki/specification
|
114
|
+
[3]: http://json-rpc.org/wd/JSON-RPC-1-1-WD-20060807.html
|
115
|
+
[4]: http://groups.google.com/group/json-rpc/web/json-rpc-1-1-alt
|
116
|
+
[5]: http://groups.google.com/group/json-rpc/web/json-rpc-2-0
|
117
|
+
[6]: http://github.com/martinkozak/json-rpc-objects/issues
|
118
|
+
[7]: http://www.martinkozak.net/
|
data/Rakefile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'rubygems'
|
3
|
+
require 'bundler'
|
4
|
+
begin
|
5
|
+
Bundler.setup(:default, :development)
|
6
|
+
rescue Bundler::BundlerError => e
|
7
|
+
$stderr.puts e.message
|
8
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
9
|
+
exit e.status_code
|
10
|
+
end
|
11
|
+
require 'rake'
|
12
|
+
|
13
|
+
require 'jeweler'
|
14
|
+
Jeweler::Tasks.new do |gem|
|
15
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
16
|
+
gem.name = "json-rpc-objects"
|
17
|
+
gem.homepage = "http://github.com/martinkozak/json-rpc-objects"
|
18
|
+
gem.license = "MIT"
|
19
|
+
gem.summary = 'Implementation of JSON-RPC objects with respect to specifications compliance and API backward compatibility. Implements all versions of the protocol and support for ability to communicate by the same protocol version which other side uses by a transparent way.'
|
20
|
+
gem.email = "martinkozak@martinkozak.net"
|
21
|
+
gem.authors = ["Martin Kozák"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
25
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rake/rdoctask'
|
30
|
+
Rake::RDocTask.new do |rdoc|
|
31
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
32
|
+
|
33
|
+
rdoc.rdoc_dir = 'rdoc'
|
34
|
+
rdoc.title = "types #{version}"
|
35
|
+
rdoc.rdoc_files.include('README*')
|
36
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
37
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,106 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{json-rpc-objects}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Martin Kozák"]
|
12
|
+
s.date = %q{2011-01-13}
|
13
|
+
s.email = %q{martinkozak@martinkozak.net}
|
14
|
+
s.extra_rdoc_files = [
|
15
|
+
"LICENSE.txt",
|
16
|
+
"README.md"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".document",
|
20
|
+
"Gemfile",
|
21
|
+
"Gemfile.lock",
|
22
|
+
"LICENSE.txt",
|
23
|
+
"README.md",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"json-rpc-objects.gemspec",
|
27
|
+
"lib/json-rpc-objects/error.rb",
|
28
|
+
"lib/json-rpc-objects/generic.rb",
|
29
|
+
"lib/json-rpc-objects/request.rb",
|
30
|
+
"lib/json-rpc-objects/response.rb",
|
31
|
+
"lib/json-rpc-objects/v10/error.rb",
|
32
|
+
"lib/json-rpc-objects/v10/fakes/error.rb",
|
33
|
+
"lib/json-rpc-objects/v10/request.rb",
|
34
|
+
"lib/json-rpc-objects/v10/response.rb",
|
35
|
+
"lib/json-rpc-objects/v10/tests/test.rb",
|
36
|
+
"lib/json-rpc-objects/v11/alt/error.rb",
|
37
|
+
"lib/json-rpc-objects/v11/alt/fakes/request.rb",
|
38
|
+
"lib/json-rpc-objects/v11/alt/fakes/response.rb",
|
39
|
+
"lib/json-rpc-objects/v11/alt/procedure-call.rb",
|
40
|
+
"lib/json-rpc-objects/v11/alt/procedure-parameter-description.rb",
|
41
|
+
"lib/json-rpc-objects/v11/alt/procedure-return.rb",
|
42
|
+
"lib/json-rpc-objects/v11/alt/request.rb",
|
43
|
+
"lib/json-rpc-objects/v11/alt/response.rb",
|
44
|
+
"lib/json-rpc-objects/v11/alt/service-description.rb",
|
45
|
+
"lib/json-rpc-objects/v11/alt/service-procedure-description.rb",
|
46
|
+
"lib/json-rpc-objects/v11/alt/tests/test.rb",
|
47
|
+
"lib/json-rpc-objects/v11/generic-types.rb",
|
48
|
+
"lib/json-rpc-objects/v11/wd/error.rb",
|
49
|
+
"lib/json-rpc-objects/v11/wd/extensions.rb",
|
50
|
+
"lib/json-rpc-objects/v11/wd/fakes/request.rb",
|
51
|
+
"lib/json-rpc-objects/v11/wd/fakes/response.rb",
|
52
|
+
"lib/json-rpc-objects/v11/wd/procedure-call.rb",
|
53
|
+
"lib/json-rpc-objects/v11/wd/procedure-parameter-description.rb",
|
54
|
+
"lib/json-rpc-objects/v11/wd/procedure-return.rb",
|
55
|
+
"lib/json-rpc-objects/v11/wd/request.rb",
|
56
|
+
"lib/json-rpc-objects/v11/wd/response.rb",
|
57
|
+
"lib/json-rpc-objects/v11/wd/service-description.rb",
|
58
|
+
"lib/json-rpc-objects/v11/wd/service-procedure-description.rb",
|
59
|
+
"lib/json-rpc-objects/v11/wd/tests/test.rb",
|
60
|
+
"lib/json-rpc-objects/v20/error.rb",
|
61
|
+
"lib/json-rpc-objects/v20/request.rb",
|
62
|
+
"lib/json-rpc-objects/v20/response.rb",
|
63
|
+
"lib/json-rpc-objects/v20/tests/test.rb",
|
64
|
+
"lib/json-rpc-objects/version.rb"
|
65
|
+
]
|
66
|
+
s.homepage = %q{http://github.com/martinkozak/json-rpc-objects}
|
67
|
+
s.licenses = ["MIT"]
|
68
|
+
s.require_paths = ["lib"]
|
69
|
+
s.rubygems_version = %q{1.3.7}
|
70
|
+
s.summary = %q{Implementation of JSON-RPC objects with respect to specifications compliance and API backward compatibility. Implements all versions of the protocol and support for ability to communicate by the same protocol version which other side uses by a transparent way.}
|
71
|
+
|
72
|
+
if s.respond_to? :specification_version then
|
73
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
74
|
+
s.specification_version = 3
|
75
|
+
|
76
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
77
|
+
s.add_runtime_dependency(%q<multitype-introspection>, [">= 0.1.0"])
|
78
|
+
s.add_runtime_dependency(%q<hash-utils>, [">= 0.3.0"])
|
79
|
+
s.add_runtime_dependency(%q<types>, [">= 0.1.0"])
|
80
|
+
s.add_runtime_dependency(%q<version>, [">= 0.9.2"])
|
81
|
+
s.add_runtime_dependency(%q<addressable>, [">= 2.2.2"])
|
82
|
+
s.add_runtime_dependency(%q<yajl-ruby>, [">= 0.7.8"])
|
83
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
84
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
85
|
+
else
|
86
|
+
s.add_dependency(%q<multitype-introspection>, [">= 0.1.0"])
|
87
|
+
s.add_dependency(%q<hash-utils>, [">= 0.3.0"])
|
88
|
+
s.add_dependency(%q<types>, [">= 0.1.0"])
|
89
|
+
s.add_dependency(%q<version>, [">= 0.9.2"])
|
90
|
+
s.add_dependency(%q<addressable>, [">= 2.2.2"])
|
91
|
+
s.add_dependency(%q<yajl-ruby>, [">= 0.7.8"])
|
92
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
93
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
94
|
+
end
|
95
|
+
else
|
96
|
+
s.add_dependency(%q<multitype-introspection>, [">= 0.1.0"])
|
97
|
+
s.add_dependency(%q<hash-utils>, [">= 0.3.0"])
|
98
|
+
s.add_dependency(%q<types>, [">= 0.1.0"])
|
99
|
+
s.add_dependency(%q<version>, [">= 0.9.2"])
|
100
|
+
s.add_dependency(%q<addressable>, [">= 2.2.2"])
|
101
|
+
s.add_dependency(%q<yajl-ruby>, [">= 0.7.8"])
|
102
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
103
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "json-rpc-objects/v20/response"
|
3
|
+
|
4
|
+
##
|
5
|
+
# Main JSON-RPC Objects module.
|
6
|
+
#
|
7
|
+
|
8
|
+
module JsonRpcObjects
|
9
|
+
|
10
|
+
##
|
11
|
+
# Error module for universal API.
|
12
|
+
#
|
13
|
+
|
14
|
+
module Error
|
15
|
+
|
16
|
+
##
|
17
|
+
# Returns request of the latest standard.
|
18
|
+
#
|
19
|
+
# @param [Array] args for target constructor
|
20
|
+
# @return [JsonRpcObjects::V11::Alt::Error] error object
|
21
|
+
#
|
22
|
+
|
23
|
+
def self.create(*args)
|
24
|
+
JsonRpcObjects::V11::Alt::Error::create(*args)
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,144 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "hash-utils"
|
3
|
+
require "yajl/json_gem"
|
4
|
+
require "json-rpc-objects/version"
|
5
|
+
|
6
|
+
##
|
7
|
+
# Main JSON-RPC Objects module.
|
8
|
+
#
|
9
|
+
|
10
|
+
module JsonRpcObjects
|
11
|
+
|
12
|
+
##
|
13
|
+
# Module for generic object methods.
|
14
|
+
#
|
15
|
+
|
16
|
+
module Generic
|
17
|
+
|
18
|
+
##
|
19
|
+
# Generic JSON-RPC Object.
|
20
|
+
# @abstract
|
21
|
+
#
|
22
|
+
|
23
|
+
class Object
|
24
|
+
|
25
|
+
##
|
26
|
+
# Creates new one.
|
27
|
+
#
|
28
|
+
# @param [Array] args some arguments
|
29
|
+
# @return [JsonRpc::Generic::Object] new object
|
30
|
+
#
|
31
|
+
|
32
|
+
def self.create(*args)
|
33
|
+
__abstract
|
34
|
+
end
|
35
|
+
|
36
|
+
##
|
37
|
+
# Returns the version object.
|
38
|
+
# @return [JsonRpcObjects::Version] appropriate version object
|
39
|
+
#
|
40
|
+
|
41
|
+
def self.version
|
42
|
+
JsonRpcObjects::Version::get(self::VERSION)
|
43
|
+
end
|
44
|
+
|
45
|
+
##
|
46
|
+
# Parses JSON-RPC string.
|
47
|
+
#
|
48
|
+
# @param [String] string with the JSON data
|
49
|
+
# @return [Generic::Object] of the given class
|
50
|
+
#
|
51
|
+
|
52
|
+
def self.parse(string)
|
53
|
+
self::new(JSON.load(string))
|
54
|
+
end
|
55
|
+
|
56
|
+
##
|
57
|
+
# Converts back to JSON.
|
58
|
+
# @return [String]
|
59
|
+
#
|
60
|
+
|
61
|
+
def to_json
|
62
|
+
self.output.to_json
|
63
|
+
end
|
64
|
+
|
65
|
+
##
|
66
|
+
# Constructor.
|
67
|
+
# @param [Hash] data for initializing the object
|
68
|
+
#
|
69
|
+
|
70
|
+
def initialize(data)
|
71
|
+
self.data = data
|
72
|
+
self.check!
|
73
|
+
end
|
74
|
+
|
75
|
+
##
|
76
|
+
# Checks correctness of the request data.
|
77
|
+
#
|
78
|
+
|
79
|
+
def check!
|
80
|
+
end
|
81
|
+
|
82
|
+
##
|
83
|
+
# Renders data to output form.
|
84
|
+
#
|
85
|
+
# @return [Object] with data of object
|
86
|
+
# @abstract
|
87
|
+
#
|
88
|
+
|
89
|
+
def output
|
90
|
+
__abstract
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
protected
|
95
|
+
|
96
|
+
##
|
97
|
+
# Assigns request data.
|
98
|
+
#
|
99
|
+
|
100
|
+
def data=(value, mode = nil)
|
101
|
+
__abstract
|
102
|
+
end
|
103
|
+
|
104
|
+
##
|
105
|
+
# Converts data keys from strings to symbols if necessary.
|
106
|
+
#
|
107
|
+
|
108
|
+
def __convert_data(data, mode = nil)
|
109
|
+
if mode != :converted
|
110
|
+
data.keys_to_sym
|
111
|
+
else
|
112
|
+
data
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
##
|
117
|
+
# Converts request data to standard (defined) format.
|
118
|
+
#
|
119
|
+
|
120
|
+
def normalize!
|
121
|
+
end
|
122
|
+
|
123
|
+
|
124
|
+
private
|
125
|
+
|
126
|
+
##
|
127
|
+
# Raises method is abstract exception.
|
128
|
+
#
|
129
|
+
|
130
|
+
def __abstract
|
131
|
+
self.class::__abstract
|
132
|
+
end
|
133
|
+
|
134
|
+
##
|
135
|
+
# Raises method is abstract exception.
|
136
|
+
#
|
137
|
+
|
138
|
+
def self.__abstract
|
139
|
+
raise Exception::new("Method is abstract.")
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|