json-rpc-objects 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGES.txt +5 -0
  3. data/Gemfile +3 -1
  4. data/Gemfile.lock +63 -12
  5. data/LICENSE.txt +1 -1
  6. data/README.md +40 -41
  7. data/Rakefile +2 -2
  8. data/VERSION +1 -1
  9. data/json-rpc-objects.gemspec +25 -11
  10. data/lib/json-rpc-objects/error.rb +1 -1
  11. data/lib/json-rpc-objects/exceptions/invalid-code.rb +25 -0
  12. data/lib/json-rpc-objects/generic.rb +2 -2
  13. data/lib/json-rpc-objects/generic/error.rb +1 -1
  14. data/lib/json-rpc-objects/generic/object.rb +4 -5
  15. data/lib/json-rpc-objects/generic/request.rb +1 -1
  16. data/lib/json-rpc-objects/generic/response.rb +1 -1
  17. data/lib/json-rpc-objects/request.rb +4 -5
  18. data/lib/json-rpc-objects/response.rb +3 -4
  19. data/lib/json-rpc-objects/serializer.rb +1 -2
  20. data/lib/json-rpc-objects/serializer/marshal.rb +1 -1
  21. data/lib/json-rpc-objects/serializer/none.rb +1 -1
  22. data/lib/json-rpc-objects/utils.rb +6 -0
  23. data/lib/json-rpc-objects/utils/hash.rb +198 -0
  24. data/lib/json-rpc-objects/utils/object.rb +85 -0
  25. data/lib/json-rpc-objects/utils/string.rb +46 -0
  26. data/lib/json-rpc-objects/v10/error.rb +1 -1
  27. data/lib/json-rpc-objects/v10/request.rb +4 -5
  28. data/lib/json-rpc-objects/v10/response.rb +1 -1
  29. data/lib/json-rpc-objects/v10/tests/test.rb +1 -1
  30. data/lib/json-rpc-objects/v11/alt/error.rb +1 -1
  31. data/lib/json-rpc-objects/v11/alt/fakes/request.rb +1 -2
  32. data/lib/json-rpc-objects/v11/alt/fakes/response.rb +1 -2
  33. data/lib/json-rpc-objects/v11/alt/procedure-call.rb +4 -4
  34. data/lib/json-rpc-objects/v11/alt/procedure-parameter-description.rb +1 -1
  35. data/lib/json-rpc-objects/v11/alt/procedure-return.rb +2 -1
  36. data/lib/json-rpc-objects/v11/alt/request.rb +1 -1
  37. data/lib/json-rpc-objects/v11/alt/response.rb +1 -1
  38. data/lib/json-rpc-objects/v11/alt/service-description.rb +1 -1
  39. data/lib/json-rpc-objects/v11/alt/service-procedure-description.rb +2 -4
  40. data/lib/json-rpc-objects/v11/alt/tests/test.rb +1 -1
  41. data/lib/json-rpc-objects/v11/generic-types.rb +1 -1
  42. data/lib/json-rpc-objects/v11/wd/error.rb +5 -6
  43. data/lib/json-rpc-objects/v11/wd/extensions.rb +1 -1
  44. data/lib/json-rpc-objects/v11/wd/fakes/request.rb +1 -2
  45. data/lib/json-rpc-objects/v11/wd/fakes/response.rb +1 -2
  46. data/lib/json-rpc-objects/v11/wd/procedure-call.rb +13 -15
  47. data/lib/json-rpc-objects/v11/wd/procedure-parameter-description.rb +8 -8
  48. data/lib/json-rpc-objects/v11/wd/procedure-return.rb +4 -5
  49. data/lib/json-rpc-objects/v11/wd/request.rb +1 -1
  50. data/lib/json-rpc-objects/v11/wd/response.rb +1 -1
  51. data/lib/json-rpc-objects/v11/wd/service-description.rb +6 -8
  52. data/lib/json-rpc-objects/v11/wd/service-procedure-description.rb +8 -10
  53. data/lib/json-rpc-objects/v11/wd/tests/test.rb +1 -1
  54. data/lib/json-rpc-objects/v20/error.rb +6 -4
  55. data/lib/json-rpc-objects/v20/request.rb +6 -6
  56. data/lib/json-rpc-objects/v20/response.rb +2 -2
  57. data/lib/json-rpc-objects/v20/tests/test.rb +2 -2
  58. data/lib/json-rpc-objects/version.rb +18 -6
  59. data/spec/request_spec.rb +11 -0
  60. data/spec/spec_helper.rb +18 -0
  61. metadata +69 -51
