json-rpc-objects 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.txt ADDED
@@ -0,0 +1,25 @@
1
+
2
+ 0.3.0
3
+ * #error? response method
4
+ * non-fake request, response and error classes (including ProcedureCall
5
+ and ProcedureReturn classes of sure) have generic marking Request,
6
+ Response and Error parent classes
7
+ * fake 1.1 request, response and error classes are parent classes of the
8
+ appropriate 2.0 classes
9
+ * correct error inheritance from 1.1 to 1.0
10
+
11
+ 0.2.0 (2011-01-30)
12
+ * high level modules now aren't modules, but constants linking to appropriate classes
13
+
14
+ 0.1.3 (2011-01-18)
15
+ * 'version' gem dependency removed
16
+
17
+ 0.1.2 (2011-01-16)
18
+ * compatibility problem in 1.0 fake error class
19
+ * high level error module returned 1.1 instead of 2.0 error
20
+
21
+ 0.1.1 (2011-01-16)
22
+ * bug in 1.1/2.0 response error assignment
23
+
24
+ 0.1.0 (2011-01-13)
25
+ * initial version
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{json-rpc-objects}
8
- s.version = "0.2.0"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Martin Kozák"]
12
- s.date = %q{2011-01-30}
12
+ s.date = %q{2011-02-01}
13
13
  s.email = %q{martinkozak@martinkozak.net}
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE.txt",
@@ -17,6 +17,7 @@ Gem::Specification.new do |s|
17
17
  ]
