Class: Snails::Harness::Response

Inherits:
Object
  • Object
show all
Defined in:
runtime/snails/harness.rb

Overview

HTTP response wrapper — the surface a case reads.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status, body, headers) ⇒ Response

Returns a new instance of Response.



23
24
25
26
27
# File 'runtime/snails/harness.rb', line 23

def initialize(status, body, headers)
  @status = status
  @body = body
  @headers = headers
end

Instance Attribute Details

#body ⇒ Object (readonly)

Returns the value of attribute body.



21
22
23
# File 'runtime/snails/harness.rb', line 21

def body
  @body
end

#headers ⇒ Object (readonly)

Returns the value of attribute headers.



21
22
23
# File 'runtime/snails/harness.rb', line 21

def headers
  @headers
end

#status ⇒ Object (readonly)

Returns the value of attribute status.



21
22
23
# File 'runtime/snails/harness.rb', line 21

def status
  @status
end

Instance Method Details

#parsed_body ⇒ Object?

the body as parsed JSON, or the raw body when it is not JSON.

Returns:

  • (Object, nil) —

    the parsed value, the raw String when parsing fails, or nil for an empty body



33
34
35
36
37
38
39
# File 'runtime/snails/harness.rb', line 33

def parsed_body
  return nil if @body.nil? || @body.empty?

  JSON.parse(@body)
rescue StandardError
  @body
end