jsonrpc2 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/jsonrpc2/html.rb +7 -0
- data/lib/jsonrpc2/types.rb +11 -0
- data/lib/jsonrpc2/version.rb +1 -1
- data/test/test_types.rb +28 -0
- metadata +88 -120
data/lib/jsonrpc2/html.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'cgi'
|
2
|
+
require 'time'
|
2
3
|
module JSONRPC2
|
3
4
|
# HTML output helpers for browseable API interface
|
4
5
|
module HTML
|
@@ -100,6 +101,12 @@ HTML5
|
|
100
101
|
0
|
101
102
|
when /^Array/
|
102
103
|
[]
|
104
|
+
when 'Time'
|
105
|
+
"00:00"
|
106
|
+
when 'DateTime'
|
107
|
+
Time.at(0).iso8601
|
108
|
+
when 'Date'
|
109
|
+
'1970-01-01'
|
103
110
|
else
|
104
111
|
{}
|
105
112
|
end
|
data/lib/jsonrpc2/types.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
1
3
|
module JSONRPC2
|
2
4
|
# Types are checked against textual descriptions of the contents:
|
3
5
|
#
|
@@ -15,6 +17,9 @@ module JSONRPC2
|
|
15
17
|
# * CustomType - A defined custom object type
|
16
18
|
module Types
|
17
19
|
module_function
|
20
|
+
DateTimeRegex = %r"([0-9]{4})(-([0-9]{2})(-([0-9]{2})(T([0-9]{2}):([0-9]{2})(:([0-9]{2})(\.([0-9]+))?)?(Z|(([-+])([0-9]{2}):([0-9]{2})))?)?)?)?"
|
21
|
+
DateRegex = %r'\A\d{4}-\d{2}-\d{2}\z'
|
22
|
+
TimeRegex = %r'\A\d{2}:\d{2}(?:\.\d{1,4})?\z'
|
18
23
|
|
19
24
|
# Checks that object is of given type (and that any custom types
|
20
25
|
# comply with interface)
|
@@ -45,6 +50,12 @@ module JSONRPC2
|
|
45
50
|
object.is_a?(Hash)
|
46
51
|
when 'Array'
|
47
52
|
object.is_a?(Array)
|
53
|
+
when 'Date'
|
54
|
+
object.is_a?(String) && DateRegex.match(object) || object.is_a?(Date)
|
55
|
+
when 'Time'
|
56
|
+
object.is_a?(String) && TimeRegex.match(object) || object.is_a?(Time)
|
57
|
+
when 'DateTime'
|
58
|
+
object.is_a?(String) && DateTimeRegex.match(object) || object.is_a?(Time)
|
48
59
|
when /\AArray\[(.*)\]\z/
|
49
60
|
object.is_a?(Array) && object.all? { |value| valid?(interface, $1, value) }
|
50
61
|
when 'Value', 'Any', 'void'
|
data/lib/jsonrpc2/version.rb
CHANGED
data/test/test_types.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
$: << File.join(File.dirname(__FILE__),'../lib')
|
3
|
+
require 'jsonrpc2/types'
|
4
|
+
|
5
|
+
InterfaceTestContainer = Struct.new("InterfaceTestContainer", :types)
|
6
|
+
|
7
|
+
class TestTypes < Test::Unit::TestCase
|
8
|
+
def setup
|
9
|
+
complex = JSONRPC2::JsonObjectType.new('Complex1',[])
|
10
|
+
complex.string('field1', 'Field 1')
|
11
|
+
|
12
|
+
container = JSONRPC2::JsonObjectType.new('Container', [])
|
13
|
+
container.field('complex', 'Complex', 'Complex field')
|
14
|
+
|
15
|
+
container2 = JSONRPC2::JsonObjectType.new('Container2', [])
|
16
|
+
container2.field('complex', 'Array[Complex]', 'Complex fields')
|
17
|
+
@interface = InterfaceTestContainer.new('Complex' => complex, 'Container' => container, 'Container2' => container2)
|
18
|
+
end
|
19
|
+
def test_complex_types
|
20
|
+
assert(JSONRPC2::Types.valid?(@interface, 'Complex', {'field1' => "Foo"}))
|
21
|
+
assert(! JSONRPC2::Types.valid?(@interface, 'Complex', {'field1' => 3}))
|
22
|
+
|
23
|
+
assert(JSONRPC2::Types.valid?(@interface, 'Container', { 'complex' => { 'field1' => 'Foo' } }))
|
24
|
+
|
25
|
+
assert(JSONRPC2::Types.valid?(@interface, 'Container2', { 'complex' => [{ 'field1' => 'Foo' }] }))
|
26
|
+
assert(!JSONRPC2::Types.valid?(@interface, 'Container2', { 'complex' => [{ 'field1' => false }] }))
|
27
|
+
end
|
28
|
+
end
|
metadata
CHANGED
@@ -1,124 +1,101 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonrpc2
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 5
|
10
|
-
version: 0.0.5
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Geoff Youngs
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-08-24 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
21
15
|
name: httpclient
|
22
|
-
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
24
17
|
none: false
|
25
|
-
requirements:
|
26
|
-
- -
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
segments:
|
30
|
-
- 0
|
31
|
-
version: "0"
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
32
22
|
type: :runtime
|
33
|
-
version_requirements: *id001
|
34
|
-
- !ruby/object:Gem::Dependency
|
35
|
-
name: json
|
36
23
|
prerelease: false
|
37
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: json
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
38
33
|
none: false
|
39
|
-
requirements:
|
40
|
-
- -
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
|
43
|
-
segments:
|
44
|
-
- 0
|
45
|
-
version: "0"
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
46
38
|
type: :runtime
|
47
|
-
version_requirements: *id002
|
48
|
-
- !ruby/object:Gem::Dependency
|
49
|
-
name: RedCloth
|
50
39
|
prerelease: false
|
51
|
-
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: RedCloth
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
52
49
|
none: false
|
53
|
-
requirements:
|
54
|
-
- -
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
|
57
|
-
segments:
|
58
|
-
- 0
|
59
|
-
version: "0"
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
60
54
|
type: :runtime
|
61
|
-
version_requirements: *id003
|
62
|
-
- !ruby/object:Gem::Dependency
|
63
|
-
name: thor
|
64
55
|
prerelease: false
|
65
|
-
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: thor
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
66
65
|
none: false
|
67
|
-
requirements:
|
68
|
-
- -
|
69
|
-
- !ruby/object:Gem::Version
|
70
|
-
|
71
|
-
segments:
|
72
|
-
- 0
|
73
|
-
version: "0"
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
74
70
|
type: :runtime
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
desc 'Add numbers'
|
99
|
-
example "Calculate 1 + 1 = 2", :params => { 'a' => 1, 'b' => 1}, :result => 2
|
100
|
-
|
101
|
-
param 'a', 'Number', 'First number'
|
102
|
-
param 'b', 'Number', 'Second number'
|
103
|
-
optional 'c', 'Number', 'Third number'
|
104
|
-
result 'Number', 'a + b + c'
|
105
|
-
def sum args
|
106
|
-
val = args['a'] + args['b']
|
107
|
-
val += args['c'] if args['c']
|
108
|
-
val
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
email:
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: ! "== Description\n\nA Rack compatible JSON-RPC2 server domain specific
|
79
|
+
language (DSL) - allows JSONRPC APIs to be \ndefined as mountable Rack applications
|
80
|
+
with inline documentation, authentication and type checking.\n\ne.g.\n\n class
|
81
|
+
Calculator < JSONRPC2::Interface\n title \"JSON-RPC2 Calculator\"\n introduction
|
82
|
+
\"This interface allows basic maths calculations via JSON-RPC2\"\n auth_with
|
83
|
+
JSONRPC2::BasicAuth.new({'user' => 'secretword'})\n\n section 'Simple Ops' do\n
|
84
|
+
\ desc 'Multiply two numbers'\n param 'a', 'Number', 'a'\n param
|
85
|
+
'b', 'Number', 'b'\n result 'Number', 'a * b'\n def mul args\n args['a']
|
86
|
+
* args['b']\n end\n\n desc 'Add numbers'\n example \"Calculate
|
87
|
+
1 + 1 = 2\", :params => { 'a' => 1, 'b' => 1}, :result => 2\n\n param 'a',
|
88
|
+
'Number', 'First number'\n param 'b', 'Number', 'Second number'\n optional
|
89
|
+
'c', 'Number', 'Third number'\n result 'Number', 'a + b + c'\n def
|
90
|
+
sum args\n val = args['a'] + args['b']\n val += args['c'] if args['c']\n
|
91
|
+
\ val\n end\n end\n end\n\n"
|
92
|
+
email:
|
114
93
|
- git@intersect-uk.co.uk
|
115
|
-
executables:
|
94
|
+
executables:
|
116
95
|
- jsonrpc2
|
117
96
|
extensions: []
|
118
|
-
|
119
97
|
extra_rdoc_files: []
|
120
|
-
|
121
|
-
files:
|
98
|
+
files:
|
122
99
|
- .gitignore
|
123
100
|
- Gemfile
|
124
101
|
- README.markdown
|
@@ -135,39 +112,30 @@ files:
|
|
135
112
|
- lib/jsonrpc2/textile.rb
|
136
113
|
- lib/jsonrpc2/types.rb
|
137
114
|
- lib/jsonrpc2/version.rb
|
115
|
+
- test/test_types.rb
|
138
116
|
homepage: http://github.com/geoffyoungs/jsonrpc2
|
139
117
|
licenses: []
|
140
|
-
|
141
118
|
post_install_message:
|
142
119
|
rdoc_options: []
|
143
|
-
|
144
|
-
require_paths:
|
120
|
+
require_paths:
|
145
121
|
- lib
|
146
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
147
123
|
none: false
|
148
|
-
requirements:
|
149
|
-
- -
|
150
|
-
- !ruby/object:Gem::Version
|
151
|
-
|
152
|
-
|
153
|
-
- 0
|
154
|
-
version: "0"
|
155
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ! '>='
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
156
129
|
none: false
|
157
|
-
requirements:
|
158
|
-
- -
|
159
|
-
- !ruby/object:Gem::Version
|
160
|
-
|
161
|
-
segments:
|
162
|
-
- 0
|
163
|
-
version: "0"
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
164
134
|
requirements: []
|
165
|
-
|
166
135
|
rubyforge_project:
|
167
|
-
rubygems_version: 1.8.
|
136
|
+
rubygems_version: 1.8.24
|
168
137
|
signing_key:
|
169
138
|
specification_version: 3
|
170
139
|
summary: JSON-RPC2 server DSL
|
171
140
|
test_files: []
|
172
|
-
|
173
141
|
has_rdoc:
|