jsonrpc2 0.1.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: fb244988f3e6da4bd9e07cb696ae0527dc60c5ec
4
- data.tar.gz: 8b378af79f04b2603d6ac7ad669918bb9e055962
2
+ SHA256:
3
+ metadata.gz: 38157bffab895f13838433b4564add0f49d5823a9220eafc0b8d9e402bad7931
4
+ data.tar.gz: 5ff1f88ca328078754a7fec05f386ab7308ddef82fbb4f8e357b4eceeef0d373
5
5
  SHA512:
6
- metadata.gz: 8ec025d776da30ad4251511f1907cad21fe1dc76580a907113417fe7e658de63435ec67976b96488c02b41806ab794452e1aad695769cb60059fc9d6dc35ceb7
7
- data.tar.gz: 0f7017e7d77711638377d340d7aae1a6355ddca9b40a0ec7e0218c16dd31bc33a364a7e07acdcf10b9a991c1465987bda927fae0c0cb90c245028ebeb38fc8f3
6
+ metadata.gz: b59d216b880ebeb4988573873090e9bd0807b77a8c7235ee28cfd84a6aeef219d5a7c7c9e16109a93b55d1857a01d3bf7e5ccc10f6bde4e62972199e05f2bccc
7
+ data.tar.gz: 507d80c0b89143a72c092dc994bc31d72977d5289dfb2c446d879af4b8790f0456457bc8d649a21cdcae9d632f2e8d3acb121c9f24999dcf276d39c18122a05f
@@ -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
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ spec/examples.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/CHANGELOG.md ADDED
@@ -0,0 +1,42 @@
1
+ ## [0.3.0] - 2023-02-09
2
+ ### Added
3
+ - Possibility to define callback for request calls prior to validation `JSONRPC2::Interface#before_validation`
4
+
5
+ ## [0.2.0] - 2022-04-07
6
+ ### Added
7
+ - Possibility to define callback for server errors with `JSONRPC2::Interface#on_server_error`
8
+
9
+ ### Fixed
10
+ - Fixed regression introduced in 0.1.1 which makes the valid requests crash
11
+ - Stopped exposing application internals publicly on errors
12
+
13
+ ## [0.1.1] - 2014-01-04
14
+ ### Changed
15
+ - Improve logging of exceptions / failure
16
+
17
+ ## [0.1.0] - 2014-01-04
18
+ ### Changed
19
+ - Turn on timing & logging of all requests
20
+
21
+ ## [0.0.9] - 2012-09-03
22
+ ### Changed
23
+ - Improve client validation
24
+ - Make params optional in request call
25
+
26
+ ## [0.0.8] - 2012-09-03
27
+ ### Changed
28
+ - Add #request to access Rack::Request object
29
+ - Make URLs in HTML interface clickable
30
+
31
+ ## [0.0.7] - 2012-08-27
32
+ ### Changed
33
+ - Add bundled Bootstrap assets for HTML test interface
34
+
35
+ ## [0.0.6] - 2012-08-24
36
+ ### Changed
37
+ - Add Date/Time/DateTime as special string types with regex checks for validation
38
+
39
+ ## [0.0.5] - 2012-07-19
40
+ ### Changed
41
+ - Add commandline client jsonrpc2
42
+ - Add #auth to access currently authenticated username
data/Dockerfile ADDED
@@ -0,0 +1,8 @@
1
+ FROM ruby:3
2
+
3
+ RUN mkdir /srv/www
4
+ WORKDIR /srv/www
5
+ COPY jsonrpc2.gemspec .
6
+ COPY Gemfile .
7
+ COPY lib/jsonrpc2/version.rb lib/jsonrpc2/
8
+ RUN bundle install
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
- class Calculator < JSONRPC2::Interface
42
- title "JSON-RPC2 Calculator"
43
- introduction "This interface allows basic maths calculations via JSON-RPC2"
44
- auth_with JSONRPC2::BasicAuth.new({'apiuser' => 'secretword'})
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
- section 'Simple Ops' do
47
- desc 'Multiply two numbers'
48
- param 'a', 'Number', 'First number'
49
- param 'b', 'Number', 'Second number'
50
- result 'Number', 'a * b'
51
- def mul args
52
- args['a'] * args['b']
53
- end
54
-
55
- desc 'Add numbers'
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
- end
41
+ end
42
+ end
43
+ ```
68
44
 
69
45
  To run example:
70
-
71
- $ gem install shotgun # unless it's already installed
72
- $ shotgun example/config.ru
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
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env bash
2
+
3
+ docker run --rm \
4
+ --mount type=bind,source="$(pwd)",target=/srv/www \
5
+ -p 9292:9292 \
6
+ jsonrpc2 \
7
+ rackup example/config.ru --host 0.0.0.0
data/bin/setup ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env bash
2
+
3
+ docker build . -t jsonrpc2
data/bin/test ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env bash
2
+
3
+ docker run --rm \
4
+ --mount type=bind,source="$(pwd)",target=/srv/www \
5
+ -t \
6
+ jsonrpc2 \
7
+ bundle exec rspec $@
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
- desc 'Multiply two numbers'
12
- param 'a', 'Number', 'a'
13
- param 'b', 'Number', 'b'
14
- result 'Number', 'a * b'
15
- def mul
16
- raise JSONRPC2::KnownError, [123, "Don't like negative numbers", params] if params['a'] < 0 or params['b'] < 0
17
- params['a'] * params['b']
18
- end
19
-
20
- desc 'Add numbers'
21
- example "Calculate 1 + 1 = 2", :params => { 'a' => 1, 'b' => 1}, :result => 2
22
-
23
- param 'a', 'Number', 'First number'
24
- param 'b', 'Number', 'Second number'
25
- optional 'c', 'Number', 'Third number'
26
- result 'Number', 'a + b + c'
27
- def sum
28
- val = params['a'] + params['b']
29
- val += params['c'] if params['c']
30
-
31
- return 42 if auth == 'admin'
32
-
33
- val
34
- end
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
-
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/geoffyoungs/jsonrpc2"
46
+ gem.homepage = "http://github.com/livelink/jsonrpc2"
47
47
 
48
- gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
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 => e
175
+ rescue Exception
176
176
  CGI.escapeHTML(result.to_s)
177
177
  end
178
178
  end