Class: A2A::JsonRpc::Request
- Inherits:
-
Object
- Object
- A2A::JsonRpc::Request
- Defined in:
- lib/simple_a2a/json_rpc.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(id:, method:, params: nil) ⇒ Request
constructor
A new instance of Request.
- #notification? ⇒ Boolean
Constructor Details
#initialize(id:, method:, params: nil) ⇒ Request
Returns a new instance of Request.
26 27 28 29 30 |
# File 'lib/simple_a2a/json_rpc.rb', line 26 def initialize(id:, method:, params: nil) @id = id @method = method @params = params end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
24 25 26 |
# File 'lib/simple_a2a/json_rpc.rb', line 24 def id @id end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
24 25 26 |
# File 'lib/simple_a2a/json_rpc.rb', line 24 def method @method end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
24 25 26 |
# File 'lib/simple_a2a/json_rpc.rb', line 24 def params @params end |
Class Method Details
.parse(json_string) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/simple_a2a/json_rpc.rb', line 32 def self.parse(json_string) data = JSON.parse(json_string) raise ParseError, "not a Hash" unless data.is_a?(Hash) raise InvalidRequestError, "missing jsonrpc field" unless data["jsonrpc"] == "2.0" raise InvalidRequestError, "missing method" unless data.key?("method") new( id: data["id"], method: data["method"], params: data["params"] ) rescue JSON::ParserError => e raise ParseError, e. end |
Instance Method Details
#notification? ⇒ Boolean
47 |
# File 'lib/simple_a2a/json_rpc.rb', line 47 def notification? = id.nil? |