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.



256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/active_resource/http_mock.rb', line 256

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

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

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



254
255
256
# File 'lib/active_resource/http_mock.rb', line 254

def body
  @body
end

#codeObject

Returns the value of attribute code.



254
255
256
# File 'lib/active_resource/http_mock.rb', line 254

def code
  @code
end

#headersObject

Returns the value of attribute headers.



254
255
256
# File 'lib/active_resource/http_mock.rb', line 254

def headers
  @headers
end

#messageObject

Returns the value of attribute message.



254
255
256
# File 'lib/active_resource/http_mock.rb', line 254

def message
  @message
end

Instance Method Details

#==(other) ⇒ Object



284
285
286
287
288
289
290
# File 'lib/active_resource/http_mock.rb', line 284

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

#[](key) ⇒ Object



276
277
278
# File 'lib/active_resource/http_mock.rb', line 276

def [](key)
  headers[key]
end

#[]=(key, value) ⇒ Object



280
281
282
# File 'lib/active_resource/http_mock.rb', line 280

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

#success?Boolean

Returns:

  • (Boolean)


272
273
274
# File 'lib/active_resource/http_mock.rb', line 272

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