Class: Episodic::Platform::Response

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

Overview

Base class for responses. This class takes the response and parses the body using XmlSimple.

If the response body contains an error then this method will throw the appropriate exception.

Direct Known Subclasses

CollectionResponse, TokenResponse, WriteResponse

Instance Method Summary collapse

Constructor Details

#initialize(response, xml_options = {}) ⇒ Response

Constructor

Parameters

response<Episodic::Platform::HttpResponse>

The response object returned from an Episodic Platform API request.

xml_options<Hash>

A set of options used by XmlSimple when parsing the response body



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/episodic/platform/response.rb', line 18

def initialize response, xml_options = {}
  @response = response
  xml_options['ForceArray'] ||= false
  @parsed_body = ::XmlSimple.xml_in(@response.body, xml_options.merge({'KeepRoot' => true}))
  
  # Now that we have parsed the response, we can make sure that it is valid or otherwise
  # throw an exception.
  if @parsed_body["error"]
    handle_error_response(@parsed_body["error"])
  else
    # Remove the root element
    @parsed_body = @parsed_body[@parsed_body.keys.first]
  end
end

Instance Method Details

#xmlObject

Provides access to the unparsed XML response

Returns

String

The XML response as a string.



40
41
42
# File 'lib/episodic/platform/response.rb', line 40

def xml
  return @response.body
end