Class: Yardi::DocumentParser::Base
- Inherits:
-
Object
- Object
- Yardi::DocumentParser::Base
- Defined in:
- lib/yardi/document_parser/base.rb
Overview
Base class for parsing Yardi responses. Subclasses must implement #parse_body and can optionally override #validator_classes to add more validation than just the default
Direct Known Subclasses
GuestCardImportResponseObject, Properties, Prospects, Residents
Instance Method Summary collapse
-
#initialize(params) ⇒ Base
constructor
A new instance of Base.
-
#parse(xml) ⇒ Object
The parsed object(s) from the rsesponse.
Constructor Details
#initialize(params) ⇒ Base
Returns a new instance of Base.
28 29 30 31 |
# File 'lib/yardi/document_parser/base.rb', line 28 def initialize(params) @params = params after_initialize(params) end |
Instance Method Details
#parse(xml) ⇒ Object
Returns the parsed object(s) from the rsesponse.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/yardi/document_parser/base.rb', line 36 def parse(xml) begin parsed = MultiXml.parse(xml) rescue MultiXml::ParseError => e raise unparsable_xml_error(xml) end return [] if test_data_not_found?(parsed) # This is a temporary code to be able to see what Yardi response # looks like when envelope is empty. if !parsed.empty? && parsed['soap:Envelope'].nil? && parsed['Envelope'].nil? if ((parsed['html'] || {})['head'] || {})['title'] raise Yardi::Error::ErrorResponse, parsed['html']['head']['title'] else raise Yardi::Error::UnparsableResponse, xml end end [*DEFAULT_VALIDATOR_CLASSES, *validator_classes].each do |klass| klass.new(action: action, parsed_response: parsed, params: @params).validate! end if parsed['soap:Envelope'] parse_body(parsed['soap:Envelope']['soap:Body']) else parse_body(parsed['Envelope']['Body']) end end |