Class: DevSuite::RequestLogger::Response

Inherits:
Object
  • Object
show all
Includes:
Utils::WarningHandler
Defined in:
lib/dev_suite/request_logger/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::WarningHandler

#warn_if_missing

Constructor Details

#initialize(status:, message:, headers:, body:, response_time: nil) ⇒ Response

Returns a new instance of Response.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/dev_suite/request_logger/response.rb', line 10

def initialize(
  status:,
  message:,
  headers:,
  body:,
  response_time: nil
)
  @status = status.to_i
  @message = message
  @headers = headers
  @body = body
  @content_type = extract_content_type
  @content_length = extract_content_length
  @response_time = response_time

  validate_presence
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



8
9
10
# File 'lib/dev_suite/request_logger/response.rb', line 8

def body
  @body
end

#content_lengthObject (readonly)

Returns the value of attribute content_length.



8
9
10
# File 'lib/dev_suite/request_logger/response.rb', line 8

def content_length
  @content_length
end

#content_typeObject (readonly)

Returns the value of attribute content_type.



8
9
10
# File 'lib/dev_suite/request_logger/response.rb', line 8

def content_type
  @content_type
end

#headersObject (readonly)

Returns the value of attribute headers.



8
9
10
# File 'lib/dev_suite/request_logger/response.rb', line 8

def headers
  @headers
end

#messageObject (readonly)

Returns the value of attribute message.



8
9
10
# File 'lib/dev_suite/request_logger/response.rb', line 8

def message
  @message
end

#response_timeObject (readonly)

Returns the value of attribute response_time.



8
9
10
# File 'lib/dev_suite/request_logger/response.rb', line 8

def response_time
  @response_time
end

#statusObject (readonly)

Returns the value of attribute status.



8
9
10
# File 'lib/dev_suite/request_logger/response.rb', line 8

def status
  @status
end

Instance Method Details

#header(key) ⇒ Object



32
33
34
# File 'lib/dev_suite/request_logger/response.rb', line 32

def header(key)
  headers[key.to_s.downcase] || headers[key.to_s]
end

#success?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/dev_suite/request_logger/response.rb', line 28

def success?
  status.between?(200, 299)
end