JSONRPC Interface
JRPC Request, JRPC Notification, JRPC Response, JRPC Error Response, JRPC Object Builder and JRPC Error Codes in Object Oriented Way.
Installation
gem 'jsonrpc_interface'
bundle install
# --- or ---
gem install jsonrpc_interface
require 'jsonrpc_interface'
Usage
JSONRPC::ERRORS
JSONRPC::ERRORS
{
parse_error: { code: -32_700, message: 'Parse Error' },
invalid_request: { code: -32_600, message: 'Invalid Request' },
method_not_found: { code: -32_601, message: 'Method Not Found' },
invalid_params: { code: -32_602, message: 'Invalid Params' },
internal_error: { code: -32_603, message: 'Internal Error' },
unauthorized: { code: -33_001, message: 'Unauthorized' },
application_error: { code: -33_002, message: 'Application Error' },
jsonrpc_specification_violation: { code: -33_003, message: 'JSONRPC Specification Violation' }
}
JSONRPC::Request
JSONRPC::Request
JSONRPC::Request.new(jsonrpc: '2.0', method: 'some.method', params: { some: 'params' }, id: 'sOmEiD')
JSONRPC::Request
JSONRPC::Request
JSONRPC::Request
JSONRPC::Request
JSONRPC::Request::Schema
schema do
required(:jsonrpc).type(:string).filled
required(:method).type(:string).filled
required(:params).type(:hash).filled
required(:id).type(:string).filled
end
JSONRPC::Notification
JSONRPC::Notification
JSONRPC::Notification.new(jsonrpc: '2.0', method: 'some.method', params: { some: 'params' })
JSONRPC::Notification
JSONRPC::Notification
JSONRPC::Notification
JSONRPC::Notification::Schema
schema do
required(:jsonrpc).type(:string).filled
required(:method).type(:string).filled
required(:params).type(:hash).filled
end
JSONRPC::Response
JSONRPC::Response
JSONRPC::Response.new(jsonrpc: '2.0', result: { some: 'result' }, id: 'sOmEiD')
JSONRPC::Response
JSONRPC::Response
JSONRPC::Response
JSONRPC::ErrorResponse
JSONRPC::ErrorResponse
JSONRPC::ErrorResponse.new(jsonrpc: '2.0', method: 'some.method', params: { some: 'params' }, id: nil)
JSONRPC::ErrorResponse.new(jsonrpc: '2.0', method: 'some.method', params: { some: 'params' }, id: 'sOmEiD')
JSONRPC::ErrorResponse
JSONRPC::ErrorResponse
JSONRPC::ErrorResponse
JSONRPC::ErrorResponse
{ code: Integer, message: String, data: Hash }
JSONRPC::ErrorResponse::Schema
schema do
required(:code).type(:integer).filled
required(:message).type(:string).filled
required(:data).type(:hash).filled
end
JSONRPC::RPCObject
.response
JSONRPC::RPCObject.response(
{ some: 'data' },
request_id: SecureRandom.uuid
)
.request
JSONRPC::RPCObject.request(
method: 'some.method',
params: { some: 'params' },
request_id: SecureRandom.uuid
)
.notification
JSONRPC::RPCObject.notification(
method: 'some.method',
params: { some: 'params' }
)
.invalid_request_error
JSONRPC::RPCObject.invalid_request_error({ some: 'data' })
JSONRPC::RPCObject.invalid_request_error({ some: 'data' }, request_id: SecureRandom.uuid)
JSONRPC::ErrorResponse
{ code: -32_600, message: 'Invalid Request', data: { some: 'data' } }
.parse_error
JSONRPC::RPCObject.parse_error
JSONRPC::ErrorResponse
{ code: -32_700, message: 'Parse Error', data: {} }
.jsonrpc_specification_violation_error
JSONRPC::RPCObject.jsonrpc_specification_violation_error
JSONRPC::RPCObject.jsonrpc_specification_violation_error(request_id: SecureRandom.uuid)
JSONRPC::ErrorResponse
{ code: -33_003, message: 'JSONRPC Specification Violation', data: {} }
.method_not_found_error
JSONRPC::RPCObject.method_not_found_error
JSONRPC::RPCObject.method_not_found_error(request_id: SecureRandom.uuid)
JSONRPC::ErrorResponse
{ code: -32_601, message: 'Method Not Found', data: {} }
.invalid_params_error
JSONRPC::RPCObject.invalid_params_error
JSONRPC::RPCObject.invalid_params_error(request_id: SecureRandom.uuid)
JSONRPC::ErrorResponse
{ code: -32_602, message: 'Invalid Params', data: {} }
.internal_error
JSONRPC::RPCObject.internal_error('some', 'error', 'code', error_context: { some: 'context' })
JSONRPC::RPCObject.internal_error('some', 'error', 'code', error_context: { some: 'context' }, request_id: SecureRandom.uuid)
JSONRPC::RPCObject.internal_error
JSONRPC::RPCObject.internal_error(request_id: SecureRandom.uuid)
JSONRPC::ErrorResponse
{
code: -32_603,
message: 'Internal Error',
data: {
error_codes: ['some', 'error', 'code'],
error_cotnext: { some: 'context' }
}
}
.detailed_internal_error
JSONRPC::RPCObject.detailed_internal_error(exception)
JSONRPC::RPCObject.detailed_internal_error(exception, request_id: SecureRandom.uuid)
JSONRPC::ErrorResponse
{
code: -32_603,
message: 'Internal Error',
data: {
error_codes: [],
error_cotnext: {
error_class:
error_message:
error_backtrace:
error_object:
}
}
}
Development
- full build (
steep
=> rubocop
=> rspec
)
bundle exec rake
- code style check (
rubocop
):
bundle exec rake rubocop
- type validation check (
steep
):
bundle exec rake steep
bundle exec rake rspec
License
Released under MIT License.
Authors
Rustam Ibragimov