Class: Spikard::Testing::Response
- Inherits:
-
Object
- Object
- Spikard::Testing::Response
- Defined in:
- lib/spikard/response.rb
Overview
:nodoc: Lightweight response wrapper used by the test client.
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.
139 140 141 142 143 144 |
# File 'lib/spikard/response.rb', line 139 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.
137 138 139 |
# File 'lib/spikard/response.rb', line 137 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
137 138 139 |
# File 'lib/spikard/response.rb', line 137 def headers @headers end |
#status_code ⇒ Object (readonly)
Returns the value of attribute status_code.
137 138 139 |
# File 'lib/spikard/response.rb', line 137 def status_code @status_code end |
Instance Method Details
#body_bytes ⇒ Object
150 151 152 |
# File 'lib/spikard/response.rb', line 150 def body_bytes @body || ''.b end |
#body_text ⇒ Object
154 155 156 |
# File 'lib/spikard/response.rb', line 154 def body_text @body_text || @body&.dup&.force_encoding(Encoding::UTF_8) end |
#bytes ⇒ Object
168 169 170 |
# File 'lib/spikard/response.rb', line 168 def bytes body_bytes.bytes end |
#json ⇒ Object
162 163 164 165 166 |
# File 'lib/spikard/response.rb', line 162 def json return nil if @body.nil? || @body.empty? JSON.parse(@body) end |
#status ⇒ Object
146 147 148 |
# File 'lib/spikard/response.rb', line 146 def status @status_code end |
#text ⇒ Object
158 159 160 |
# File 'lib/spikard/response.rb', line 158 def text body_text end |