@@ -1,9 +1,7 @@
1
1
  # encoding: utf-8
2
- # (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
2
+ # (c) 2011-2015 Martin Poljak (martin@poljak.cz)
3
3
 
4
4
  require "addressable/uri"
5
- require "hash-utils/array"
6
- require "hash-utils/object"
7
5
  require "json-rpc-objects/v11/wd/procedure-parameter-description"
8
6
  require "json-rpc-objects/generic"
9
7
 
@@ -113,16 +111,16 @@ module JsonRpcObjects
113
111
  def check!
114
112
  self.normalize!
115
113
 
116
- if not @name.symbol?
114
+ if not @name.kind_of? Symbol
117
115
  raise Exception::new("Procedure name must be Symbol or convertable to Symbol.")
118
116
  end
119
117
 
120
118
  if not @params.nil?
121
- if (not @params.array?) or (not @params.all? { |v| v.kind_of? self.class::PARAMETER_DESCRIPTION_CLASS })
119
+ if (not @params.kind_of? Array) or (not @params.all? { |v| v.kind_of? self.class::PARAMETER_DESCRIPTION_CLASS })
122
120
  raise Exception::new("If params is defined, must be an Array of " << self.class::PARAMETER_DESCRIPTION_CLASS.name << " objects.")
123
121
  end
124
122
 
125
- if @params.array?
123
+ if @params.kind_of? Array
126
124
  @params.each { |param| param.check! }
127
125
  end
128
126
  end
@@ -135,7 +133,7 @@ module JsonRpcObjects
135
133
  @return.check!
136
134
  end
137
135
 
138
- if (not @idempotent.nil?) and (not @idempotent.boolean?)
136
+ if (not @idempotent.nil?) and (not Utils::Object.boolean? @idempotent)
139
137
  raise Exception::new("If idempotent is defined, must be boolean.")
140
138
  end
141
139
  end
@@ -208,11 +206,11 @@ module JsonRpcObjects
208
206
  @params = data[:params]
209
207
  @return = data[:return]
210
208
 
211
- if @params.array?
209
+ if @params.kind_of? Array
212
210
  @params = @params.map { |v| self.class::PARAMETER_DESCRIPTION_CLASS::new(v) }
213
211
  end
214
212
 
215
- if @return.hash?
213
+ if @return.kind_of? Hash
216
214
  @return = self.class::PARAMETER_DESCRIPTION_CLASS::new(@return)
217
215
  end
218
216
  end
@@ -222,7 +220,7 @@ module JsonRpcObjects
222
220
  #
223
221
 
224
222
  def normalize!
225
- if @name.string?
223
+ if @name.kind_of? String
226
224
  @name = @name.to_sym
227
225
  end
228
226
 
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- # (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
2
+ # (c) 2011-2015 Martin Poljak (martin@poljak.cz)
3
3
 
4
4
  $:.push("../../../..")
5
5
 
@@ -1,8 +1,8 @@
1
1
  # encoding: utf-8
2
- # (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
2
+ # (c) 2011-2015 Martin Poljak (martin@poljak.cz)
3
3
 
4
- require "hash-utils/numeric"
5
4
  require "json-rpc-objects/v11/alt/error"
5
+ require "json-rpc-objects/exceptions/invalid-code"
6
6
 
7
7
  ##
8
8
  # Main JSON-RPC Objects module.
@@ -42,8 +42,10 @@ module JsonRpcObjects
42
42
  def check!
43
43
  self.normalize!
44
44
 
