Class: Contentful::Management::Response
- Inherits:
-
Object
- Object
- Contentful::Management::Response
- 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
-
#error_message ⇒ Object
readonly
Returns the value of attribute error_message.
-
#object ⇒ Object
readonly
Returns the value of attribute object.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#initialize(raw, request = nil) ⇒ Response
constructor
A new instance of Response.
-
#load_json ⇒ Object
Returns the JSON body of the response.
Constructor Details
#initialize(raw, request = nil) ⇒ Response
Returns a new instance of Response.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/contentful/management/response.rb', line 28 def initialize(raw, request = nil) @raw = raw @request = request @status = :ok if valid_http_response? parse_json! elsif no_content_response? @status = :no_content elsif resource_error? parse_contentful_error elsif service_unavailable_response? service_unavailable_error else parse_http_error end end |
Instance Attribute Details
#error_message ⇒ Object (readonly)
Returns the value of attribute error_message.
26 27 28 |
# File 'lib/contentful/management/response.rb', line 26 def @error_message end |
#object ⇒ Object (readonly)
Returns the value of attribute object.
26 27 28 |
# File 'lib/contentful/management/response.rb', line 26 def object @object end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
26 27 28 |
# File 'lib/contentful/management/response.rb', line 26 def raw @raw end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
26 27 28 |
# File 'lib/contentful/management/response.rb', line 26 def request @request end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
26 27 28 |
# File 'lib/contentful/management/response.rb', line 26 def status @status end |
Instance Method Details
#load_json ⇒ Object
Returns the JSON body of the response
47 48 49 |
# File 'lib/contentful/management/response.rb', line 47 def load_json MultiJson.load(unzip_response(raw)) end |