Class: Snails::Harness::Response
Overview
HTTP response wrapper — the surface a case reads.
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#initialize(status, body, headers) ⇒ Response
constructor
A new instance of Response.
-
#parsed_body ⇒ Object?
the body as parsed JSON, or the raw body when it is not JSON.
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.
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 |