Class: CouchObject::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/couch_object/response.rb

Overview

The response returned from the database

Instance Method Summary collapse

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

#bodyObject

the body



14
15
16
# File 'lib/couch_object/response.rb', line 14

def body
  @response.body
end

#codeObject

the response HTTP code



9
10
11
# File 'lib/couch_object/response.rb', line 9

def code
  @response.code.to_i
end

#parseObject

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_bodyObject

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?

Returns:

  • (Boolean)


24
25
26
27
# File 'lib/couch_object/response.rb', line 24

def success?
  # FIXME: make better
  (200...400).include?(code.to_i)
end

#to_documentObject

Returns a CouchObject::Document with the parsed_body set as the attributes



30
31
32
33
34
35
36
# File 'lib/couch_object/response.rb', line 30

def to_document
  if @parsed_body
    Document.new(@parsed_body)
  else
    Document.new(parse.parsed_body)
  end
end