Class: Spectre::Http::SpectreHttpResponse
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.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
Instance Method Summary collapse
-
#initialize(net_res) ⇒ SpectreHttpResponse
constructor
A new instance of SpectreHttpResponse.
- #json ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(net_res) ⇒ SpectreHttpResponse
Returns a new instance of SpectreHttpResponse.
144 145 146 147 148 149 150 |
# File 'lib/spectre/http.rb', line 144 def initialize net_res @code = net_res.code.to_i @message = net_res. @body = net_res.body @headers = SpectreHttpHeader.new(net_res.to_hash) @json_data = nil end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
142 143 144 |
# File 'lib/spectre/http.rb', line 142 def body @body end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
142 143 144 |
# File 'lib/spectre/http.rb', line 142 def code @code end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
142 143 144 |
# File 'lib/spectre/http.rb', line 142 def headers @headers end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
142 143 144 |
# File 'lib/spectre/http.rb', line 142 def @message end |
Instance Method Details
#json ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/spectre/http.rb', line 152 def json if !@body.nil? and @json_data.nil? begin @json_data = JSON.parse(@body, object_class: OpenStruct) rescue JSON::ParserError raise HttpError.new("Body content is not a valid JSON:\n#{@body}") end end @json_data end |
#success? ⇒ Boolean
164 165 166 |
# File 'lib/spectre/http.rb', line 164 def success? @code < 400 end |