Class: Fleakr::Api::Response

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

Overview

Response

Response objects contain Hpricot documents that are traversed and parsed by the model objects. This class is never called directly but is instantiated during the request cycle (see: Fleakr::Api::MethodRequest.with_response!)

Instance Method Summary collapse

Constructor Details

#initialize(response_xml) ⇒ Response

Creates a new response from a raw XML string returned from a Request



13
14
15
# File 'lib/fleakr/api/response.rb', line 13

def initialize(response_xml)
  @response_xml = response_xml
end

Instance Method Details

#bodyObject

Return a document-based representation of the XML contained in the API response. This is an Hpricot document object



19
20
21
# File 'lib/fleakr/api/response.rb', line 19

def body
  @body ||= Hpricot.XML(@response_xml)
end

#errorObject

Access the API error if one exists



29
30
31
# File 'lib/fleakr/api/response.rb', line 29

def error
  Fleakr::Objects::Error.new(self.body) if self.error?
end

#error?Boolean

Did the response from the API contain errors?

Returns:

  • (Boolean)


24
25
26
# File 'lib/fleakr/api/response.rb', line 24

def error?
  (self.body/'rsp').attr('stat') != 'ok'
end