Class: AgentClientProtocol::RPC::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/agent_client_protocol/rpc.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, method:, params: nil) ⇒ Request

Returns a new instance of Request.



71
72
73
74
75
# File 'lib/agent_client_protocol/rpc.rb', line 71

def initialize(id:, method:, params: nil)
  @id = RequestId.coerce(id)
  @method = String(method)
  @params = params
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



69
70
71
# File 'lib/agent_client_protocol/rpc.rb', line 69

def id
  @id
end

#methodObject (readonly)

Returns the value of attribute method.



69
70
71
# File 'lib/agent_client_protocol/rpc.rb', line 69

def method
  @method
end

#paramsObject (readonly)

Returns the value of attribute params.



69
70
71
# File 'lib/agent_client_protocol/rpc.rb', line 69

def params
  @params
end

Instance Method Details

#to_h(include_jsonrpc: true) ⇒ Object



77
78
79
80
81
82
83
84
# File 'lib/agent_client_protocol/rpc.rb', line 77

def to_h(include_jsonrpc: true)
  payload = {
    "id" => id,
    "method" => method
  }
  payload["params"] = params unless params.nil?
  include_jsonrpc ? { "jsonrpc" => JSONRPC_VERSION }.merge(payload) : payload
end