Class: Scanii::TraceResult

Inherits:
Object
  • Object
show all
Defined in:
lib/scanii/trace_result.rb

Overview

Result of Client#retrieve_trace — ordered processing events for a scan.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, events:, request_id:, host_id:, raw_response:) ⇒ TraceResult

Returns a new instance of TraceResult.



10
11
12
13
14
15
16
# File 'lib/scanii/trace_result.rb', line 10

def initialize(id:, events:, request_id:, host_id:, raw_response:)
  @id           = id
  @events       = events
  @request_id   = request_id
  @host_id      = host_id
  @raw_response = raw_response
end

Instance Attribute Details

#eventsObject (readonly)

Returns the value of attribute events.



8
9
10
# File 'lib/scanii/trace_result.rb', line 8

def events
  @events
end

#host_idObject (readonly)

Returns the value of attribute host_id.



8
9
10
# File 'lib/scanii/trace_result.rb', line 8

def host_id
  @host_id
end

#idObject (readonly)

Returns the value of attribute id.



8
9
10
# File 'lib/scanii/trace_result.rb', line 8

def id
  @id
end

#raw_responseObject (readonly)

Returns the value of attribute raw_response.



8
9
10
# File 'lib/scanii/trace_result.rb', line 8

def raw_response
  @raw_response
end

#request_idObject (readonly)

Returns the value of attribute request_id.



8
9
10
# File 'lib/scanii/trace_result.rb', line 8

def request_id
  @request_id
end

Class Method Details

.from_response(body, headers) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/scanii/trace_result.rb', line 18

def self.from_response(body, headers)
  json = body.nil? || body.empty? ? {} : JSON.parse(body)

  new(
    id: (json["id"] || "").to_s,
    events: Array(json["events"]).map { |e| TraceEvent.from_hash(e) },
    request_id: headers["x-scanii-request-id"],
    host_id: headers["x-scanii-host-id"],
    raw_response: body
  )
end