Class: Contentful::Management::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/contentful/management/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)

  • #request (the request the response is refering to)

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

#initialize(raw, request = nil) ⇒ Response

Returns a new instance of Response.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/contentful/management/response.rb', line 27

def initialize(raw, request = nil)
  @raw = raw
  @request = request
  @status = :ok

  if service_unavailable_response?
    @status = :service_unavailable
    @error_message = 'Service Unavailable, contenful.com API seems to be down'
  elsif no_content_response?
    @status = :no_content
    @object = true
  elsif parse_json!
    parse_contentful_error!
  end
end

Instance Attribute Details

#error_messageObject (readonly)

Returns the value of attribute error_message.



25
26
27
# File 'lib/contentful/management/response.rb', line 25

def error_message
  @error_message
end

#objectObject (readonly)

Returns the value of attribute object.



25
26
27
# File 'lib/contentful/management/response.rb', line 25

def object
  @object
end

#rawObject (readonly)

Returns the value of attribute raw.



25
26
27
# File 'lib/contentful/management/response.rb', line 25

def raw
  @raw
end

#requestObject (readonly)

Returns the value of attribute request.



25
26
27
# File 'lib/contentful/management/response.rb', line 25

def request
  @request
end

#statusObject (readonly)

Returns the value of attribute status.



25
26
27
# File 'lib/contentful/management/response.rb', line 25

def status
  @status
end