Class: JSONRPC::Request
- Inherits:
-
Dry::Struct
- Object
- Dry::Struct
- JSONRPC::Request
- Defined in:
- lib/jsonrpc/request.rb
Overview
A JSON-RPC 2.0 Request object
Represents a call to a specific method with optional parameters and an identifier.
Instance Method Summary collapse
-
#id ⇒ String, ...
The request identifier.
-
#jsonrpc ⇒ String
JSON-RPC protocol version.
-
#method ⇒ String
The method name to invoke.
-
#params ⇒ Hash, ...
Parameters to pass to the method.
-
#to_h ⇒ Hash
Converts the request to a JSON-compatible Hash.
-
#to_json ⇒ String
Converts the request to a JSON string.
Instance Method Details
#id ⇒ String, ...
The request identifier
59 |
# File 'lib/jsonrpc/request.rb', line 59 attribute? :id, Types::String | Types::Integer | Types::Nil |
#jsonrpc ⇒ String
JSON-RPC protocol version
26 |
# File 'lib/jsonrpc/request.rb', line 26 attribute :jsonrpc, Types::String.default('2.0') |
#method ⇒ String
The method name to invoke
37 |
# File 'lib/jsonrpc/request.rb', line 37 attribute :method, Types::String.constrained(format: /\A(?!rpc\.)/) |
#params ⇒ Hash, ...
Parameters to pass to the method
48 |
# File 'lib/jsonrpc/request.rb', line 48 attribute? :params, (Types::Hash | Types::Array).optional |
#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 |