18
18
  s.files = [
19
19
  ".document",
20
+ "CHANGES.txt",
20
21
  "Gemfile",
21
22
  "Gemfile.lock",
22
23
  "LICENSE.txt",
@@ -26,10 +27,13 @@ Gem::Specification.new do |s|
26
27
  "json-rpc-objects.gemspec",
27
28
  "lib/json-rpc-objects/error.rb",
28
29
  "lib/json-rpc-objects/generic.rb",
30
+ "lib/json-rpc-objects/generic/error.rb",
31
+ "lib/json-rpc-objects/generic/object.rb",
32
+ "lib/json-rpc-objects/generic/request.rb",
33
+ "lib/json-rpc-objects/generic/response.rb",
29
34
  "lib/json-rpc-objects/request.rb",
30
35
  "lib/json-rpc-objects/response.rb",
31
36
  "lib/json-rpc-objects/v10/error.rb",
32
- "lib/json-rpc-objects/v10/fakes/error.rb",
33
37
  "lib/json-rpc-objects/v10/request.rb",
34
38
  "lib/json-rpc-objects/v10/response.rb",
35
39
  "lib/json-rpc-objects/v10/tests/test.rb",
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+ require "json-rpc-objects/generic/object"
3
+
4
+ ##
5
+ # Main JSON-RPC Objects module.
6
+ #
7
+
8
+ module JsonRpcObjects
9
+
10
+ ##
11
+ # Module for generic object methods.
12
+ #
13
+
14
+ module Generic
15
+
16
+ ##
17
+ # Generic JSON-RPC error.
18
+ #
19
+ # @since 0.3.0
20
+ # @abstract
21
+ #
22
+
23
+ class Error < Object
24
+ end
25
+
26
+ end
27
+ 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
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+ require "json-rpc-objects/generic/object"
3
+
4
+ ##
5
+ # Main JSON-RPC Objects module.
6
+ #
7
+
8
+ module JsonRpcObjects
9
+
10
+ ##
11
+ # Module for generic object methods.
12
+ #
13
+
14
+ module Generic
15
+
16
+ ##
17
+ # Generic JSON-RPC request.
18
+ #
19
+ # @since 0.3.0
20
+ # @abstract
21
+ #
22
+
23
+ class Request < Object
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+ require "json-rpc-objects/generic/object"
3
+
4
+ ##
5
+ # Main JSON-RPC Objects module.
6
+ #
7
+
8
+ module JsonRpcObjects
9
+
10
+ ##
11
+ # Module for generic object methods.
12
+ #
13
+
14
+ module Generic
15
+
16
+ ##
17
+ # Generic JSON-RPC response.
18
+ #
19
+ # @since 0.3.0
20
+ # @abstract
21
+ #
22
+
23
+ class Response < Object
24
+ end
25
+
26
+ end
27
+ end
@@ -1,144 +1,5 @@
1
1
  # encoding: utf-8
2
- require "hash-utils"
3
- require "yajl/json_gem"
4
- require "json-rpc-objects/version"
2
+ # @deprecated (since 0.3.0)
5
3
 
6
- ##
7
- # Main JSON-RPC Objects module.
8
- #
4
+ require "json-rpc-objects/generic/object"
9
5
 
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
@@ -1,2 +1,80 @@
1
1
  # encoding: utf-8
2
- require "json-rpc-objects/v10/fakes/error"
2
+ require "json-rpc-objects/generic/error"
3
+
4
+ ##
5
+ # Main JSON-RPC Objects module.
6
+ #
7
+
8
+ module JsonRpcObjects
9
+
10
+ ##
11
+ # Module of JSON-RPC 1.0.
12
+ # @see http://json-rpc.org/wiki/specification
13
+ #
14
+
15
+ module V10
16
+
17
+ ##
18
+ # In fact, fake error class.
19
+ #
20
+
21
+ class Error < JsonRpcObjects::Generic::Error
22
+
23
+ ##
24
+ # Holds request method name.
25
+ #
26
+
27
+ @data
28
+ attr_accessor :data
29
+
30
+ ##
31
+ # Holds link to its version module.
32
+ #
33
+
34
+ VERSION = JsonRpcObjects::V10
35
+
36
+ ##
37
+ # Creates new one.
38
+ #
39
+ # @param [Object] data error data
40
+ # @return [JsonRpcObjects::V10::Error] new object
41
+ #
42
+
43
+ def self.create(code, message = nil, opts = { })
44
+ if message.nil? and opts.empty?
45
+ data = code
46
+ elsif not opts.empty?
47
+ data = {
48
+ :message => message,
49
+ :data => opts
50
+ }
51
+ elsif
52
+ data = message
53
+ end
54
+
55
+ self::new(data)
56
+ end
57
+
58
+ ##
59
+ # Renders data to output form.
60
+ # @return [Object] with data of object
61
+ #
62
+
63
+ def output
64
+ @data
65
+ end
66
+
67
+
68
+ protected
69
+
70
+ ##
71
+ # Assigns request data.
72
+ #
73
+
74
+ def data=(value, mode = nil)
75
+ @data = value
76
+ end
77
+
78
+ end
79
+ end
80
+ end
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- require "json-rpc-objects/generic"
2
+ require "json-rpc-objects/generic/request"
3
3
 
4
4
  ##
5
5
  # Main JSON-RPC Objects module.
@@ -18,7 +18,7 @@ module JsonRpcObjects
18
18
  # Request object class.
19
19
  #
20
20
 
21
- class Request < JsonRpcObjects::Generic::Object
21
+ class Request < JsonRpcObjects::Generic::Request
22
22
 
23
23
  ##
24
24
  # Holds link to its version module.
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- require "json-rpc-objects/generic"
2
+ require "json-rpc-objects/generic/response"
3
3
  require "json-rpc-objects/v10/error"
4
4
 
5
5
  ##
@@ -19,7 +19,7 @@ module JsonRpcObjects
19
19
  # Response object class.
20
20
  #
21
21
 
22
- class Response < JsonRpcObjects::Generic::Object
22
+ class Response < JsonRpcObjects::Generic::Response
23
23
 
24
24
  ##
25
25
  # Holds link to its version module.
@@ -110,6 +110,17 @@ module JsonRpcObjects
110
110
  @result = result
111
111
  end
112
112
 
113
+ ##
114
+ # Indicates, response is error.
115
+ #
116
+ # @return [Boolean] +true+ if it's, +false+ otherwise
117
+ # @since 0.3.0
118
+ #
119
+
120
+ def error?
121
+ not @error.nil?
122
+ end
123
+
113
124
 
114
125
  protected
115
126
 
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  require "hash-utils/hash"
3
- require "json-rpc-objects/v11/wd/procedure-call"
3
+ require "json-rpc-objects/v11/wd/request"
4
4
 
5
5
  ##
6
6
  # Main JSON-RPC Objects module.
@@ -25,7 +25,7 @@ module JsonRpcObjects
25
25
  # Procedure call (request) class.
26
26
  #
27
27
 
28
- class ProcedureCall < JsonRpcObjects::V11::WD::ProcedureCall
28
+ class ProcedureCall < JsonRpcObjects::V11::WD::Request
29
29
 
30
30
  ##
31
31
  # Holds link to its version module.
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  require "json-rpc-objects/v11/alt/error"
3
- require "json-rpc-objects/v11/wd/procedure-return"
3
+ require "json-rpc-objects/v11/wd/response"
4
4
 
5
5
  ##
6
6
  # Main JSON-RPC Objects module.
@@ -25,7 +25,7 @@ module JsonRpcObjects
25
25
  # Procedure return (response) class.
26
26
  #
27
27
 
28
- class ProcedureReturn < JsonRpcObjects::V11::WD::ProcedureReturn
28
+ class ProcedureReturn < JsonRpcObjects::V11::WD::Response
29
29
 
30
30
  ##
31
31
  # Holds link to its version module.
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require "hash-utils/numeric"
3
3
  require "json-rpc-objects/generic"
4
+ require "json-rpc-objects/v10/error"
4
5
  require "json-rpc-objects/v11/wd/extensions"
5
6
 
6
7
  ##
@@ -26,7 +27,7 @@ module JsonRpcObjects
26
27
  # Error description object class for ProcedureReturn.
27
28
  #
28
29
 
29
- class Error < JsonRpcObjects::Generic::Object
30
+ class Error < JsonRpcObjects::V10::Error
30
31
 
31
32
  include Extensions
32
33
 
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require "multitype-introspection"
3
3
  require "hash-utils/hash"
4
- require "json-rpc-objects/v11/alt/procedure-call"
4
+ require "json-rpc-objects/v11/alt/request"
5
5
 
6
6
  ##
7
7
  # Main JSON-RPC Objects module.
@@ -20,7 +20,7 @@ module JsonRpcObjects
20
20
  # Request object class.
21
21
  #
22
22
 
23
- class Request < JsonRpcObjects::V11::Alt::ProcedureCall
23
+ class Request < JsonRpcObjects::V11::Alt::Request
24
24
 
25
25
  ##
26
26
  # Holds link to its version module.
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  require "multitype-introspection"
3
- require "json-rpc-objects/v11/alt/procedure-return"
3
+ require "json-rpc-objects/v11/alt/response"
4
4
  require "json-rpc-objects/v20/error"
5
5
 
6
6
  ##
@@ -20,7 +20,7 @@ module JsonRpcObjects
20
20
  # Response object class.
21
21
  #
22
22
 
23
- class Response < JsonRpcObjects::V11::Alt::ProcedureReturn
23
+ class Response < JsonRpcObjects::V11::Alt::Response
24
24
 
25
25
  ##
26
26
  # Holds link to its version module.
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 2
7
+ - 3
8
8
  - 0
9
- version: 0.2.0
9
+ version: 0.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - "Martin Koz\xC3\xA1k"
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-01-30 00:00:00 +01:00
17
+ date: 2011-02-01 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -133,6 +133,7 @@ extra_rdoc_files:
133
133
  - README.md
134
134
  files:
135
135
  - .document
136
+ - CHANGES.txt
136
137
  - Gemfile
137
138
  - Gemfile.lock
138
139
  - LICENSE.txt
@@ -142,10 +143,13 @@ files:
142
143
  - json-rpc-objects.gemspec
143
144
  - lib/json-rpc-objects/error.rb
144
145
  - lib/json-rpc-objects/generic.rb
146
+ - lib/json-rpc-objects/generic/error.rb
147
+ - lib/json-rpc-objects/generic/object.rb
148
+ - lib/json-rpc-objects/generic/request.rb
149
+ - lib/json-rpc-objects/generic/response.rb
145
150
  - lib/json-rpc-objects/request.rb
146
151
  - lib/json-rpc-objects/response.rb
147
152
  - lib/json-rpc-objects/v10/error.rb
148
- - lib/json-rpc-objects/v10/fakes/error.rb
149
153
  - lib/json-rpc-objects/v10/request.rb
150
154
  - lib/json-rpc-objects/v10/response.rb
151
155
  - lib/json-rpc-objects/v10/tests/test.rb
@@ -192,7 +196,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
192
196
  requirements:
193
197
  - - ">="
194
198
  - !ruby/object:Gem::Version
195
- hash: 223533265713224733
199
+ hash: -3073341896383133206
196
200
  segments:
197
201
  - 0
198
202
  version: "0"
@@ -1,80 +0,0 @@
1
- # encoding: utf-8
2
- require "json-rpc-objects/generic"
3
-
4
- ##
5
- # Main JSON-RPC Objects module.
6
- #
7
-
8
- module JsonRpcObjects
9
-
10
- ##
11
- # Module of JSON-RPC 1.0.
12
- # @see http://json-rpc.org/wiki/specification
13
- #
14
-
15
- module V10
16
-
17
- ##
18
- # In fact, fake error class.
19
- #
20
-
21
- class Error < JsonRpcObjects::Generic::Object
22
-
23
- ##
24
- # Holds link to its version module.
25
- #
26
-
27
- VERSION = JsonRpcObjects::V10
28
-
29
- ##
30
- # Creates new one.
31
- #
32
- # @param [Object] data error data
33
- # @return [JsonRpcObjects::V10::Error] new object
34
- #
35
-
36
- def self.create(code, message = nil, opts = { })
37
- if message.nil? and opts.empty?
38
- data = code
39
- elsif not opts.empty?
40
- data = {
41
- :message => message,
42
- :data => opts
43
- }
44
- elsif
45
- data = message
46
- end
47
-
48
- self::new(data)
49
- end
50
-
51
- ##
52
- # Holds request method name.
53
- #
54
-
55
- @data
56
- attr_accessor :data
57
-
58
- ##
59
- # Renders data to output form.
60
- # @return [Object] with data of object
61
- #
62
-
63
- def output
64
- @data
65
- end
66
-
67
-
68
- protected
69
-
70
- ##
71
- # Assigns request data.
72
- #
73
-
74
- def data=(value, mode = nil)
75
- @data = value
76
- end
77
-
78
- end
79
- end
80
- end