Class: ActiveResource::Response
- Inherits:
-
Object
- Object
- ActiveResource::Response
- Defined in:
- lib/active_resource/http_mock.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#code ⇒ Object
Returns the value of attribute code.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#message ⇒ Object
Returns the value of attribute message.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Returns true if the other is a Response with an equal body, equal message and equal headers.
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#initialize(body, message = 200, headers = {}) ⇒ Response
constructor
A new instance of Response.
-
#success? ⇒ Boolean
Returns true if code is 2xx, false otherwise.
Constructor Details
#initialize(body, message = 200, headers = {}) ⇒ Response
Returns a new instance of Response.
309 310 311 312 313 314 315 316 317 318 319 |
# File 'lib/active_resource/http_mock.rb', line 309 def initialize(body, = 200, headers = {}) @body, @message, @headers = body, .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
#body ⇒ Object
Returns the value of attribute body.
307 308 309 |
# File 'lib/active_resource/http_mock.rb', line 307 def body @body end |
#code ⇒ Object
Returns the value of attribute code.
307 308 309 |
# File 'lib/active_resource/http_mock.rb', line 307 def code @code end |
#headers ⇒ Object
Returns the value of attribute headers.
307 308 309 |
# File 'lib/active_resource/http_mock.rb', line 307 def headers @headers end |
#message ⇒ Object
Returns the value of attribute message.
307 308 309 |
# File 'lib/active_resource/http_mock.rb', line 307 def @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.
337 338 339 340 341 342 343 |
# File 'lib/active_resource/http_mock.rb', line 337 def ==(other) if other.is_a?(Response) other.body == body && other. == && other.headers == headers else false end end |
#[](key) ⇒ Object
327 328 329 |
# File 'lib/active_resource/http_mock.rb', line 327 def [](key) headers[key] end |
#[]=(key, value) ⇒ Object
331 332 333 |
# File 'lib/active_resource/http_mock.rb', line 331 def []=(key, value) headers[key] = value end |
#success? ⇒ Boolean
Returns true if code is 2xx, false otherwise.
323 324 325 |
# File 'lib/active_resource/http_mock.rb', line 323 def success? code.in?(200..299) end |