Class: Spectre::Http::SpectreHttpResponse
- Inherits:
-
Object
- Object
- Spectre::Http::SpectreHttpResponse
- Defined in:
- lib/spectre/http.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#json ⇒ Object
readonly
Returns the value of attribute json.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
Instance Method Summary collapse
-
#initialize(net_res) ⇒ SpectreHttpResponse
constructor
A new instance of SpectreHttpResponse.
- #success? ⇒ Boolean
Constructor Details
#initialize(net_res) ⇒ SpectreHttpResponse
Returns a new instance of SpectreHttpResponse.
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/spectre/http.rb', line 191 def initialize net_res @code = net_res.code.to_i = net_res. @body = net_res.body @headers = SpectreHttpHeader.new(net_res.to_hash) @json = nil return if @body.nil? begin @json = JSON.parse(@body, object_class: OpenStruct) rescue JSON::ParserError # Shhhhh... it's ok. Do nothing here end end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
189 190 191 |
# File 'lib/spectre/http.rb', line 189 def body @body end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
189 190 191 |
# File 'lib/spectre/http.rb', line 189 def code @code end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
189 190 191 |
# File 'lib/spectre/http.rb', line 189 def headers @headers end |
#json ⇒ Object (readonly)
Returns the value of attribute json.
189 190 191 |
# File 'lib/spectre/http.rb', line 189 def json @json end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
189 190 191 |
# File 'lib/spectre/http.rb', line 189 def end |
Instance Method Details
#success? ⇒ Boolean
207 208 209 |
# File 'lib/spectre/http.rb', line 207 def success? @code < 400 end |