Class: JSONRPC::Request
- Inherits:
-
Dry::Struct
- Object
- Dry::Struct
- JSONRPC::Request
- Defined in:
- lib/jsonrpc/request.rb,
sig/jsonrpc/request.rbs
Overview
A JSON-RPC 2.0 Request object
Represents a call to a specific method with optional parameters and an identifier.
Instance Attribute Summary collapse
-
#id ⇒ String, ...
readonly
The request identifier.
-
#jsonrpc ⇒ String
readonly
JSON-RPC protocol version.
-
#method ⇒ String
readonly
The method name to invoke.
-
#params ⇒ Hash, ...
readonly
Parameters to pass to the method.
Instance Method Summary collapse
-
#initialize ⇒ Request
constructor
A new instance of Request.
-
#to_h ⇒ Hash
Converts the request to a JSON-compatible Hash.
-
#to_json ⇒ String
Converts the request to a JSON string.
- #validate_id ⇒ void
- #validate_method ⇒ void
- #validate_params ⇒ void
Constructor Details
#initialize ⇒ Request
Returns a new instance of Request.
8 |
# File 'sig/jsonrpc/request.rbs', line 8
def initialize: (method: String, ?params: params_type, id: id_type) -> void
|
Instance Attribute Details
#id ⇒ String, ... (readonly)
The request identifier
59 |
# File 'lib/jsonrpc/request.rb', line 59 attribute? :id, Types::String | Types::Integer | Types::Nil |
#jsonrpc ⇒ String (readonly)
JSON-RPC protocol version
26 |
# File 'lib/jsonrpc/request.rb', line 26 attribute :jsonrpc, Types::String.default('2.0') |
#method ⇒ String (readonly)
The method name to invoke
37 |
# File 'lib/jsonrpc/request.rb', line 37 attribute :method, Types::String.constrained(format: /\A(?!rpc\.)/) |
Instance Method Details
#to_h ⇒ Hash
Converts the request to a JSON-compatible Hash
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/jsonrpc/request.rb', line 71 def to_h hash = { jsonrpc: jsonrpc, method: method, id: id } hash[:params] = params unless params.nil? hash end |
#to_json ⇒ String
Converts the request to a JSON string
92 93 94 |
# File 'lib/jsonrpc/request.rb', line 92 def to_json(*) MultiJson.dump(to_h, *) end |
#validate_id ⇒ void
This method returns an undefined value.
16 |
# File 'sig/jsonrpc/request.rbs', line 16
def validate_id: (id_type) -> void
|
#validate_method ⇒ void
This method returns an undefined value.
14 |
# File 'sig/jsonrpc/request.rbs', line 14
def validate_method: (String) -> void
|
#validate_params ⇒ void
This method returns an undefined value.
15 |
# File 'sig/jsonrpc/request.rbs', line 15
def validate_params: (params_type) -> void
|