Class: Helipad::Response

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

Overview

Contains the data returned by Helipad in response to certain API calls.

Various Helipad methods create and return Helipad::Response objects; there is probably little reason to make an instance of Helipad::Response in your own code.

The class contains a number of read-only methods for retrieving a response’s properties. Depending on which Helipad method created the Helipad::Response object, some of these methods may not be present. For example, the Helipad.update method leaves out the doc_id attribute, and Helipad.destroy doesn’t use the saved? method.

  • doc_id - ID of the document associated with the response. Helipad.create returns this to let you know the ID of the document it just created.

  • saved? - true if the document was saved succesfully, otherwise false

  • deleted? - true if the document was deleted successfully, otherwise false

  • raw_response - The raw XML response returned by Helipad. This could be useful if, for some reason, you want to parse the results yourself. See the Helipad API documentation for more information.

Instance Method Summary collapse

Constructor Details

#initialize(raw_response) ⇒ Response

:nodoc:



334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
# File 'lib/helipad.rb', line 334

def initialize(raw_response) #:nodoc:
  doc = REXML::Document.new raw_response
  REXML::XPath.match(doc, "//*").each do |tag|
    suffix = ""
    case tag.name
    when "saved"
      name = "saved"
      suffix = "?"
      value = tag.text == "true" ? true : false
    when "deleted"
      name = "deleted"
      suffix = "?"
      value = tag.text == "true" ? true : false
    when "id"
      name = "doc_id"
      value = Integer(tag.text)
    else
      name = tag.name
      value = tag.text
    end
    self.instance_eval %{
      def self.#{name}#{suffix}
        @#{name}
      end
      @#{name} = value
    }, __FILE__, __LINE__ unless tag.name == "response"
  end
  self.instance_eval %{
    def self.raw_response
      @raw_response
    end
    @raw_response = %{#{raw_response}}
  }, __FILE__, __LINE__
end