json-rpc-objects 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/.document +5 -0
  2. data/Gemfile +16 -0
  3. data/Gemfile.lock +29 -0
  4. data/LICENSE.txt +20 -0
  5. data/README.md +118 -0
  6. data/Rakefile +37 -0
  7. data/VERSION +1 -0
  8. data/json-rpc-objects.gemspec +106 -0
  9. data/lib/json-rpc-objects/error.rb +29 -0
  10. data/lib/json-rpc-objects/generic.rb +144 -0
  11. data/lib/json-rpc-objects/request.rb +76 -0
  12. data/lib/json-rpc-objects/response.rb +73 -0
  13. data/lib/json-rpc-objects/v10/error.rb +2 -0
  14. data/lib/json-rpc-objects/v10/fakes/error.rb +69 -0
  15. data/lib/json-rpc-objects/v10/request.rb +168 -0
  16. data/lib/json-rpc-objects/v10/response.rb +189 -0
  17. data/lib/json-rpc-objects/v10/tests/test.rb +20 -0
  18. data/lib/json-rpc-objects/v11/alt/error.rb +58 -0
  19. data/lib/json-rpc-objects/v11/alt/fakes/request.rb +33 -0
  20. data/lib/json-rpc-objects/v11/alt/fakes/response.rb +33 -0
  21. data/lib/json-rpc-objects/v11/alt/procedure-call.rb +81 -0
  22. data/lib/json-rpc-objects/v11/alt/procedure-parameter-description.rb +39 -0
  23. data/lib/json-rpc-objects/v11/alt/procedure-return.rb +45 -0
  24. data/lib/json-rpc-objects/v11/alt/request.rb +2 -0
  25. data/lib/json-rpc-objects/v11/alt/response.rb +2 -0
  26. data/lib/json-rpc-objects/v11/alt/service-description.rb +45 -0
  27. data/lib/json-rpc-objects/v11/alt/service-procedure-description.rb +58 -0
  28. data/lib/json-rpc-objects/v11/alt/tests/test.rb +39 -0
  29. data/lib/json-rpc-objects/v11/generic-types.rb +52 -0
  30. data/lib/json-rpc-objects/v11/wd/error.rb +172 -0
  31. data/lib/json-rpc-objects/v11/wd/extensions.rb +76 -0
  32. data/lib/json-rpc-objects/v11/wd/fakes/request.rb +33 -0
  33. data/lib/json-rpc-objects/v11/wd/fakes/response.rb +33 -0
  34. data/lib/json-rpc-objects/v11/wd/procedure-call.rb +205 -0
  35. data/lib/json-rpc-objects/v11/wd/procedure-parameter-description.rb +179 -0
  36. data/lib/json-rpc-objects/v11/wd/procedure-return.rb +155 -0
  37. data/lib/json-rpc-objects/v11/wd/request.rb +2 -0
  38. data/lib/json-rpc-objects/v11/wd/response.rb +2 -0
  39. data/lib/json-rpc-objects/v11/wd/service-description.rb +251 -0
  40. data/lib/json-rpc-objects/v11/wd/service-procedure-description.rb +234 -0
  41. data/lib/json-rpc-objects/v11/wd/tests/test.rb +39 -0
  42. data/lib/json-rpc-objects/v20/error.rb +78 -0
  43. data/lib/json-rpc-objects/v20/request.rb +127 -0
  44. data/lib/json-rpc-objects/v20/response.rb +107 -0
  45. data/lib/json-rpc-objects/v20/tests/test.rb +24 -0
  46. data/lib/json-rpc-objects/version.rb +98 -0
  47. metadata +230 -0
