Class: ActiveResource::Response

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

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

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

Returns a new instance of Response



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'activeresource/lib/active_resource/http_mock.rb', line 186

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

- (Object) body

Returns the value of attribute body



184
185
186
# File 'activeresource/lib/active_resource/http_mock.rb', line 184

def body
  @body
end

- (Object) code

Returns the value of attribute code



184
185
186
# File 'activeresource/lib/active_resource/http_mock.rb', line 184

def code
  @code
end

- (Object) headers

Returns the value of attribute headers



184
185
186
# File 'activeresource/lib/active_resource/http_mock.rb', line 184

def headers
  @headers
end

- (Object) message

Returns the value of attribute message



184
185
186
# File 'activeresource/lib/active_resource/http_mock.rb', line 184

def message
  @message
end

Instance Method Details

- (Object) ==(other)



214
215
216
217
218
219
220
# File 'activeresource/lib/active_resource/http_mock.rb', line 214

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

- (Object) [](key)



206
207
208
# File 'activeresource/lib/active_resource/http_mock.rb', line 206

def [](key)
  headers[key]
end

- (Object) []=(key, value)



210
211
212
# File 'activeresource/lib/active_resource/http_mock.rb', line 210

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

- (Boolean) success?

Returns:

  • (Boolean)


202
203
204
# File 'activeresource/lib/active_resource/http_mock.rb', line 202

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