ripcord 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rspec +1 -0
- data/.rubocop.yml +13 -0
- data/CHANGELOG.md +9 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +10 -1
- data/Gemfile.lock +77 -0
- data/README.md +12 -11
- data/Rakefile +7 -1
- data/lib/ripcord/authentication/http_basic_auth.rb +12 -7
- data/lib/ripcord/authentication/http_token_auth.rb +11 -7
- data/lib/ripcord/authentication/inline_token.rb +11 -7
- data/lib/ripcord/authentication.rb +5 -3
- data/lib/ripcord/base_client.rb +9 -9
- data/lib/ripcord/client.rb +21 -21
- data/lib/ripcord/error.rb +3 -1
- data/lib/ripcord/json_rpc/error.rb +11 -5
- data/lib/ripcord/json_rpc/notification.rb +11 -6
- data/lib/ripcord/json_rpc/request.rb +25 -18
- data/lib/ripcord/json_rpc/response.rb +37 -32
- data/lib/ripcord/json_rpc.rb +6 -4
- data/lib/ripcord/version.rb +3 -1
- data/lib/ripcord.rb +5 -3
- data/ripcord.gemspec +21 -14
- metadata +16 -71
- data/.gitignore +0 -9
- data/.travis.yml +0 -6
- data/Guardfile +0 -6
- data/bin/console +0 -14
- data/bin/setup +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a6f4824697afe1be3bc87090c42e5896c7d7bd5c51c74b327d865e63a9d5958d
|
4
|
+
data.tar.gz: 7fd6510c3dfdc74d6923bb64fa17ad62a0a16f31bbc24785812f910fe5b5291c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 321bb751c17acc56b5446a8df6a54fba42dd2120e68349ebdc0da275af1b4b0569bef30abd999e2549cb5abe452d6a9a31a08ffc8c15b164e21c18594dc0dcff
|
7
|
+
data.tar.gz: 0d1673d284ec1792b3f41f8d6e1b397bdece5862c3b9660a4389ac49f4fcac229bf94da917f6ad8722486a4e0b65fa5862b38eabb8f194e7ac783779069b8acd
|
data/.rspec
CHANGED
data/.rubocop.yml
ADDED
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at code@kgz.me. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/Gemfile
CHANGED
@@ -1,4 +1,13 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
2
4
|
|
3
5
|
# Specify your gem's dependencies in ripcord.gemspec
|
4
6
|
gemspec
|
7
|
+
|
8
|
+
gem 'simplecov'
|
9
|
+
gem 'simplecov-lcov', '~> 0.8.0'
|
10
|
+
gem "rake", "~> 13.0"
|
11
|
+
gem "rspec", "~> 3.0"
|
12
|
+
gem "rubocop", "~> 1.21"
|
13
|
+
gem "webmock"
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
ripcord (1.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
addressable (2.8.0)
|
10
|
+
public_suffix (>= 2.0.2, < 5.0)
|
11
|
+
ast (2.4.2)
|
12
|
+
crack (0.4.5)
|
13
|
+
rexml
|
14
|
+
diff-lcs (1.5.0)
|
15
|
+
docile (1.4.0)
|
16
|
+
hashdiff (1.0.1)
|
17
|
+
parallel (1.21.0)
|
18
|
+
parser (3.1.0.0)
|
19
|
+
ast (~> 2.4.1)
|
20
|
+
public_suffix (4.0.6)
|
21
|
+
rainbow (3.1.1)
|
22
|
+
rake (13.0.6)
|
23
|
+
regexp_parser (2.2.0)
|
24
|
+
rexml (3.2.5)
|
25
|
+
rspec (3.11.0)
|
26
|
+
rspec-core (~> 3.11.0)
|
27
|
+
rspec-expectations (~> 3.11.0)
|
28
|
+
rspec-mocks (~> 3.11.0)
|
29
|
+
rspec-core (3.11.0)
|
30
|
+
rspec-support (~> 3.11.0)
|
31
|
+
rspec-expectations (3.11.0)
|
32
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
33
|
+
rspec-support (~> 3.11.0)
|
34
|
+
rspec-mocks (3.11.0)
|
35
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
36
|
+
rspec-support (~> 3.11.0)
|
37
|
+
rspec-support (3.11.0)
|
38
|
+
rubocop (1.25.1)
|
39
|
+
parallel (~> 1.10)
|
40
|
+
parser (>= 3.1.0.0)
|
41
|
+
rainbow (>= 2.2.2, < 4.0)
|
42
|
+
regexp_parser (>= 1.8, < 3.0)
|
43
|
+
rexml
|
44
|
+
rubocop-ast (>= 1.15.1, < 2.0)
|
45
|
+
ruby-progressbar (~> 1.7)
|
46
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
47
|
+
rubocop-ast (1.15.1)
|
48
|
+
parser (>= 3.0.1.1)
|
49
|
+
ruby-progressbar (1.11.0)
|
50
|
+
simplecov (0.21.2)
|
51
|
+
docile (~> 1.1)
|
52
|
+
simplecov-html (~> 0.11)
|
53
|
+
simplecov_json_formatter (~> 0.1)
|
54
|
+
simplecov-html (0.12.3)
|
55
|
+
simplecov-lcov (0.8.0)
|
56
|
+
simplecov_json_formatter (0.1.4)
|
57
|
+
unicode-display_width (2.1.0)
|
58
|
+
webmock (3.14.0)
|
59
|
+
addressable (>= 2.8.0)
|
60
|
+
crack (>= 0.3.2)
|
61
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
62
|
+
|
63
|
+
PLATFORMS
|
64
|
+
arm64-darwin-21
|
65
|
+
x86_64-linux
|
66
|
+
|
67
|
+
DEPENDENCIES
|
68
|
+
rake (~> 13.0)
|
69
|
+
ripcord!
|
70
|
+
rspec (~> 3.0)
|
71
|
+
rubocop (~> 1.21)
|
72
|
+
simplecov
|
73
|
+
simplecov-lcov (~> 0.8.0)
|
74
|
+
webmock
|
75
|
+
|
76
|
+
BUNDLED WITH
|
77
|
+
2.3.7
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# RiPCord [![
|
1
|
+
# RiPCord [![Ruby](https://github.com/klaustopher/ripcord/actions/workflows/main.yml/badge.svg)](https://github.com/klaustopher/ripcord/actions/workflows/main.yml) [![Gem Version](https://badge.fury.io/rb/ripcord.svg)](https://badge.fury.io/rb/ripcord) [![Coverage Status](https://coveralls.io/repos/github/klaustopher/ripcord/badge.svg?branch=master)](https://coveralls.io/github/klaustopher/ripcord?branch=master)
|
2
2
|
|
3
3
|
This is a [JSON-RPC 2.0](http://www.jsonrpc.org/specification) implementation. It is heavily based on [JSONRPC::Client](https://github.com/fxposter/jsonrpc-client) but has a lot of changes
|
4
4
|
from the initial implementation that are sort of specific to our use case. But it might work for you as well.
|
@@ -19,29 +19,26 @@ And then execute:
|
|
19
19
|
|
20
20
|
## Usage
|
21
21
|
|
22
|
-
|
23
22
|
### Basic Usage
|
23
|
+
|
24
24
|
```ruby
|
25
25
|
client = Ripcord::Client.new('http://www.some-server.com/rpc-endpoint')
|
26
26
|
|
27
|
-
client.call('add', [1,2])
|
27
|
+
client.call('add', [1, 2])
|
28
28
|
```
|
29
29
|
|
30
30
|
### ... with Authentication
|
31
31
|
|
32
32
|
```ruby
|
33
|
-
|
34
|
-
|
33
|
+
client.authentication =
|
34
|
+
Ripcord::Authentication::HTTPBasicAuth.new('user', 'password')
|
35
35
|
```
|
36
36
|
|
37
37
|
```ruby
|
38
|
-
|
39
|
-
client.authentication = Ripcord::Authentication::HTTPBasicAuth.new('some-token')
|
38
|
+
client.authentication = Ripcord::Authentication::HTTPTokenAuth.new('some-token')
|
40
39
|
```
|
41
40
|
|
42
41
|
```ruby
|
43
|
-
# Inline Token
|
44
|
-
# This adds a token item to the root of the JSON request.
|
45
42
|
client.authentication = Ripcord::Authentication::InlineToken.new('some-token')
|
46
43
|
```
|
47
44
|
|
@@ -57,9 +54,13 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/klaust
|
|
57
54
|
|
58
55
|
## Special thanks
|
59
56
|
|
60
|
-
-
|
61
|
-
-
|
57
|
+
- [Pavel Forkert](https://github.com/fxposter/) for the initial implementation of `JSONRPC::Client`
|
58
|
+
- [Clark Germany](https://www.clark.de) for paying me to work on this ;)
|
62
59
|
|
63
60
|
## License
|
64
61
|
|
65
62
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
63
|
+
|
64
|
+
## Code of Conduct
|
65
|
+
|
66
|
+
Everyone interacting in the Ripcord project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/klaustopher/ripcord/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
CHANGED
@@ -1,11 +1,16 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Ripcord
|
4
|
+
module Authentication
|
5
|
+
class HTTPBasicAuth
|
6
|
+
def initialize(username, password)
|
7
|
+
@username = username
|
8
|
+
@password = password
|
9
|
+
end
|
6
10
|
|
7
|
-
|
8
|
-
|
11
|
+
def apply_to(request, _payload_hash)
|
12
|
+
request.basic_auth(@username, @password)
|
13
|
+
end
|
9
14
|
end
|
10
15
|
end
|
11
16
|
end
|
@@ -1,11 +1,15 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Ripcord
|
4
|
+
module Authentication
|
5
|
+
class HTTPTokenAuth
|
6
|
+
def initialize(token)
|
7
|
+
@token = token
|
8
|
+
end
|
6
9
|
|
7
|
-
|
8
|
-
|
10
|
+
def apply_to(request, _payload_hash)
|
11
|
+
request.add_field "Authorization", "Token token=#{@token}"
|
12
|
+
end
|
9
13
|
end
|
10
14
|
end
|
11
15
|
end
|
@@ -1,11 +1,15 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Ripcord
|
4
|
+
module Authentication
|
5
|
+
class InlineToken
|
6
|
+
def initialize(token)
|
7
|
+
@token = token
|
8
|
+
end
|
6
9
|
|
7
|
-
|
8
|
-
|
10
|
+
def apply_to(_request, payload_hash)
|
11
|
+
payload_hash[:token] = @token
|
12
|
+
end
|
9
13
|
end
|
10
14
|
end
|
11
15
|
end
|
@@ -1,7 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Ripcord
|
2
4
|
module Authentication
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
5
|
+
require "ripcord/authentication/http_basic_auth"
|
6
|
+
require "ripcord/authentication/http_token_auth"
|
7
|
+
require "ripcord/authentication/inline_token"
|
6
8
|
end
|
7
9
|
end
|
data/lib/ripcord/base_client.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "securerandom"
|
4
|
+
require "uri"
|
5
|
+
require "net/http"
|
6
|
+
require "json"
|
5
7
|
|
6
8
|
module Ripcord
|
7
9
|
class BaseClient
|
@@ -17,20 +19,18 @@ module Ripcord
|
|
17
19
|
end
|
18
20
|
|
19
21
|
protected
|
22
|
+
|
20
23
|
def execute_request(json_rpc_request)
|
21
24
|
request = Net::HTTP::Post.new(@endpoint_url.request_uri)
|
22
|
-
request.content_type =
|
25
|
+
request.content_type = "application/json"
|
23
26
|
|
24
27
|
payload_hash = json_rpc_request.to_payload
|
25
28
|
|
26
|
-
|
27
|
-
authentication.apply_to(request, payload_hash)
|
28
|
-
end
|
29
|
+
authentication&.apply_to(request, payload_hash)
|
29
30
|
|
30
31
|
request.body = JSON.generate(payload_hash)
|
31
32
|
|
32
33
|
@http_client.request(request)
|
33
34
|
end
|
34
|
-
|
35
35
|
end
|
36
36
|
end
|
data/lib/ripcord/client.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
-
|
2
|
-
require 'ripcord/json_rpc'
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
require
|
5
|
-
require
|
6
|
-
|
7
|
-
require
|
8
|
-
require
|
3
|
+
require "ripcord/authentication"
|
4
|
+
require "ripcord/json_rpc"
|
5
|
+
|
6
|
+
require "securerandom"
|
7
|
+
require "uri"
|
8
|
+
require "net/http"
|
9
|
+
require "json"
|
10
|
+
require "logger"
|
9
11
|
|
10
12
|
module Ripcord
|
11
13
|
class Client
|
@@ -19,9 +21,9 @@ module Ripcord
|
|
19
21
|
|
20
22
|
@http_client = Net::HTTP.new(@endpoint_url.host, @endpoint_url.port)
|
21
23
|
|
22
|
-
if @endpoint_url.
|
23
|
-
@http_client.use_ssl=true
|
24
|
-
|
24
|
+
if @endpoint_url.is_a?(URI::HTTPS)
|
25
|
+
@http_client.use_ssl = true
|
26
|
+
# @http_client.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
25
27
|
end
|
26
28
|
end
|
27
29
|
|
@@ -39,19 +41,18 @@ module Ripcord
|
|
39
41
|
end
|
40
42
|
|
41
43
|
def inspect
|
42
|
-
"#<Ripcord::Client endpoint=#{@endpoint_url
|
44
|
+
"#<Ripcord::Client endpoint=#{@endpoint_url}>"
|
43
45
|
end
|
44
46
|
|
45
47
|
private
|
48
|
+
|
46
49
|
def execute_request(json_rpc_request)
|
47
50
|
request = Net::HTTP::Post.new(@endpoint_url.request_uri)
|
48
|
-
request.content_type =
|
51
|
+
request.content_type = "application/json"
|
49
52
|
|
50
53
|
payload_hash = json_rpc_request.to_payload
|
51
54
|
|
52
|
-
|
53
|
-
authentication.apply_to(request, payload_hash)
|
54
|
-
end
|
55
|
+
authentication&.apply_to(request, payload_hash)
|
55
56
|
|
56
57
|
request.body = JSON.generate(payload_hash)
|
57
58
|
|
@@ -61,20 +62,19 @@ module Ripcord
|
|
61
62
|
def parse_response(http_response)
|
62
63
|
# Check status code
|
63
64
|
status_code = http_response.code.to_i
|
64
|
-
if status_code < 200 || status_code > 299
|
65
|
-
raise Ripcord::Error::InvalidResponse.new(http_response.body)
|
66
|
-
end
|
65
|
+
raise Ripcord::Error::InvalidResponse, http_response.body if status_code < 200 || status_code > 299
|
67
66
|
|
68
67
|
# try to parse json
|
69
68
|
begin
|
70
69
|
json_data = JSON.parse(http_response.body, symbolize_names: true)
|
71
70
|
rescue JSON::ParserError
|
72
|
-
raise Ripcord::Error::InvalidJSON
|
71
|
+
raise Ripcord::Error::InvalidJSON, http_response.body
|
73
72
|
end
|
74
73
|
|
75
|
-
|
74
|
+
case json_data
|
75
|
+
when Hash # Handle single response
|
76
76
|
Ripcord::JsonRPC::Response.from_data(json_data)
|
77
|
-
|
77
|
+
when Array # Handle batch response
|
78
78
|
json_data.map do |request_json|
|
79
79
|
Ripcord::JsonRPC::Response.from_data(request_json)
|
80
80
|
end
|
data/lib/ripcord/error.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Ripcord
|
2
4
|
module Error
|
3
5
|
class InvalidResponse < StandardError
|
4
6
|
def initialize(response_body = nil)
|
5
|
-
message =
|
7
|
+
message = "Invalid or empty response from server."
|
6
8
|
message += "\nResponse: #{response_body}" if response_body
|
7
9
|
|
8
10
|
super(message)
|
@@ -1,9 +1,15 @@
|
|
1
|
-
|
2
|
-
class Error
|
3
|
-
attr_reader :code, :message, :data
|
1
|
+
# frozen_string_literal: true
|
4
2
|
|
5
|
-
|
6
|
-
|
3
|
+
module Ripcord
|
4
|
+
module JsonRPC
|
5
|
+
class Error
|
6
|
+
attr_reader :code, :message, :data
|
7
|
+
|
8
|
+
def initialize(code, message, data)
|
9
|
+
@code = code
|
10
|
+
@message = message
|
11
|
+
@data = data
|
12
|
+
end
|
7
13
|
end
|
8
14
|
end
|
9
15
|
end
|
@@ -1,10 +1,15 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
require "ripcord/json_rpc/request"
|
4
|
+
|
5
|
+
module Ripcord
|
6
|
+
module JsonRPC
|
7
|
+
class Notification < Request
|
8
|
+
def initialize(method, params)
|
9
|
+
@method = method
|
10
|
+
@params = params
|
11
|
+
@id = nil
|
12
|
+
end
|
8
13
|
end
|
9
14
|
end
|
10
15
|
end
|
@@ -1,25 +1,32 @@
|
|
1
|
-
|
2
|
-
class Request
|
3
|
-
attr_accessor :method, :params
|
4
|
-
attr_reader :id
|
1
|
+
# frozen_string_literal: true
|
5
2
|
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
module Ripcord
|
4
|
+
module JsonRPC
|
5
|
+
class Request
|
6
|
+
attr_accessor :method, :params
|
7
|
+
attr_reader :id
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
}.tap do |payload_hash|
|
15
|
-
payload_hash[:params] = params if should_include_params?
|
16
|
-
payload_hash[:id] = id unless id.nil?
|
9
|
+
def initialize(method, params, id)
|
10
|
+
@method = method
|
11
|
+
@params = params
|
12
|
+
@id = id
|
17
13
|
end
|
18
|
-
end
|
19
14
|
|
20
|
-
|
21
|
-
|
22
|
-
|
15
|
+
def to_payload
|
16
|
+
{
|
17
|
+
jsonrpc: Ripcord::JSON_RPC_VERSION,
|
18
|
+
method: method
|
19
|
+
}.tap do |payload_hash|
|
20
|
+
payload_hash[:params] = params if should_include_params?
|
21
|
+
payload_hash[:id] = id unless id.nil?
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def should_include_params?
|
28
|
+
(params.is_a?(Array) || params.is_a?(Hash)) && !params.empty?
|
29
|
+
end
|
23
30
|
end
|
24
31
|
end
|
25
32
|
end
|
@@ -1,44 +1,49 @@
|
|
1
|
-
|
2
|
-
require 'ripcord/json_rpc/error'
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
attr_reader :result, :error, :id
|
3
|
+
require "ripcord/error"
|
4
|
+
require "ripcord/json_rpc/error"
|
7
5
|
|
8
|
-
|
9
|
-
|
6
|
+
module Ripcord
|
7
|
+
module JsonRPC
|
8
|
+
class Response
|
9
|
+
attr_reader :result, :error, :id
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
def successful?
|
15
|
-
error.nil? && !result.nil?
|
16
|
-
end
|
11
|
+
def initialize(result, error, id)
|
12
|
+
@result = result
|
13
|
+
@id = id
|
17
14
|
|
18
|
-
|
19
|
-
|
20
|
-
raise Ripcord::Error::InvalidResponse.new(json_data) unless valid_data?(json_data)
|
15
|
+
@error = Ripcord::JsonRPC::Error.new(error[:code], error[:message], error[:data]) if error
|
16
|
+
end
|
21
17
|
|
22
|
-
|
18
|
+
def successful?
|
19
|
+
error.nil? && !result.nil?
|
23
20
|
end
|
24
21
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
if json_data.has_key?(:error)
|
32
|
-
return false if !json_data[:error].kind_of?(Hash)
|
33
|
-
return false if !json_data[:error].has_key?(:code)
|
34
|
-
return false if !json_data[:error][:code].kind_of?(Fixnum)
|
35
|
-
return false if !json_data[:error].has_key?(:message)
|
36
|
-
return false if !json_data[:error][:message].kind_of?(String)
|
22
|
+
class << self
|
23
|
+
def from_data(json_data)
|
24
|
+
raise Ripcord::Error::InvalidResponse, json_data unless valid_data?(json_data)
|
25
|
+
|
26
|
+
new(json_data[:result], json_data[:error], json_data[:id])
|
37
27
|
end
|
38
28
|
|
39
|
-
|
40
|
-
|
41
|
-
|
29
|
+
def valid_data?(json_data)
|
30
|
+
return false unless json_data.is_a?(Hash)
|
31
|
+
return false if json_data[:jsonrpc] != Ripcord::JSON_RPC_VERSION
|
32
|
+
return false unless json_data.key?(:id)
|
33
|
+
return false unless json_data.key?(:error) ^ json_data.key?(:result)
|
34
|
+
|
35
|
+
if json_data.key?(:error)
|
36
|
+
return false unless json_data[:error].is_a?(Hash)
|
37
|
+
return false unless json_data[:error].key?(:code)
|
38
|
+
return false unless json_data[:error][:code].is_a?(Integer)
|
39
|
+
return false unless json_data[:error].key?(:message)
|
40
|
+
return false unless json_data[:error][:message].is_a?(String)
|
41
|
+
end
|
42
|
+
|
43
|
+
true
|
44
|
+
rescue StandardError
|
45
|
+
false
|
46
|
+
end
|
42
47
|
end
|
43
48
|
end
|
44
49
|
end
|
data/lib/ripcord/json_rpc.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Ripcord
|
2
4
|
module JsonRPC
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
5
|
+
require "ripcord/json_rpc/error"
|
6
|
+
require "ripcord/json_rpc/request"
|
7
|
+
require "ripcord/json_rpc/response"
|
8
|
+
require "ripcord/json_rpc/notification"
|
7
9
|
end
|
8
10
|
end
|
data/lib/ripcord/version.rb
CHANGED
data/lib/ripcord.rb
CHANGED
data/ripcord.gemspec
CHANGED
@@ -1,24 +1,31 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
4
|
-
require 'ripcord/version'
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/ripcord/version"
|
5
4
|
|
6
5
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name
|
8
|
-
spec.version
|
6
|
+
spec.name = "ripcord"
|
7
|
+
spec.version = Ripcord::VERSION
|
9
8
|
spec.authors = ["Klaus Zanders", "Pavel Forkert"]
|
10
9
|
spec.email = ["coding@kgz.me", "fxposter@gmail.com"]
|
11
10
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
11
|
+
spec.summary = "This is a JSON-RPC 2.0 client implementation with some specific additions (custom auth schemes, etc)"
|
12
|
+
spec.description = "JSON-RPC 2.0 client implementation"
|
14
13
|
spec.homepage = "https://github.com/klaustopher/ripcord"
|
15
14
|
spec.license = "MIT"
|
16
15
|
|
17
|
-
spec.
|
18
|
-
|
16
|
+
spec.required_ruby_version = ">= 2.0.0"
|
17
|
+
|
18
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
19
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
20
|
+
spec.metadata["changelog_uri"] = "https://github.com/klaustopher/ripcord/blob/master/CHANGELOG.md"
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
-
spec.
|
23
|
-
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
25
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
26
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
spec.require_paths = ["lib"]
|
24
31
|
end
|
metadata
CHANGED
@@ -1,72 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ripcord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Klaus Zanders
|
8
8
|
- Pavel Forkert
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
dependencies:
|
14
|
-
- !ruby/object:Gem::Dependency
|
15
|
-
name: bundler
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
requirements:
|
18
|
-
- - "~>"
|
19
|
-
- !ruby/object:Gem::Version
|
20
|
-
version: '1.12'
|
21
|
-
type: :development
|
22
|
-
prerelease: false
|
23
|
-
version_requirements: !ruby/object:Gem::Requirement
|
24
|
-
requirements:
|
25
|
-
- - "~>"
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
version: '1.12'
|
28
|
-
- !ruby/object:Gem::Dependency
|
29
|
-
name: rake
|
30
|
-
requirement: !ruby/object:Gem::Requirement
|
31
|
-
requirements:
|
32
|
-
- - "~>"
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version: '10.0'
|
35
|
-
type: :development
|
36
|
-
prerelease: false
|
37
|
-
version_requirements: !ruby/object:Gem::Requirement
|
38
|
-
requirements:
|
39
|
-
- - "~>"
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
version: '10.0'
|
42
|
-
- !ruby/object:Gem::Dependency
|
43
|
-
name: rspec
|
44
|
-
requirement: !ruby/object:Gem::Requirement
|
45
|
-
requirements:
|
46
|
-
- - "~>"
|
47
|
-
- !ruby/object:Gem::Version
|
48
|
-
version: '3.0'
|
49
|
-
type: :development
|
50
|
-
prerelease: false
|
51
|
-
version_requirements: !ruby/object:Gem::Requirement
|
52
|
-
requirements:
|
53
|
-
- - "~>"
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
version: '3.0'
|
56
|
-
- !ruby/object:Gem::Dependency
|
57
|
-
name: webmock
|
58
|
-
requirement: !ruby/object:Gem::Requirement
|
59
|
-
requirements:
|
60
|
-
- - ">="
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
version: '0'
|
63
|
-
type: :development
|
64
|
-
prerelease: false
|
65
|
-
version_requirements: !ruby/object:Gem::Requirement
|
66
|
-
requirements:
|
67
|
-
- - ">="
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: '0'
|
12
|
+
date: 2022-02-21 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
70
14
|
description: JSON-RPC 2.0 client implementation
|
71
15
|
email:
|
72
16
|
- coding@kgz.me
|
@@ -75,16 +19,15 @@ executables: []
|
|
75
19
|
extensions: []
|
76
20
|
extra_rdoc_files: []
|
77
21
|
files:
|
78
|
-
- ".gitignore"
|
79
22
|
- ".rspec"
|
80
|
-
- ".
|
23
|
+
- ".rubocop.yml"
|
24
|
+
- CHANGELOG.md
|
25
|
+
- CODE_OF_CONDUCT.md
|
81
26
|
- Gemfile
|
82
|
-
-
|
27
|
+
- Gemfile.lock
|
83
28
|
- LICENSE.txt
|
84
29
|
- README.md
|
85
30
|
- Rakefile
|
86
|
-
- bin/console
|
87
|
-
- bin/setup
|
88
31
|
- lib/ripcord.rb
|
89
32
|
- lib/ripcord/authentication.rb
|
90
33
|
- lib/ripcord/authentication/http_basic_auth.rb
|
@@ -103,8 +46,11 @@ files:
|
|
103
46
|
homepage: https://github.com/klaustopher/ripcord
|
104
47
|
licenses:
|
105
48
|
- MIT
|
106
|
-
metadata:
|
107
|
-
|
49
|
+
metadata:
|
50
|
+
homepage_uri: https://github.com/klaustopher/ripcord
|
51
|
+
source_code_uri: https://github.com/klaustopher/ripcord
|
52
|
+
changelog_uri: https://github.com/klaustopher/ripcord/blob/master/CHANGELOG.md
|
53
|
+
post_install_message:
|
108
54
|
rdoc_options: []
|
109
55
|
require_paths:
|
110
56
|
- lib
|
@@ -112,16 +58,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
112
58
|
requirements:
|
113
59
|
- - ">="
|
114
60
|
- !ruby/object:Gem::Version
|
115
|
-
version:
|
61
|
+
version: 2.0.0
|
116
62
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
63
|
requirements:
|
118
64
|
- - ">="
|
119
65
|
- !ruby/object:Gem::Version
|
120
66
|
version: '0'
|
121
67
|
requirements: []
|
122
|
-
|
123
|
-
|
124
|
-
signing_key:
|
68
|
+
rubygems_version: 3.3.7
|
69
|
+
signing_key:
|
125
70
|
specification_version: 4
|
126
71
|
summary: This is a JSON-RPC 2.0 client implementation with some specific additions
|
127
72
|
(custom auth schemes, etc)
|
data/.gitignore
DELETED
data/.travis.yml
DELETED
data/Guardfile
DELETED
data/bin/console
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "bundler/setup"
|
4
|
-
require "ripcord"
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require "irb"
|
14
|
-
IRB.start
|