jsonrpc2 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/test.yml +26 -0
- data/.gitignore +1 -0
- data/.rspec +1 -0
- data/CHANGELOG.md +38 -0
- data/Dockerfile +8 -0
- data/README.markdown +36 -56
- data/bin/run-example +7 -0
- data/bin/setup +3 -0
- data/bin/test +7 -0
- data/example/config.ru +27 -25
- data/{bin → exe}/jsonrpc2 +0 -0
- data/jsonrpc2.gemspec +15 -3
- data/lib/jsonrpc2/html.rb +3 -3
- data/lib/jsonrpc2/interface.rb +309 -289
- data/lib/jsonrpc2/textile.rb +5 -5
- data/lib/jsonrpc2/types.rb +14 -10
- data/lib/jsonrpc2/version.rb +1 -1
- data/spec/lib/interface_spec.rb +162 -0
- data/spec/spec_helper.rb +94 -0
- metadata +133 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6656e3e753bbf3ae9c6d64fc70f1f98ecabe3f8854651d9d4574f6d1b4a3a6c2
|
4
|
+
data.tar.gz: 9ecd6c561d1c037f755331d8ca9c968f085e76479853dccbd239e89cb5e76b84
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00fc45704df91c0a9b836c9ae7167a2117709e52275d47233c44e724b0f245de35ed29f445c2c4b383fc864f14511577f7e49a023d562e6ae753e29ca95114dd
|
7
|
+
data.tar.gz: 76b803ba32848432dee6797b733ce75e775c151a9e1cf18047ce84dbe5aff6c8ea0d62bbb56e55b66f128e81a5522176db331a078b63247014b4270a00078c74
|
@@ -0,0 +1,26 @@
|
|
1
|
+
name: Run automated tests
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- master
|
7
|
+
|
8
|
+
pull_request:
|
9
|
+
|
10
|
+
jobs:
|
11
|
+
build:
|
12
|
+
runs-on: ubuntu-latest
|
13
|
+
name: Ruby ${{ matrix.ruby }}
|
14
|
+
strategy:
|
15
|
+
matrix:
|
16
|
+
ruby: [2.7, 3.0]
|
17
|
+
|
18
|
+
steps:
|
19
|
+
- uses: actions/checkout@v2
|
20
|
+
- name: Set up Ruby
|
21
|
+
uses: ruby/setup-ruby@v1
|
22
|
+
with:
|
23
|
+
ruby-version: ${{ matrix.ruby }}
|
24
|
+
bundler-cache: true
|
25
|
+
- name: Run automated tests
|
26
|
+
run: bundle exec rspec
|
data/.gitignore
CHANGED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
## [0.2.0] - 2022-04-07
|
2
|
+
### Added
|
3
|
+
- Possibility to define callback for server errors with `JSONRPC2::Interface#on_server_error`
|
4
|
+
|
5
|
+
### Fixed
|
6
|
+
- Fixed regression introduced in 0.1.1 which makes the valid requests crash
|
7
|
+
- Stopped exposing application internals publicly on errors
|
8
|
+
|
9
|
+
## [0.1.1] - 2014-01-04
|
10
|
+
### Changed
|
11
|
+
- Improve logging of exceptions / failure
|
12
|
+
|
13
|
+
## [0.1.0] - 2014-01-04
|
14
|
+
### Changed
|
15
|
+
- Turn on timing & logging of all requests
|
16
|
+
|
17
|
+
## [0.0.9] - 2012-09-03
|
18
|
+
### Changed
|
19
|
+
- Improve client validation
|
20
|
+
- Make params optional in request call
|
21
|
+
|
22
|
+
## [0.0.8] - 2012-09-03
|
23
|
+
### Changed
|
24
|
+
- Add #request to access Rack::Request object
|
25
|
+
- Make URLs in HTML interface clickable
|
26
|
+
|
27
|
+
## [0.0.7] - 2012-08-27
|
28
|
+
### Changed
|
29
|
+
- Add bundled Bootstrap assets for HTML test interface
|
30
|
+
|
31
|
+
## [0.0.6] - 2012-08-24
|
32
|
+
### Changed
|
33
|
+
- Add Date/Time/DateTime as special string types with regex checks for validation
|
34
|
+
|
35
|
+
## [0.0.5] - 2012-07-19
|
36
|
+
### Changed
|
37
|
+
- Add commandline client jsonrpc2
|
38
|
+
- Add #auth to access currently authenticated username
|
data/Dockerfile
ADDED
data/README.markdown
CHANGED
@@ -2,32 +2,6 @@
|
|
2
2
|
|
3
3
|
A Rack compatible, documenting JSON-RPC 2 DSL/server implementation for ruby.
|
4
4
|
|
5
|
-
## Changes
|
6
|
-
|
7
|
-
* 0.1.1 - 4-Jan-2013
|
8
|
-
Improve logging of exceptions / failure
|
9
|
-
|
10
|
-
* 0.1.0 - 4-Jan-2013
|
11
|
-
Turn on timing & logging of all requests
|
12
|
-
|
13
|
-
* 0.0.9 - 3-Sep-2012
|
14
|
-
Improve client validation
|
15
|
-
Make params optional in request call
|
16
|
-
|
17
|
-
* 0.0.8 - 3-Sep-2012
|
18
|
-
Add #request to access Rack::Request object
|
19
|
-
Make URLs in HTML interface clickable
|
20
|
-
|
21
|
-
* 0.0.7 - 27-Aug-2012
|
22
|
-
Add bundled Bootstrap assets for HTML test interface
|
23
|
-
|
24
|
-
* 0.0.6 - 24-Aug-2012
|
25
|
-
Add Date/Time/DateTime as special string types with regex checks for validation
|
26
|
-
|
27
|
-
* 0.0.5 - 19-Jul-2012
|
28
|
-
Add commandline client jsonrpc2
|
29
|
-
Add #auth to access currently authenticated username
|
30
|
-
|
31
5
|
## Features
|
32
6
|
|
33
7
|
* Inline documentation
|
@@ -38,42 +12,44 @@ A Rack compatible, documenting JSON-RPC 2 DSL/server implementation for ruby.
|
|
38
12
|
|
39
13
|
## Example
|
40
14
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
15
|
+
```ruby
|
16
|
+
class Calculator < JSONRPC2::Interface
|
17
|
+
title "JSON-RPC2 Calculator"
|
18
|
+
introduction "This interface allows basic maths calculations via JSON-RPC2"
|
19
|
+
auth_with JSONRPC2::BasicAuth.new({'apiuser' => 'secretword'})
|
20
|
+
|
21
|
+
section 'Simple Ops' do
|
22
|
+
desc 'Multiply two numbers'
|
23
|
+
param 'a', 'Number', 'First number'
|
24
|
+
param 'b', 'Number', 'Second number'
|
25
|
+
result 'Number', 'a * b'
|
26
|
+
def mul args
|
27
|
+
args['a'] * args['b']
|
28
|
+
end
|
45
29
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
param 'a', 'Number', 'First number'
|
57
|
-
param 'b', 'Number', 'Second number'
|
58
|
-
optional 'c', 'Number', 'Third number'
|
59
|
-
example 'Calculate 1 + 1', :params => { 'a' => 1, 'b' => 1}, :result => 2
|
60
|
-
result 'Number', 'a + b + c'
|
61
|
-
def sum args
|
62
|
-
val = args['a'] + args['b']
|
63
|
-
val += args['c'] if args['c']
|
64
|
-
val
|
65
|
-
end
|
30
|
+
desc 'Add numbers'
|
31
|
+
param 'a', 'Number', 'First number'
|
32
|
+
param 'b', 'Number', 'Second number'
|
33
|
+
optional 'c', 'Number', 'Third number'
|
34
|
+
example 'Calculate 1 + 1', :params => { 'a' => 1, 'b' => 1}, :result => 2
|
35
|
+
result 'Number', 'a + b + c'
|
36
|
+
def sum args
|
37
|
+
val = args['a'] + args['b']
|
38
|
+
val += args['c'] if args['c']
|
39
|
+
val
|
66
40
|
end
|
67
|
-
|
41
|
+
end
|
42
|
+
end
|
43
|
+
```
|
68
44
|
|
69
45
|
To run example:
|
70
|
-
|
71
|
-
|
72
|
-
|
46
|
+
```bash
|
47
|
+
$ gem install shotgun # unless it's already installed
|
48
|
+
$ shotgun example/config.ru
|
49
|
+
```
|
73
50
|
|
74
51
|
Browse API and test it via a web browser at http://localhost:9393/
|
75
52
|
|
76
|
-
|
77
53
|
## Inline documentation
|
78
54
|
|
79
55
|
Use built in helper methods to declare complex types and function
|
@@ -174,7 +150,7 @@ e.g.
|
|
174
150
|
title "Calculator interface"
|
175
151
|
introduction "Very simple calculator interface"
|
176
152
|
|
177
|
-
section "Entry points" do
|
153
|
+
section "Entry points" do
|
178
154
|
...
|
179
155
|
end
|
180
156
|
|
@@ -199,4 +175,8 @@ e.g.
|
|
199
175
|
|
200
176
|
> Specify authentication method that should be used to verify the access credentials before printing. See {JSONRPC2::BasicAuth} for examples/info.
|
201
177
|
|
178
|
+
## Development
|
202
179
|
|
180
|
+
- Run `bin/setup` to build a local docker image
|
181
|
+
- Run `bin/test` to run the test suite
|
182
|
+
- Run `bin/run-example` to run the example JSONRPC API from within docker container
|
data/bin/run-example
ADDED
data/bin/setup
ADDED
data/bin/test
ADDED
data/example/config.ru
CHANGED
@@ -2,39 +2,41 @@ $: << File.join(File.dirname(__FILE__),'../lib')
|
|
2
2
|
require 'jsonrpc2/interface'
|
3
3
|
require 'rack/logger'
|
4
4
|
|
5
|
+
# Example of JSONRPC2 API
|
6
|
+
# Start with `bin/run-example`
|
7
|
+
# Open localhost:9292 in your browser and have fun!
|
5
8
|
class ::Object::Calculator < JSONRPC2::Interface
|
6
9
|
title "JSON-RPC2 Calculator"
|
7
10
|
introduction "This interface allows basic maths calculations via JSON-RPC2"
|
8
11
|
auth_with JSONRPC2::BasicAuth.new({'user' => 'secretword', 'admin' => 'password'})
|
9
12
|
|
10
13
|
section 'Simple Ops' do
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
14
|
+
desc 'Multiply two numbers'
|
15
|
+
param 'a', 'Number', 'a'
|
16
|
+
param 'b', 'Number', 'b'
|
17
|
+
result 'Number', 'a * b'
|
18
|
+
def mul
|
19
|
+
raise JSONRPC2::KnownError, [123, "Don't like negative numbers", params] if params['a'] < 0 or params['b'] < 0
|
20
|
+
params['a'] * params['b']
|
21
|
+
end
|
22
|
+
|
23
|
+
desc 'Add numbers'
|
24
|
+
example "Calculate 1 + 1 = 2", :params => { 'a' => 1, 'b' => 1}, :result => 2
|
25
|
+
|
26
|
+
param 'a', 'Number', 'First number'
|
27
|
+
param 'b', 'Number', 'Second number'
|
28
|
+
optional 'c', 'Number', 'Third number'
|
29
|
+
result 'Number', 'a + b + c'
|
30
|
+
def sum
|
31
|
+
val = params['a'] + params['b']
|
32
|
+
val += params['c'] if params['c']
|
33
|
+
|
34
|
+
return 42 if auth == 'admin'
|
35
|
+
|
36
|
+
val
|
37
|
+
end
|
35
38
|
end
|
36
39
|
end
|
37
40
|
|
38
41
|
use Rack::Logger
|
39
42
|
run Calculator
|
40
|
-
|
data/{bin → exe}/jsonrpc2
RENAMED
File without changes
|
data/jsonrpc2.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |gem|
|
|
7
7
|
gem.description = <<-EOD
|
8
8
|
== Description
|
9
9
|
|
10
|
-
A Rack compatible JSON-RPC2 server domain specific language (DSL) - allows JSONRPC APIs to be
|
10
|
+
A Rack compatible JSON-RPC2 server domain specific language (DSL) - allows JSONRPC APIs to be
|
11
11
|
defined as mountable Rack applications with inline documentation, authentication and type checking.
|
12
12
|
|
13
13
|
e.g.
|
@@ -43,16 +43,28 @@ e.g.
|
|
43
43
|
|
44
44
|
EOD
|
45
45
|
gem.summary = %q{JSON-RPC2 server DSL}
|
46
|
-
gem.homepage = "http://github.com/
|
46
|
+
gem.homepage = "http://github.com/livelink/jsonrpc2"
|
47
47
|
|
48
|
-
gem.
|
48
|
+
gem.bindir = 'exe'
|
49
|
+
gem.executables = `git ls-files -- exe/*`.split("\n").map{ |f| File.basename(f) }
|
49
50
|
gem.files = `git ls-files`.split("\n")
|
50
51
|
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
51
52
|
gem.name = "jsonrpc2"
|
52
53
|
gem.require_paths = ["lib"]
|
53
54
|
gem.version = JSONRPC2::VERSION
|
55
|
+
gem.metadata = {
|
56
|
+
"bug_tracker_uri" => "https://github.com/livelink/jsonrpc2/issues",
|
57
|
+
"changelog_uri" => "https://github.com/livelink/jsonrpc2/blob/master/CHANGELOG.md",
|
58
|
+
"documentation_uri" => "https://github.com/livelink/jsonrpc2#inline-documentation",
|
59
|
+
}
|
60
|
+
|
54
61
|
gem.add_dependency("httpclient")
|
55
62
|
gem.add_dependency("json")
|
56
63
|
gem.add_dependency("RedCloth")
|
57
64
|
gem.add_dependency('thor')
|
65
|
+
|
66
|
+
gem.add_development_dependency('rack') # Makes it possible to test JSONRPC2::Interface
|
67
|
+
gem.add_development_dependency('rspec')
|
68
|
+
gem.add_development_dependency('puma') # Required to run rackup example/config.ru
|
69
|
+
gem.add_development_dependency('pry-byebug')
|
58
70
|
end
|
data/lib/jsonrpc2/html.rb
CHANGED
@@ -23,7 +23,7 @@ module JSONRPC2
|
|
23
23
|
}
|
24
24
|
</style>
|
25
25
|
</head>
|
26
|
-
<body>
|
26
|
+
<body>
|
27
27
|
<div class="navbar navbar-fixed-top">
|
28
28
|
<div class="navbar-inner">
|
29
29
|
<div class="container">
|
@@ -101,7 +101,7 @@ EOM
|
|
101
101
|
end
|
102
102
|
else
|
103
103
|
body = RedCloth.new(interface.to_textile).to_html.gsub(/\<h3\>(.*?)\<\/h3\>/, '<h3><a href="'+request.script_name+'/\1">\1</a></h3>')
|
104
|
-
[200, {'Content-Type' => 'text/html'},
|
104
|
+
[200, {'Content-Type' => 'text/html'},
|
105
105
|
html5('Interface: '+interface.name.to_s, body, :request => request)]
|
106
106
|
end
|
107
107
|
end
|
@@ -172,7 +172,7 @@ EOS
|
|
172
172
|
url = CGI.unescapeHTML(str)[1...-1]
|
173
173
|
%Q["<a href="#{CGI.escapeHTML(url)}">#{CGI.escapeHTML(url)}</a>"]
|
174
174
|
end
|
175
|
-
rescue Exception
|
175
|
+
rescue Exception
|
176
176
|
CGI.escapeHTML(result.to_s)
|
177
177
|
end
|
178
178
|
end
|