Class: Sarif::WebResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/sarif/web_response.rb

Overview

Describes the response to an HTTP request.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(index: -1,, protocol: nil, version: nil, status_code: nil, reason_phrase: nil, headers: nil, body: nil, no_response_received: false, properties: nil) ⇒ WebResponse

Returns a new instance of WebResponse.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/sarif/web_response.rb', line 8

def initialize(index: -1, protocol: nil, version: nil, status_code: nil, reason_phrase: nil, headers: nil, body: nil, no_response_received: false, properties: nil)
  @index = index
  @protocol = protocol
  @version = version
  @status_code = status_code
  @reason_phrase = reason_phrase
  @headers = headers
  @body = body
  @no_response_received = no_response_received
  @properties = properties
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



6
7
8
# File 'lib/sarif/web_response.rb', line 6

def body
  @body
end

#headersObject

Returns the value of attribute headers.



6
7
8
# File 'lib/sarif/web_response.rb', line 6

def headers
  @headers
end

#indexObject

Returns the value of attribute index.



6
7
8
# File 'lib/sarif/web_response.rb', line 6

def index
  @index
end

#no_response_receivedObject

Returns the value of attribute no_response_received.



6
7
8
# File 'lib/sarif/web_response.rb', line 6

def no_response_received
  @no_response_received
end

#propertiesObject

Returns the value of attribute properties.



6
7
8
# File 'lib/sarif/web_response.rb', line 6

def properties
  @properties
end

#protocolObject

Returns the value of attribute protocol.



6
7
8
# File 'lib/sarif/web_response.rb', line 6

def protocol
  @protocol
end

#reason_phraseObject

Returns the value of attribute reason_phrase.



6
7
8
# File 'lib/sarif/web_response.rb', line 6

def reason_phrase
  @reason_phrase
end

#status_codeObject

Returns the value of attribute status_code.



6
7
8
# File 'lib/sarif/web_response.rb', line 6

def status_code
  @status_code
end

#versionObject

Returns the value of attribute version.



6
7
8
# File 'lib/sarif/web_response.rb', line 6

def version
  @version
end

Class Method Details

.from_hash(h) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/sarif/web_response.rb', line 38

def self.from_hash(h)
  return nil if h.nil?
  new(
    index: h["index"] || -1,
    protocol: h["protocol"],
    version: h["version"],
    status_code: h["statusCode"],
    reason_phrase: h["reasonPhrase"],
    headers: h["headers"],
    body: ArtifactContent.from_hash(h["body"]),
    no_response_received: h.key?("noResponseReceived") ? h["noResponseReceived"] : false,
    properties: h["properties"]
  )
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



53
54
55
56
# File 'lib/sarif/web_response.rb', line 53

def ==(other)
  return false unless other.is_a?(WebResponse)
  @index == other.index && @protocol == other.protocol && @version == other.version && @status_code == other.status_code && @reason_phrase == other.reason_phrase && @headers == other.headers && @body == other.body && @no_response_received == other.no_response_received && @properties == other.properties
end

#hashObject



60
61
62
# File 'lib/sarif/web_response.rb', line 60

def hash
  [@index, @protocol, @version, @status_code, @reason_phrase, @headers, @body, @no_response_received, @properties].hash
end

#to_hObject



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/sarif/web_response.rb', line 20

def to_h
  h = {}
  h["index"] = @index if @index && @index != -1
  h["protocol"] = @protocol unless @protocol.nil?
  h["version"] = @version unless @version.nil?
  h["statusCode"] = @status_code unless @status_code.nil?
  h["reasonPhrase"] = @reason_phrase unless @reason_phrase.nil?
  h["headers"] = @headers unless @headers.nil?
  h["body"] = @body&.to_h unless @body.nil?
  h["noResponseReceived"] = @no_response_received if @no_response_received
  h["properties"] = @properties unless @properties.nil?
  h
end

#to_json(pretty: false) ⇒ Object



34
35
36
# File 'lib/sarif/web_response.rb', line 34

def to_json(pretty: false)
  pretty ? JSON.pretty_generate(to_h) : JSON.generate(to_h)
end