Class: Scanii::ProcessingResult

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

Overview

Result of a synchronous file scan returned by Client#process and Client#retrieve.

findings is always an Array. Empty array means the content is clean.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, findings:, checksum:, content_length:, content_type:, metadata:, creation_date:, error:, request_id:, host_id:, resource_location:, raw_response:) ⇒ ProcessingResult

Returns a new instance of ProcessingResult.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/scanii/processing_result.rb', line 15

def initialize(id:, findings:, checksum:, content_length:, content_type:,
               metadata:, creation_date:, error:,
               request_id:, host_id:, resource_location:, raw_response:)
  @id                = id
  @findings          = findings
  @checksum          = checksum
  @content_length    = content_length
  @content_type      = content_type
  @metadata          = 
  @creation_date     = creation_date
  @error             = error
  @request_id        = request_id
  @host_id           = host_id
  @resource_location = resource_location
  @raw_response      = raw_response
end

Instance Attribute Details

#checksumObject (readonly)

Returns the value of attribute checksum.



11
12
13
# File 'lib/scanii/processing_result.rb', line 11

def checksum
  @checksum
end

#content_lengthObject (readonly)

Returns the value of attribute content_length.



11
12
13
# File 'lib/scanii/processing_result.rb', line 11

def content_length
  @content_length
end

#content_typeObject (readonly)

Returns the value of attribute content_type.



11
12
13
# File 'lib/scanii/processing_result.rb', line 11

def content_type
  @content_type
end

#creation_dateObject (readonly)

Returns the value of attribute creation_date.



11
12
13
# File 'lib/scanii/processing_result.rb', line 11

def creation_date
  @creation_date
end

#errorObject (readonly)

Returns the value of attribute error.



11
12
13
# File 'lib/scanii/processing_result.rb', line 11

def error
  @error
end

#findingsObject (readonly)

Returns the value of attribute findings.



11
12
13
# File 'lib/scanii/processing_result.rb', line 11

def findings
  @findings
end

#host_idObject (readonly)

Returns the value of attribute host_id.



11
12
13
# File 'lib/scanii/processing_result.rb', line 11

def host_id
  @host_id
end

#idObject (readonly)

Returns the value of attribute id.



11
12
13
# File 'lib/scanii/processing_result.rb', line 11

def id
  @id
end

#metadataObject (readonly)

Returns the value of attribute metadata.



11
12
13
# File 'lib/scanii/processing_result.rb', line 11

def 
  @metadata
end

#raw_responseObject (readonly)

Returns the value of attribute raw_response.



11
12
13
# File 'lib/scanii/processing_result.rb', line 11

def raw_response
  @raw_response
end

#request_idObject (readonly)

Returns the value of attribute request_id.



11
12
13
# File 'lib/scanii/processing_result.rb', line 11

def request_id
  @request_id
end

#resource_locationObject (readonly)

Returns the value of attribute resource_location.



11
12
13
# File 'lib/scanii/processing_result.rb', line 11

def resource_location
  @resource_location
end

Class Method Details

.from_response(body, headers) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/scanii/processing_result.rb', line 32

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

  new(
    id: (json["id"] || "").to_s,
    findings: Array(json["findings"]).map(&:to_s),
    checksum: json["checksum"]&.to_s,
    content_length: json["content_length"]&.to_i,
    content_type: json["content_type"]&.to_s,
    metadata: (json["metadata"] || {}).transform_values(&:to_s),
    creation_date: json["creation_date"]&.to_s,
    error: json["error"]&.to_s,
    request_id: headers["x-scanii-request-id"],
    host_id: headers["x-scanii-host-id"],
    resource_location: headers["location"],
    raw_response: body
  )
end