Class: Scanii::PendingResult

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

Overview

Result of an asynchronous scan submission returned by Client#process_async and Client#fetch.

The actual scan result is fetched later via Client#retrieve, or delivered to the supplied callback URL.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, request_id:, host_id:, resource_location:, raw_response:) ⇒ PendingResult

Returns a new instance of PendingResult.



14
15
16
17
18
19
20
# File 'lib/scanii/pending_result.rb', line 14

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

Instance Attribute Details

#host_idObject (readonly)

Returns the value of attribute host_id.



12
13
14
# File 'lib/scanii/pending_result.rb', line 12

def host_id
  @host_id
end

#idObject (readonly)

Returns the value of attribute id.



12
13
14
# File 'lib/scanii/pending_result.rb', line 12

def id
  @id
end

#raw_responseObject (readonly)

Returns the value of attribute raw_response.



12
13
14
# File 'lib/scanii/pending_result.rb', line 12

def raw_response
  @raw_response
end

#request_idObject (readonly)

Returns the value of attribute request_id.



12
13
14
# File 'lib/scanii/pending_result.rb', line 12

def request_id
  @request_id
end

#resource_locationObject (readonly)

Returns the value of attribute resource_location.



12
13
14
# File 'lib/scanii/pending_result.rb', line 12

def resource_location
  @resource_location
end

Class Method Details

.from_response(body, headers) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/scanii/pending_result.rb', line 22

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

  new(
    id: (json["id"] || "").to_s,
    request_id: headers["x-scanii-request-id"],
    host_id: headers["x-scanii-host-id"],
    resource_location: headers["location"],
    raw_response: body
  )
end