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


286
287
288
289
290
291
292
293
294
295
296
297
# File 'lib/active_resource/http_mock.rb', line 286

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


284
285
286
# File 'lib/active_resource/http_mock.rb', line 284

def body
  @body
end

#codeObject

Returns the value of attribute code


284
285
286
# File 'lib/active_resource/http_mock.rb', line 284

def code
  @code
end

#headersObject

Returns the value of attribute headers


284
285
286
# File 'lib/active_resource/http_mock.rb', line 284

def headers
  @headers
end

#messageObject

Returns the value of attribute message


284
285
286
# File 'lib/active_resource/http_mock.rb', line 284

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.


315
316
317
318
319
320
321
# File 'lib/active_resource/http_mock.rb', line 315

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

#[](key) ⇒ Object


305
306
307
# File 'lib/active_resource/http_mock.rb', line 305

def [](key)
  headers[key]
end

#[]=(key, value) ⇒ Object


309
310
311
# File 'lib/active_resource/http_mock.rb', line 309

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

#success?Boolean

Returns true if code is 2xx, false otherwise.

Returns:

  • (Boolean)

301
302
303
# File 'lib/active_resource/http_mock.rb', line 301

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