Class: Contentful::Response

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

Overview

An object representing an answer by the contentful service. It is later used to build a Resource, which is done by the ResourceBuilder.

The Response parses the http response (as returned by the underlying http library) to a JSON object. Responses can be asked the following methods:

  • #raw (raw HTTP response by the HTTP library)

  • #object (the parsed JSON object)

It also sets a #status which can be one of:

  • :ok (seems to be a valid resource object)

  • :contentful_error (valid error object)

  • :not_contentful (valid json, but missing the contentful's sys property)

  • :unparsable_json (invalid json)

Error Repsonses also contain a:

  • :error_message

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Response) initialize(raw)

Returns a new instance of Response



24
25
26
27
28
29
30
31
# File 'lib/contentful/response.rb', line 24

def initialize(raw)
  @raw = raw
  @status = :ok

  if parse_json!
    parse_contentful_error!
  end
end

Instance Attribute Details

- (Object) error_message (readonly)

Returns the value of attribute error_message



22
23
24
# File 'lib/contentful/response.rb', line 22

def error_message
  @error_message
end

- (Object) object (readonly)

Returns the value of attribute object



22
23
24
# File 'lib/contentful/response.rb', line 22

def object
  @object
end

- (Object) raw (readonly)

Returns the value of attribute raw



22
23
24
# File 'lib/contentful/response.rb', line 22

def raw
  @raw
end

- (Object) status (readonly)

Returns the value of attribute status



22
23
24
# File 'lib/contentful/response.rb', line 22

def status
  @status
end