Class: Exchanger::Operation::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Response

Returns a new instance of Response.


73
74
75
76
77
78
# File 'lib/exchanger/operation.rb', line 73

def initialize(options = {})
  @status = options[:status]
  @body   = options[:body]
  parse_soap_errors
  parse_response_message
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body


71
72
73
# File 'lib/exchanger/operation.rb', line 71

def body
  @body
end

#statusObject (readonly)

Returns the value of attribute status


71
72
73
# File 'lib/exchanger/operation.rb', line 71

def status
  @status
end

Instance Method Details

#codeObject

Raises:

  • (NotImplemented)

105
106
107
# File 'lib/exchanger/operation.rb', line 105

def code
  raise NotImplemented
end

#parse_response_messageObject

Checks the ResponseMessage for errors.

msdn.microsoft.com/en-us/library/aa494164%28EXCHG.80%29.aspx Exhange 2007 Valid Response Messages


96
97
98
99
100
101
102
103
# File 'lib/exchanger/operation.rb', line 96

def parse_response_message
  error_node = to_xml.xpath('//m:ResponseMessages/child::*[@ResponseClass="Error"]', NS)
  unless error_node.empty?
    error_msg = error_node.xpath('m:MessageText/text()', NS).to_s
    response_code = error_node.xpath('m:ResponseCode/text()', NS).to_s
    raise ResponseError.new(error_msg, response_code)
  end
end

#parse_soap_errorsObject


84
85
86
87
88
89
90
# File 'lib/exchanger/operation.rb', line 84

def parse_soap_errors
  fault_node = to_xml.xpath(".//faultstring")
  unless fault_node.empty?
    error_msg = fault_node.text
    raise ResponseError.new(error_msg, 0)
  end
end

#to_xmlObject


80
81
82
# File 'lib/exchanger/operation.rb', line 80

def to_xml
  @xml ||= Nokogiri::XML(@body)
end