Class: Spikard::Testing::Response
- Inherits:
-
Object
- Object
- Spikard::Testing::Response
- Defined in:
- lib/spikard/response.rb
Overview
Lightweight wrapper around native response hashes.
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#status_code ⇒ Object
readonly
Returns the value of attribute status_code.
Instance Method Summary collapse
- #body_bytes ⇒ Object
- #body_text ⇒ Object
- #bytes ⇒ Object
-
#initialize(payload) ⇒ Response
constructor
A new instance of Response.
- #json ⇒ Object
- #status ⇒ Object
- #text ⇒ Object
Constructor Details
#initialize(payload) ⇒ Response
Returns a new instance of Response.
75 76 77 78 79 80 |
# File 'lib/spikard/response.rb', line 75 def initialize(payload) @status_code = payload[:status_code] @headers = payload[:headers] || {} @body = payload[:body] @body_text = payload[:body_text] end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
73 74 75 |
# File 'lib/spikard/response.rb', line 73 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
73 74 75 |
# File 'lib/spikard/response.rb', line 73 def headers @headers end |
#status_code ⇒ Object (readonly)
Returns the value of attribute status_code.
73 74 75 |
# File 'lib/spikard/response.rb', line 73 def status_code @status_code end |
Instance Method Details
#body_bytes ⇒ Object
86 87 88 |
# File 'lib/spikard/response.rb', line 86 def body_bytes @body || ''.b end |
#body_text ⇒ Object
90 91 92 |
# File 'lib/spikard/response.rb', line 90 def body_text @body_text || @body&.dup&.force_encoding(Encoding::UTF_8) end |
#bytes ⇒ Object
104 105 106 |
# File 'lib/spikard/response.rb', line 104 def bytes body_bytes.bytes end |
#json ⇒ Object
98 99 100 101 102 |
# File 'lib/spikard/response.rb', line 98 def json return nil if @body.nil? || @body.empty? JSON.parse(@body) end |
#status ⇒ Object
82 83 84 |
# File 'lib/spikard/response.rb', line 82 def status @status_code end |
#text ⇒ Object
94 95 96 |
# File 'lib/spikard/response.rb', line 94 def text body_text end |