45
- if (@code.in? -32768..-32000) and not ((@code == -32700) or (@code.in? -32603..-32600) or (@code.in? -32099..-32000))
46
- raise Exception::new("Code is invalid because of reserved space.")
45
+ if ((-32768..-32000).include?(@code)) and not ((@code == -32700) or
46
+ ((-32603..-32600).include?(@code)) or ((-32099..-32000).include?(code)))
47
+
48
+ raise JsonRpcObjects::Exceptions::InvalidCode::new("Code is invalid because of reserved space.")
47
49
  end
48
50
  end
49
51
 
@@ -1,8 +1,8 @@
1
1
  # encoding: utf-8
2
- # (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
2
+ # (c) 2011-2015 Martin Poljak (martin@poljak.cz)
3
3
 
4
- require "hash-utils/hash"
5
4
  require "json-rpc-objects/v11/alt/request"
5
+ require "json-rpc-objects/utils"
6
6
 
7
7
  ##
8
8
  # Main JSON-RPC Objects module.
@@ -54,7 +54,7 @@ module JsonRpcObjects
54
54
  def check!
55
55
  super()
56
56
 
57
- if not @id.kind_of_any? [Symbol, String, Integer, NilClass]
57
+ if not [Symbol, String, Integer, NilClass].any?{ |cl| @id.kind_of?(cl) }
58
58
  raise Exception::new("ID must contain Symbol, String, Number or nil if included.")
59
59
  end
60
60
  end
@@ -105,8 +105,8 @@ module JsonRpcObjects
105
105
  #
106
106
 
107
107
  def __get_params(data)
108
- if @params.hash?
109
- @keyword_params = @params.keys_to_sym
108
+ if @params.kind_of?(Hash)
109
+ @keyword_params = Utils::Hash.keys_to_sym(@params)
110
110
  @params = nil
111
111
  end
112
112
  end
@@ -119,7 +119,7 @@ module JsonRpcObjects
119
119
  if not @params.nil? and not @params.empty?
120
120
  data[:params] = @params
121
121
  elsif not @keyword_params.nil? and not @keyword_params.empty?
122
- data[:params] = @keyword_params.map_keys { |k| k.to_s }
122
+ data[:params] = Utils::Hash.map_keys(@keyword_params) { |k| k.to_s }
123
123
  end
124
124
  end
125
125
 
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- # (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
2
+ # (c) 2011-2015 Martin Poljak (martin@poljak.cz)
3
3
 
4
4
  require "json-rpc-objects/v11/alt/response"
5
5
  require "json-rpc-objects/v20/error"
@@ -60,7 +60,7 @@ module JsonRpcObjects
60
60
  def check!
61
61
  super()
62
62
 
63
- if not @id.kind_of_any? [Symbol, String, Integer, NilClass]
63
+ if not [Symbol, String, Integer, NilClass].any?{ |cl| @id.kind_of?(cl) }
64
64
  raise Exception::new("ID must contain Symbol, String, Number or nil if included.")
65
65
  end
66
66
  end
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- # (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
2
+ # (c) 2011-2015 Martin Poljak (martin@poljak.cz)
3
3
 
4
4
  $:.push("../../..")
5
5
 
@@ -19,7 +19,7 @@ puts res.serialize
19
19
  require "../request"
20
20
  req = JsonRpcObjects::V20::Request::create(:alfa, [:beta], :"version" => :"1.0")
21
21
  puts req.serialize
22
- req = JsonRpcObjects::V20::Request::create(:alfa, {:alfa => :beta}, :id => :"12345", :"$whatever" => false)
22
+ req = JsonRpcObjects::V20::Request::create(:alfa, {:alfa => :beta}, :id => :"12345", :$whatever => false)
23
23
  puts req.serialize
24
24
 
25
25
  require "../../request"
@@ -1,8 +1,5 @@
1
1
  # encoding: utf-8
2
- # (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
3
-
4
- require "hash-utils/object"
5
- require "hash-utils/module"
2
+ # (c) 2011-2015 Martin Poljak (martin@poljak.cz)
6
3
 
7
4
  ##
8
5
  # Main JSON-RPC Objects module.
@@ -54,7 +51,7 @@ module JsonRpcObjects
54
51
  #
