Class: CouchObject::Response
- Inherits:
-
Object
- Object
- CouchObject::Response
- Defined in:
- lib/couch_object/response.rb
Overview
The response returned from the database
Instance Method Summary collapse
-
#body ⇒ Object
the body.
-
#code ⇒ Object
the response HTTP code.
-
#initialize(response) ⇒ Response
constructor
A new instance of Response.
-
#parse ⇒ Object
Parse the response body into JSON and return
self
. -
#parsed_body ⇒ Object
The parsed (to JSON) body.
-
#success? ⇒ Boolean
is the request considered a success?.
-
#to_document ⇒ Object
Returns a CouchObject::Document with the
parsed_body
set as the attributes.
Constructor Details
#initialize(response) ⇒ Response
Returns a new instance of Response.
4 5 6 |
# File 'lib/couch_object/response.rb', line 4 def initialize(response) @response = response end |
Instance Method Details
#body ⇒ Object
the body
14 15 16 |
# File 'lib/couch_object/response.rb', line 14 def body @response.body end |
#code ⇒ Object
the response HTTP code
9 10 11 |
# File 'lib/couch_object/response.rb', line 9 def code @response.code.to_i end |
#parse ⇒ Object
Parse the response body into JSON and return self
39 40 41 42 |
# File 'lib/couch_object/response.rb', line 39 def parse @parsed_body = JSON.parse(body) self end |
#parsed_body ⇒ Object
The parsed (to JSON) body
19 20 21 |
# File 'lib/couch_object/response.rb', line 19 def parsed_body @parsed_body end |
#success? ⇒ Boolean
is the request considered a success?
24 25 26 27 |
# File 'lib/couch_object/response.rb', line 24 def success? # FIXME: make better (200...400).include?(code.to_i) end |