Class: ActiveResource::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/active_resource/http_mock.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body, message = 200, headers = {}) ⇒ Response

Returns a new instance of Response.



324
325
326
327
328
329
330
331
332
333
334
# File 'lib/active_resource/http_mock.rb', line 324

def initialize(body, message = 200, headers = {})
  @body, @message, @headers = body, message.to_s, headers
  @code = @message[0, 3].to_i

  resp_cls = Net::HTTPResponse::CODE_TO_OBJ[@code.to_s]
  if resp_cls && !resp_cls.body_permitted?
    @body = nil
  end

  self["Content-Length"] = @body.nil? ? "0" : body.size.to_s
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



322
323
324
# File 'lib/active_resource/http_mock.rb', line 322

def body
  @body
end

#codeObject

Returns the value of attribute code.



322
323
324
# File 'lib/active_resource/http_mock.rb', line 322

def code
  @code
end

#headersObject

Returns the value of attribute headers.



322
323
324
# File 'lib/active_resource/http_mock.rb', line 322

def headers
  @headers
end

#messageObject

Returns the value of attribute message.



322
323
324
# File 'lib/active_resource/http_mock.rb', line 322

def message
  @message
end

Instance Method Details

#==(other) ⇒ Object

Returns true if the other is a Response with an equal body, equal message and equal headers. Otherwise it returns false.



352
353
354
355
356
357
358
# File 'lib/active_resource/http_mock.rb', line 352

def ==(other)
  if other.is_a?(Response)
    other.body == body && other.message == message && other.headers == headers
  else
    false
  end
end

#[](key) ⇒ Object



342
343
344
# File 'lib/active_resource/http_mock.rb', line 342

def [](key)
  headers[key]
end

#[]=(key, value) ⇒ Object



346
347
348
# File 'lib/active_resource/http_mock.rb', line 346

def []=(key, value)
  headers[key] = value
end

#success?Boolean

Returns true if code is 2xx, false otherwise.

Returns:

  • (Boolean)


338
339
340
# File 'lib/active_resource/http_mock.rb', line 338

def success?
  code.in?(200..299)
end