Class: Msf::RPC::JSON::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/msf/core/rpc/json/response.rb

Overview

Represents a JSON-RPC response.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, result:, response: nil) ⇒ Response

Instantiate a Response object.

Parameters:

  • id (Integer, String, NilClass)

    It MUST be the same as the value of the id member in the Request Object. If there was an error in detecting the id in the Request object (e.g. Parse error/Invalid Request), it MUST be Null.

  • result (Integer, String, Array, Hash, NilClass)

    Result of the method.

  • response (Hash) (defaults to: nil)

    A response hash. The default value is nil.



31
32
33
34
35
# File 'lib/msf/core/rpc/json/response.rb', line 31

def initialize(id:, result:, response: nil)
  @id = id
  @result = result
  @response = response
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/msf/core/rpc/json/response.rb', line 6

def id
  @id
end

#responseObject (readonly)

Returns the value of attribute response.



5
6
7
# File 'lib/msf/core/rpc/json/response.rb', line 5

def response
  @response
end

#resultObject (readonly)

Returns the value of attribute result.



7
8
9
# File 'lib/msf/core/rpc/json/response.rb', line 7

def result
  @result
end

Class Method Details

.parse(response, symbolize_names: true) ⇒ Response

Parse response and return a new Response instance.

Parameters:

  • response (Hash)

    A response hash.

  • symbolize_names (Boolean) (defaults to: true)

    If true, symbols are used for the names (keys) when processing JSON objects; otherwise, strings are used. Default: true

Returns:

  • (Response)

    Response object that represents the response hash.



14
15
16
17
18
19
20
21
22
# File 'lib/msf/core/rpc/json/response.rb', line 14

def self.parse(response, symbolize_names: true)
  id_key = symbolize_names ? :id : :id.to_s
  result_key = symbolize_names ? :result : :result.to_s

  id = response[id_key]
  result = response[result_key]

  Response.new(id: id, result: result, response: response)
end