class DynamicsCRM::Response::Result

Attributes

document[R]
result_response[R]

Public Class Methods

new(xml) click to toggle source
# File lib/dynamics_crm/response/result.rb, line 7
def initialize(xml)
  @document = REXML::Document.new(xml)

  fault_xml = @document.get_elements("//[local-name() = 'Fault']")
  raise XML::Fault.new(fault_xml) if fault_xml.any?

  @result_response = @document.get_elements("//#{response_element}").first

  # Child classes should override this method.
  h = parse_result_response(@result_response)

  # Calling super causes undesired behavior so just merge.
  self.merge!(h)
end

Public Instance Methods

method_missing(method, *args, &block) click to toggle source

Allows method-like access to the hash using camelcase field names.

# File lib/dynamics_crm/response/result.rb, line 34
def method_missing(method, *args, &block)
  # First return local hash entry for symbol or string.
  return self[method] if self.has_key?(method)

  string_method = method.to_s
  return self[string_method] if self.has_key?(string_method)

  value = nil
  # Then check if string converted to underscore finds a match.
  if string_method =~ /[A-Z+]/
    string_method = ::DynamicsCRM::StringUtil.underscore(string_method)
    value = self[string_method] || self[string_method.to_sym]
  end

  # Finally return nil.
  value
end
parse_result_response(result) click to toggle source

Invoked by constructor, should be implemented in sub-classes.

# File lib/dynamics_crm/response/result.rb, line 28
def parse_result_response(result)
  # do nothing here
  {}
end
respond_to_missing?(method_name, include_private = false) click to toggle source
Calls superclass method
# File lib/dynamics_crm/response/result.rb, line 52
def respond_to_missing?(method_name, include_private = false)
  self.has_key?(method_name.to_s) || self.has_key?(method_name) || super
end
response_element() click to toggle source

Returns base element of the response document to parse.

# File lib/dynamics_crm/response/result.rb, line 23
def response_element
  class_name = self.class.to_s.split('::').last
end