55
52
 
56
53
  def self.get(mod)
57
- if not mod.in? @@cache
54
+ if not @@cache.include? mod
58
55
  @@cache[mod] = self::new(mod)
59
56
  end
60
57
 
@@ -93,7 +90,7 @@ module JsonRpcObjects
93
90
  @@files[file_path] = true
94
91
  end
95
92
 
96
- return Module.get_module(module_name)
93
+ return __get_module(module_name)
97
94
  end
98
95
 
99
96
 
@@ -107,6 +104,21 @@ module JsonRpcObjects
107
104
  @module = mod
108
105
  end
109
106
 
107
+
108
+ private
109
+
110
+ def __get_module(name)
111
+ names = name.split("::")
112
+ mod = ::Module
113
+
114
+ while not names.empty?
115
+ name = names.shift
116
+ mod = mod.const_get(name)
117
+ end
118
+
119
+ return mod
120
+ end
121
+
110
122
  end
111
123
 
112
124
  end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+ require 'json-rpc-objects/request'
3
+
4
+ describe JsonRpcObjects::Request do
5
+ describe "#parse" do
6
+ let(:json) { '{"jsonrpc":"2.0","method":"sum","params":[1,2],"id":"cbf5d56b"}' }
7
+ subject(:request) { described_class.parse(json) }
8
+ its(:method) { should == :sum }
9
+ its(:params) { should == [1,2] }
10
+ end
11
+ end
@@ -0,0 +1,18 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ require 'rspec/its'
8
+
9
+ RSpec.configure do |config|
10
+ config.run_all_when_everything_filtered = true
11
+ config.filter_run :focus
12
+
13
+ # Run specs in random order to surface order dependencies. If you find an
14
+ # order dependency and want to debug it, you can fix the order by providing
15
+ # the seed, which is printed after each run.
16
+ # --seed 1234
17
+ config.order = 'random'
18
+ end
metadata CHANGED
@@ -1,121 +1,136 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json-rpc-objects
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
5
- prerelease:
4
+ version: 0.4.4
6
5
  platform: ruby
7
6
  authors:
8
- - Martin Kozák
7
+ - Martin Poljak
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-05-06 00:00:00.000000000 Z
11
+ date: 2015-08-15 00:00:00.000000000 Z
13
12
  dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: hash-utils
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - '>='
20
- - !ruby/object:Gem::Version
21
- version: 0.18.0
22
- type: :runtime
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - '>='
28
- - !ruby/object:Gem::Version
29
- version: 0.18.0
30
13
  - !ruby/object:Gem::Dependency
31
14
  name: addressable
32
15
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
16
  requirements:
35
- - - '>='
17
+ - - ">="
36
18
  - !ruby/object:Gem::Version
37
19
  version: 2.2.2
38
20
  type: :runtime
39
21
  prerelease: false
40
22
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
23
  requirements:
43
- - - '>='
24
+ - - ">="
44
25
  - !ruby/object:Gem::Version
45
26
  version: 2.2.2
46
27
  - !ruby/object:Gem::Dependency
47
28
  name: abstract
48
29
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
30
  requirements:
51
- - - '>='
31
+ - - ">="
52
32
  - !ruby/object:Gem::Version
53
33
  version: 1.0.0
54
34
  type: :runtime
55
35
  prerelease: false
56
36
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
37
  requirements:
59
- - - '>='
38
+ - - ">="
60
39
  - !ruby/object:Gem::Version
61
40
  version: 1.0.0
62
41
  - !ruby/object:Gem::Dependency
63
42
  name: json-rpc-objects-json
64
43
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
44
  requirements:
67
- - - '>='
45
+ - - ">="
68
46
  - !ruby/object:Gem::Version
69
47
  version: 0.1.1
70
48
  type: :runtime
71
49
  prerelease: false
72
50
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
51
  requirements:
75
- - - '>='
52
+ - - ">="
76
53
  - !ruby/object:Gem::Version
77
54
  version: 0.1.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: ruby-version
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 0.4.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 0.4.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec-its
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
78
97
  - !ruby/object:Gem::Dependency
