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.



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/active_resource/http_mock.rb', line 162

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.



160
161
162
# File 'lib/active_resource/http_mock.rb', line 160

def body
  @body
end

#codeObject

Returns the value of attribute code.



160
161
162
# File 'lib/active_resource/http_mock.rb', line 160

def code
  @code
end

#headersObject

Returns the value of attribute headers.



160
161
162
# File 'lib/active_resource/http_mock.rb', line 160

def headers
  @headers
end

#messageObject

Returns the value of attribute message.



160
161
162
# File 'lib/active_resource/http_mock.rb', line 160

def message
  @message
end

Instance Method Details

#==(other) ⇒ Object



190
191
192
193
194
195
196
# File 'lib/active_resource/http_mock.rb', line 190

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

#[](key) ⇒ Object



182
183
184
# File 'lib/active_resource/http_mock.rb', line 182

def [](key)
  headers[key]
end

#[]=(key, value) ⇒ Object



186
187
188
# File 'lib/active_resource/http_mock.rb', line 186

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

#success?Boolean

Returns:

  • (Boolean)


178
179
180
# File 'lib/active_resource/http_mock.rb', line 178

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