Exception: DynamicsCRM::XML::Fault

Inherits:
RuntimeError
  • Object
show all
Defined in:
lib/dynamics_crm/xml/fault.rb

Overview

Represents a SOAP Fault Resposible for parsing each element

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fault_xml) ⇒ Fault

Returns a new instance of Fault.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/dynamics_crm/xml/fault.rb', line 10

def initialize(fault_xml)
  if fault_xml.is_a?(Array)
    fault_xml = fault_xml.first
  end
  # REXL::Element
  @code = fault_xml.get_text("//[local-name() = 'Code']/[local-name() = 'Value']")
  @subcode = fault_xml.get_text("//[local-name() = 'Code']/[local-name() = 'Subcode']/[local-name() = 'Value']")
  @reason = fault_xml.get_text("//[local-name() = 'Reason']/[local-name() = 'Text']")

  @detail = {}
  detail_fragment = fault_xml.get_elements("//[local-name() = 'Detail']").first
  if detail_fragment
    fault_type = detail_fragment.elements.first
    @detail[:type] = fault_type.name
    detail_fragment.elements.first.each_element do |node|

      @detail[node.name.to_sym] = node.text
    end
  end
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



8
9
10
# File 'lib/dynamics_crm/xml/fault.rb', line 8

def code
  @code
end

#detailObject (readonly)

Returns the value of attribute detail.



8
9
10
# File 'lib/dynamics_crm/xml/fault.rb', line 8

def detail
  @detail
end

#reasonObject (readonly)

Returns the value of attribute reason.



8
9
10
# File 'lib/dynamics_crm/xml/fault.rb', line 8

def reason
  @reason
end

#subcodeObject (readonly)

Returns the value of attribute subcode.



8
9
10
# File 'lib/dynamics_crm/xml/fault.rb', line 8

def subcode
  @subcode
end

Instance Method Details

#messageObject



31
32
33
34
35
36
37
# File 'lib/dynamics_crm/xml/fault.rb', line 31

def message
  if @detail.empty?
    "%s[%s] %s" % [@code, @subcode, @reason]
  else
    "%s[%s] %s (Detail => %s)" % [@code, @subcode, @reason, @detail]
  end
end