79
98
  name: bundler
80
99
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
100
  requirements:
83
- - - '>='
101
+ - - ">="
84
102
  - !ruby/object:Gem::Version
85
103
  version: 1.0.0
86
104
  type: :development
87
105
  prerelease: false
88
106
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
107
  requirements:
91
- - - '>='
108
+ - - ">="
92
109
  - !ruby/object:Gem::Version
93
110
  version: 1.0.0
94
111
  - !ruby/object:Gem::Dependency
95
112
  name: jeweler
96
113
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
114
  requirements:
99
- - - '>='
115
+ - - ">="
100
116
  - !ruby/object:Gem::Version
101
117
  version: 1.5.2
102
118
  type: :development
103
119
  prerelease: false
104
120
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
121
  requirements:
107
- - - '>='
122
+ - - ">="
108
123
  - !ruby/object:Gem::Version
109
124
  version: 1.5.2
110
125
  description:
111
- email: martinkozak@martinkozak.net
126
+ email: martin@poljak.cz
112
127
  executables: []
113
128
  extensions: []
114
129
  extra_rdoc_files:
115
130
  - LICENSE.txt
116
131
  - README.md
117
132
  files:
118
- - .document
133
+ - ".document"
119
134
  - CHANGES.txt
120
135
  - Gemfile
121
136
  - Gemfile.lock
@@ -125,6 +140,7 @@ files:
125
140
  - VERSION
126
141
  - json-rpc-objects.gemspec
127
142
  - lib/json-rpc-objects/error.rb
143
+ - lib/json-rpc-objects/exceptions/invalid-code.rb
128
144
  - lib/json-rpc-objects/generic.rb
129
145
  - lib/json-rpc-objects/generic/error.rb
130
146
  - lib/json-rpc-objects/generic/object.rb
@@ -135,6 +151,10 @@ files:
135
151
  - lib/json-rpc-objects/serializer.rb
136
152
  - lib/json-rpc-objects/serializer/marshal.rb
137
153
  - lib/json-rpc-objects/serializer/none.rb
154
+ - lib/json-rpc-objects/utils.rb
155
+ - lib/json-rpc-objects/utils/hash.rb
156
+ - lib/json-rpc-objects/utils/object.rb
157
+ - lib/json-rpc-objects/utils/string.rb
138
158
  - lib/json-rpc-objects/v10/error.rb
139
159
  - lib/json-rpc-objects/v10/request.rb
140
160
  - lib/json-rpc-objects/v10/response.rb
@@ -168,33 +188,31 @@ files:
168
188
  - lib/json-rpc-objects/v20/response.rb
169
189
  - lib/json-rpc-objects/v20/tests/test.rb
170
190
  - lib/json-rpc-objects/version.rb
191
+ - spec/request_spec.rb
192
+ - spec/spec_helper.rb
171
193
  homepage: http://github.com/martinkozak/json-rpc-objects
172
194
  licenses:
173
195
  - MIT
196
+ metadata: {}
174
197
  post_install_message:
175
198
  rdoc_options: []
176
199
  require_paths:
177
200
  - lib
178
201
  required_ruby_version: !ruby/object:Gem::Requirement
179
- none: false
180
202
  requirements:
181
- - - '>='
203
+ - - ">="
182
204
  - !ruby/object:Gem::Version
183
205
  version: '0'
184
- segments:
185
- - 0
186
- hash: -4582882999797080532
187
206
  required_rubygems_version: !ruby/object:Gem::Requirement
188
- none: false
189
207
  requirements:
190
- - - '>='
208
+ - - ">="
191
209
  - !ruby/object:Gem::Version
192
210
  version: '0'
193
211
  requirements: []
194
212
  rubyforge_project:
195
- rubygems_version: 1.8.23
213
+ rubygems_version: 2.4.5
196
214
  signing_key:
197
- specification_version: 3
215
+ specification_version: 4
198
216
  summary: Implementation of JSON-RPC objects with respect to specifications compliance
199
217
  and API backward compatibility. Implements all versions of the protocol and support
200
218
  for ability to communicate by the same protocol version which other side uses by