Class: A2A::Protocol::Request
- Inherits:
-
Object
- Object
- A2A::Protocol::Request
- Defined in:
- lib/a2a/protocol/json_rpc.rb
Overview
Represents a JSON-RPC 2.0 request
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#jsonrpc ⇒ Object
readonly
Returns the value of attribute jsonrpc.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
-
#initialize(jsonrpc:, method:, params: {}, id: nil) ⇒ Request
constructor
Initialize a new request.
-
#notification? ⇒ Boolean
Check if this is a notification (no response expected).
-
#to_h ⇒ Hash
Convert to hash representation.
-
#to_json(*_args) ⇒ String
Convert to JSON string.
Constructor Details
#initialize(jsonrpc:, method:, params: {}, id: nil) ⇒ Request
Initialize a new request
213 214 215 216 217 218 |
# File 'lib/a2a/protocol/json_rpc.rb', line 213 def initialize(jsonrpc:, method:, params: {}, id: nil) @jsonrpc = jsonrpc @method = method @params = params @id = id end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
204 205 206 |
# File 'lib/a2a/protocol/json_rpc.rb', line 204 def id @id end |
#jsonrpc ⇒ Object (readonly)
Returns the value of attribute jsonrpc.
204 205 206 |
# File 'lib/a2a/protocol/json_rpc.rb', line 204 def jsonrpc @jsonrpc end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
204 205 206 |
# File 'lib/a2a/protocol/json_rpc.rb', line 204 def method @method end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
204 205 206 |
# File 'lib/a2a/protocol/json_rpc.rb', line 204 def params @params end |
Instance Method Details
#notification? ⇒ Boolean
Check if this is a notification (no response expected)
224 225 226 |
# File 'lib/a2a/protocol/json_rpc.rb', line 224 def notification? @id.nil? end |
#to_h ⇒ Hash
Convert to hash representation
232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/a2a/protocol/json_rpc.rb', line 232 def to_h hash = { jsonrpc: @jsonrpc, method: @method } hash[:params] = @params unless @params.nil? || (@params.respond_to?(:empty?) && @params.empty?) hash[:id] = @id unless @id.nil? hash end |
#to_json(*_args) ⇒ String
Convert to JSON string
248 249 250 251 |
# File 'lib/a2a/protocol/json_rpc.rb', line 248 def to_json(*_args) # Use optimized JSON generator if available JsonRpc.generate_json(to_h) end |