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.



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/active_resource/http_mock.rb', line 101

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

#body ⇒ Object

Returns the value of attribute body.



99
100
101
# File 'lib/active_resource/http_mock.rb', line 99

def body
  @body
end

#code ⇒ Object

Returns the value of attribute code.



99
100
101
# File 'lib/active_resource/http_mock.rb', line 99

def code
  @code
end

#headers ⇒ Object

Returns the value of attribute headers.



99
100
101
# File 'lib/active_resource/http_mock.rb', line 99

def headers
  @headers
end

#message ⇒ Object

Returns the value of attribute message.



99
100
101
# File 'lib/active_resource/http_mock.rb', line 99

def message
  @message
end

Instance Method Details

#==(other) ⇒ Object



129
130
131
132
133
134
135
# File 'lib/active_resource/http_mock.rb', line 129

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

#[](key) ⇒ Object



121
122
123
# File 'lib/active_resource/http_mock.rb', line 121

def [](key)
  headers[key]
end

#[]=(key, value) ⇒ Object



125
126
127
# File 'lib/active_resource/http_mock.rb', line 125

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

#success? ⇒ Boolean

Returns:

  • (Boolean)


117
118
119
# File 'lib/active_resource/http_mock.rb', line 117

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