class ActiveResource::Response

Attributes

body[RW]
code[RW]
headers[RW]
message[RW]

Public Class Methods

new(body, message = 200, headers = {}) click to toggle source
# File lib/active_resource/http_mock.rb, line 311
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

Public Instance Methods

==(other) click to toggle source

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

# File lib/active_resource/http_mock.rb, line 340
def ==(other)
  if (other.is_a?(Response))
    other.body == body && other.message == message && other.headers == headers
  else
    false
  end
end
[](key) click to toggle source
# File lib/active_resource/http_mock.rb, line 330
def [](key)
  headers[key]
end
[]=(key, value) click to toggle source
# File lib/active_resource/http_mock.rb, line 334
def []=(key, value)
  headers[key] = value
end
success?() click to toggle source

Returns true if code is 2xx, false otherwise.

# File lib/active_resource/http_mock.rb, line 326
def success?
  code.in?(200..299)
end