@@ -0,0 +1,107 @@
1
+ # encoding: utf-8
2
+ require "multitype-introspection"
3
+ require "json-rpc-objects/v11/alt/procedure-return"
4
+ require "json-rpc-objects/v20/error"
5
+
6
+ ##
7
+ # Main JSON-RPC Objects module.
8
+ #
9
+
10
+ module JsonRpcObjects
11
+
12
+ ##
13
+ # Module of JSON-RPC 2.0.
14
+ # @see http://groups.google.com/group/json-rpc/web/json-rpc-2-0
15
+ #
16
+
17
+ module V20
18
+
19
+ ##
20
+ # Response object class.
21
+ #
22
+
23
+ class Response < JsonRpcObjects::V11::Alt::ProcedureReturn
24
+
25
+ ##
26
+ # Holds link to its version module.
27
+ #
28
+
29
+ VERSION = JsonRpcObjects::V20
30
+
31
+ ##
32
+ # Identifies the error object class.
33
+ #
34
+
35
+ ERROR_CLASS = JsonRpcObjects::V20::Error
36
+
37
+ ##
38
+ # Holds JSON-RPC version specification.
39
+ #
40
+
41
+ VERSION_NUMBER = :"2.0"
42
+
43
+ ##
44
+ # Holds JSON-RPC version member identification.
45
+ #
46
+
47
+ VERSION_MEMBER = :jsonrpc
48
+
49
+ ##
50
+ # Indicates ID has been set.
51
+ #
52
+
53
+ @_id_set
54
+
55
+ ##
56
+ # Checks correctness of the request data.
57
+ #
58
+
59
+ def check!
60
+ super()
61
+
62
+ if not @id.kind_of_any? [String, Integer, NilClass]
63
+ raise Exception::new("ID must contain String, Number or nil if included.")
64
+ end
65
+ end
66
+
67
+ ##
68
+ # Renders data to output hash.
69
+ # @return [Hash] with data of error
70
+ #
71
+
72
+ def output
73
+ result = super()
74
+
75
+ if @_id_set and @id.nil?
76
+ result[:id] = nil
77
+ end
78
+
79
+ return result
80
+ end
81
+
82
+
83
+ protected
84
+
85
+ ##
86
+ # Assigns request data.
87
+ #
88
+
89
+ def data=(value, mode = nil)
90
+ data = __convert_data(value, mode)
91
+ super(data, :converted)
92
+
93
+ # Indicates, ID has been explicitly assigned
94
+ @_id_set = data.include? :id
95
+ end
96
+
97
+ ##
98
+ # Assignes the version specification.
99
+ #
100
+
101
+ def __assign_version(data)
102
+ data[:jsonrpc] = :"2.0"
103
+ end
104
+
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+ $:.push("../../..")
3
+
4
+ require "../request"
5
+ req = JsonRpcObjects::V20::Request::create(:alfa, {:alfa => :beta}, :id => 12345, :"$whatever" => false)
6
+ puts req.to_json
7
+ req = JsonRpcObjects::V20::Request::create(:alfa, [:beta], :"version" => :"1.0")
8
+ puts req.to_json
9
+
10
+ require "../error"
11
+ err = JsonRpcObjects::V20::Error::create(200, "some problem")
12
+
13
+ require "../response"
14
+ res = JsonRpcObjects::V20::Response::create(nil, err, :id => 12345)
15
+ puts res.to_json
16
+ res = JsonRpcObjects::V20::Response::create(true, nil, :id => 12345)
17
+ puts res.to_json
18
+
19
+ require "../../request"
20
+ puts JsonRpcObjects::Request::parse(req.to_json).inspect
21
+ require "../../response"
22
+ puts JsonRpcObjects::Response::parse(res.to_json).inspect
23
+
24
+ puts req.class::version.response::create(25)
@@ -0,0 +1,98 @@
1
+ # encoding: utf-8
2
+
3
+ ##
4
+ # Main JSON-RPC Objects module.
5
+ #
6
+
7
+ module JsonRpcObjects
8
+
9
+ ##
10
+ # Generic version class.
11
+ #
12
+
13
+ class Version
14
+
15
+ ##
16
+ # Holds class name generator for internal use.
17
+ #
18
+
19
+ CLASS_NAME_GENERATOR = /_\w/
20
+
21
+ ##
22
+ # Holds file name generator for internal use.
23
+ #
24
+
25
+ FILE_NAME_GENERATOR = /[a-z0-9][A-Z]/
26
+
27
+ ##
28
+ # Holds version module.
29
+ #
30
+
31
+ @module
32
+
33
+ ##
34
+ # Holds cache of class to module assignments.
35
+ #
36
+
37
+ @@cache = { }
38
+
39
+ ##
40
+ # Returns version object for appropriate version module.
41
+ #
42
+ # @param [Module] mod appropriate version module
43
+ # @return [Version] version object
44
+ #
45
+
46
+ def self.get(mod)
47
+ if not @@cache.include? mod
48
+ @@cache[mod] = self::new(mod)
49
+ end
50
+
51
+ @@cache[mod]
52
+ end
53
+
54
+ ##
55
+ # Handles unknown call as request for appropriate class.
56
+ #
57
+ # Camel case is defined by underscores, so for example <tt>
58
+ # #some_class<tt> will be transformed to <tt>SomeClass</tt>.
59
+ #
60
+ # @param [Symbol] name formatted object name
61
+ # @return [JsonRpcObjects::Generic::Object] object of appropriate version
62
+ #
63
+
64
+ def method_missing(name)
65
+ name = name.to_s
66
+
67
+ # Class name
68
+ class_name = "_" << name
69
+ class_name.gsub!(self.class::CLASS_NAME_GENERATOR) { |s| s[1].chr.upcase }
70
+
71
+ # Module name
72
+ module_name = @module.name.dup << "::" << class_name
73
+
74
+ # File path
75
+ file_path = "x" << module_name
76
+ file_path.gsub!(self.class::FILE_NAME_GENERATOR) { |s| s[0].chr << "-" << s[1].chr }
77
+ file_path.replace(file_path[2..-1])
78
+ file_path.gsub!("::", "/")
79
+ file_path.downcase!
80
+
81
+ require file_path
82
+ return Kernel::eval(module_name)
83
+ end
84
+
85
+
86
+ protected
87
+
88
+ ##
89
+ # Constructor.
90
+ #
91
+
92
+ def initialize(mod)
93
+ @module = mod
94
+ end
95
+
96
+ end
97
+
98
+ end
metadata ADDED
@@ -0,0 +1,230 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: json-rpc-objects
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - "Martin Koz\xC3\xA1k"
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-01-13 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: multitype-introspection
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 1
30
+ - 0
31
+ version: 0.1.0
32
+ type: :runtime
33
+ prerelease: false
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: hash-utils
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ segments:
43
+ - 0
44
+ - 3
45
+ - 0
46
+ version: 0.3.0
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: types
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ segments:
58
+ - 0
59
+ - 1
60
+ - 0
61
+ version: 0.1.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ name: version
67
+ requirement: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ segments:
73
+ - 0
74
+ - 9
75
+ - 2
76
+ version: 0.9.2
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: *id004
80
+ - !ruby/object:Gem::Dependency
81
+ name: addressable
82
+ requirement: &id005 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ segments:
88
+ - 2
89
+ - 2
90
+ - 2
91
+ version: 2.2.2
92
+ type: :runtime
93
+ prerelease: false
94
+ version_requirements: *id005
95
+ - !ruby/object:Gem::Dependency
96
+ name: yajl-ruby
97
+ requirement: &id006 !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ segments:
103
+ - 0
104
+ - 7
105
+ - 8
106
+ version: 0.7.8
107
+ type: :runtime
108
+ prerelease: false
109
+ version_requirements: *id006
110
+ - !ruby/object:Gem::Dependency
111
+ name: bundler
112
+ requirement: &id007 !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ segments:
118
+ - 1
119
+ - 0
120
+ - 0
121
+ version: 1.0.0
122
+ type: :development
123
+ prerelease: false
124
+ version_requirements: *id007
125
+ - !ruby/object:Gem::Dependency
126
+ name: jeweler
127
+ requirement: &id008 !ruby/object:Gem::Requirement
128
+ none: false
129
+ requirements:
130
+ - - ~>
131
+ - !ruby/object:Gem::Version
132
+ segments:
133
+ - 1
134
+ - 5
135
+ - 2
136
+ version: 1.5.2
137
+ type: :development
138
+ prerelease: false
139
+ version_requirements: *id008
140
+ description:
141
+ email: martinkozak@martinkozak.net
142
+ executables: []
143
+
144
+ extensions: []
145
+
146
+ extra_rdoc_files:
147
+ - LICENSE.txt
148
+ - README.md
149
+ files:
150
+ - .document
151
+ - Gemfile
152
+ - Gemfile.lock
153
+ - LICENSE.txt
154
+ - README.md
155
+ - Rakefile
156
+ - VERSION
157
+ - json-rpc-objects.gemspec
158
+ - lib/json-rpc-objects/error.rb
159
+ - lib/json-rpc-objects/generic.rb
160
+ - lib/json-rpc-objects/request.rb
161
+ - lib/json-rpc-objects/response.rb
162
+ - lib/json-rpc-objects/v10/error.rb
163
+ - lib/json-rpc-objects/v10/fakes/error.rb
164
+ - lib/json-rpc-objects/v10/request.rb
165
+ - lib/json-rpc-objects/v10/response.rb
166
+ - lib/json-rpc-objects/v10/tests/test.rb
167
+ - lib/json-rpc-objects/v11/alt/error.rb
168
+ - lib/json-rpc-objects/v11/alt/fakes/request.rb
169
+ - lib/json-rpc-objects/v11/alt/fakes/response.rb
170
+ - lib/json-rpc-objects/v11/alt/procedure-call.rb
171
+ - lib/json-rpc-objects/v11/alt/procedure-parameter-description.rb
172
+ - lib/json-rpc-objects/v11/alt/procedure-return.rb
173
+ - lib/json-rpc-objects/v11/alt/request.rb
174
+ - lib/json-rpc-objects/v11/alt/response.rb
175
+ - lib/json-rpc-objects/v11/alt/service-description.rb
176
+ - lib/json-rpc-objects/v11/alt/service-procedure-description.rb
177
+ - lib/json-rpc-objects/v11/alt/tests/test.rb
178
+ - lib/json-rpc-objects/v11/generic-types.rb
179
+ - lib/json-rpc-objects/v11/wd/error.rb
180
+ - lib/json-rpc-objects/v11/wd/extensions.rb
181
+ - lib/json-rpc-objects/v11/wd/fakes/request.rb
182
+ - lib/json-rpc-objects/v11/wd/fakes/response.rb
183
+ - lib/json-rpc-objects/v11/wd/procedure-call.rb
184
+ - lib/json-rpc-objects/v11/wd/procedure-parameter-description.rb
185
+ - lib/json-rpc-objects/v11/wd/procedure-return.rb
186
+ - lib/json-rpc-objects/v11/wd/request.rb
187
+ - lib/json-rpc-objects/v11/wd/response.rb
188
+ - lib/json-rpc-objects/v11/wd/service-description.rb
189
+ - lib/json-rpc-objects/v11/wd/service-procedure-description.rb
190
+ - lib/json-rpc-objects/v11/wd/tests/test.rb
191
+ - lib/json-rpc-objects/v20/error.rb
192
+ - lib/json-rpc-objects/v20/request.rb
193
+ - lib/json-rpc-objects/v20/response.rb
194
+ - lib/json-rpc-objects/v20/tests/test.rb
195
+ - lib/json-rpc-objects/version.rb
196
+ has_rdoc: true
197
+ homepage: http://github.com/martinkozak/json-rpc-objects
198
+ licenses:
199
+ - MIT
200
+ post_install_message:
201
+ rdoc_options: []
202
+
203
+ require_paths:
204
+ - lib
205
+ required_ruby_version: !ruby/object:Gem::Requirement
206
+ none: false
207
+ requirements:
208
+ - - ">="
209
+ - !ruby/object:Gem::Version
210
+ hash: -3503757597753248663
211
+ segments:
212
+ - 0
213
+ version: "0"
214
+ required_rubygems_version: !ruby/object:Gem::Requirement
215
+ none: false
216
+ requirements:
217
+ - - ">="
218
+ - !ruby/object:Gem::Version
219
+ segments:
220
+ - 0
221
+ version: "0"
222
+ requirements: []
223
+
224
+ rubyforge_project:
225
+ rubygems_version: 1.3.7
226
+ signing_key:
227
+ specification_version: 3
228
+ 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.
229
+ test_files: []
230
+