Class: JSONRPC::Notification
- Inherits:
-
Object
- Object
- JSONRPC::Notification
- Defined in:
- lib/jsonrpc/notification.rb
Overview
A JSON-RPC 2.0 Notification object
Represents a method call that does not expect a response. Unlike a Request, a Notification omits the “id” field, indicating that no response should be sent.
A Notification is a Request object without an “id” member. Notifications are not confirmable by definition since they do not have a Response object.
Instance Attribute Summary collapse
-
#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(method:, params: nil) ⇒ Notification
constructor
Creates a new JSON-RPC 2.0 Notification object.
-
#to_h ⇒ Hash
Converts the notification to a JSON-compatible Hash.
-
#to_json ⇒ String
Converts the notification to a JSON string.
Constructor Details
#initialize(method:, params: nil) ⇒ Notification
Creates a new JSON-RPC 2.0 Notification object
72 73 74 75 76 77 78 79 80 |
# File 'lib/jsonrpc/notification.rb', line 72 def initialize(method:, params: nil) @jsonrpc = '2.0' validate_method(method) validate_params(params) @method = method @params = params end |
Instance Attribute Details
#jsonrpc ⇒ String (readonly)
JSON-RPC protocol version
31 32 33 |
# File 'lib/jsonrpc/notification.rb', line 31 def jsonrpc @jsonrpc end |
#method ⇒ String (readonly)
The method name to invoke
42 43 44 |
# File 'lib/jsonrpc/notification.rb', line 42 def method @method end |
#params ⇒ Hash, ... (readonly)
Parameters to pass to the method
53 54 55 |
# File 'lib/jsonrpc/notification.rb', line 53 def params @params end |
Instance Method Details
#to_h ⇒ Hash
Converts the notification to a JSON-compatible Hash
91 92 93 94 95 96 97 98 99 |
# File 'lib/jsonrpc/notification.rb', line 91 def to_h hash = { jsonrpc: jsonrpc, method: method } hash[:params] = params unless params.nil? hash end |
#to_json ⇒ String
Converts the notification to a JSON string
110 111 112 |
# File 'lib/jsonrpc/notification.rb', line 110 def to_json(*) MultiJson.dump(to_h, *) end |