Class: Spectre::Http::SpectreHttpResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/spectre/http.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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
  @message = net_res.message
  @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

#bodyObject (readonly)

Returns the value of attribute body.



189
190
191
# File 'lib/spectre/http.rb', line 189

def body
  @body
end

#codeObject (readonly)

Returns the value of attribute code.



189
190
191
# File 'lib/spectre/http.rb', line 189

def code
  @code
end

#headersObject (readonly)

Returns the value of attribute headers.



189
190
191
# File 'lib/spectre/http.rb', line 189

def headers
  @headers
end

#jsonObject (readonly)

Returns the value of attribute json.



189
190
191
# File 'lib/spectre/http.rb', line 189

def json
  @json
end

#messageObject (readonly)

Returns the value of attribute message.



189
190
191
# File 'lib/spectre/http.rb', line 189

def message
  @message
end

Instance Method Details

#success?Boolean

Returns:

  • (Boolean)


207
208
209
# File 'lib/spectre/http.rb', line 207

def success?
  @code < 400
end