Class: Distelli::XmlMarshaller
- Inherits:
-
Marshaller
- Object
- Marshaller
- Distelli::XmlMarshaller
- Defined in:
- lib/distelli/servicemarshallers.rb
Overview
XML Marshaller
Instance Method Summary collapse
-
#initialize ⇒ XmlMarshaller
constructor
A new instance of XmlMarshaller.
- #marshall(request) ⇒ Object
- #marshall_error(error) ⇒ Object
- #unmarshall(xml_data) ⇒ Object
-
#unmarshall_error(xml_data) ⇒ Object
Unmarshalls an xml error response and returns the error code and message.
Methods inherited from Marshaller
Constructor Details
#initialize ⇒ XmlMarshaller
Returns a new instance of XmlMarshaller.
200 201 202 |
# File 'lib/distelli/servicemarshallers.rb', line 200 def initialize() super end |
Instance Method Details
#marshall(request) ⇒ Object
204 205 206 207 |
# File 'lib/distelli/servicemarshallers.rb', line 204 def marshall(request) root_tag_name = request.class.name.split('::').last return ['<', root_tag_name,'>', encode_obj_xml(request), '</', root_tag_name, '>'].join('') end |
#marshall_error(error) ⇒ Object
215 216 217 218 219 220 221 222 223 |
# File 'lib/distelli/servicemarshallers.rb', line 215 def marshall_error(error) if not error.is_a?(Distelli::BaseException) raise StandardError.new("Cannot marshall error: "+error.inspect) end err_msg = error.err_msg err_code = error.err_code return "<Error><code>"+err_code.to_s+"</code><message>"+err_msg.to_s+"</message></Error>" end |
#unmarshall(xml_data) ⇒ Object
209 210 211 212 213 |
# File 'lib/distelli/servicemarshallers.rb', line 209 def unmarshall(xml_data) xml_doc = Nokogiri::XML(xml_data) root_node = xml_doc.root return unmarshall_obj(root_node) end |
#unmarshall_error(xml_data) ⇒ Object
Unmarshalls an xml error response and returns the error
code and message.
This is what an xml error looks like:
<Error>
<code>MalformedRequest</code>
<message>The request is malformed</message>
</Error>
236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/distelli/servicemarshallers.rb', line 236 def unmarshall_error(xml_data) xml_doc = Nokogiri::XML(xml_data) err_code_elem = xml_doc.xpath('//'+ServiceConstants::ERROR_KEY+'//'+ServiceConstants::ERR_CODE_KEY) err_msg_elem = xml_doc.xpath('//'+ServiceConstants::ERROR_KEY+'//'+ServiceConstants::ERR_MSG_KEY) err_code = nil err_msg = nil if err_code_elem != nil err_code = err_code_elem.text end if err_msg_elem != nil err_msg = err_msg_elem.text end return [err_code, err_msg] end |