class Yardi::Validator::MissingProperty

Make sure the property we're trying to send a guestcard for is configured in Yardi's system. For an example, @see invalid_property.xml

Constants

UNCONFIGURED_PROPERTY_REGEX

Attributes

action[R]
response[R]

Public Class Methods

new(action:, parsed_response:) click to toggle source

@param parsed_response [Hash<String, Object>] the XML response parsed

into a Hash
# File lib/yardi/validator/missing_property.rb, line 12
def initialize(action:, parsed_response:)
  @action = action
  @response = parsed_response
end

Public Instance Methods

validate!() click to toggle source

@raise [Yardi::Error::ErrorResponse] if the response is effectively

empty
# File lib/yardi/validator/missing_property.rb, line 19
def validate!
  return if valid_property?
  raise Error::MissingProperty, message
end

Private Instance Methods

message() click to toggle source

This looks like: test0123:Invalid Yardi Property Code. In the example, the remote property ID that was invalid is 'test0123'.

Successful guestcard insertion responses have multiple Message nodes, which become an array after parsing.

Successful prospect search responses don't have any Message nodes at all.

If there is only one Message node (in the case where we have an error, perhaps an invalid property), it will be a Hash. When we have an array, we know it isn't an invalid property error so we return an empty string which will fail the comparison to the regex.

# File lib/yardi/validator/missing_property.rb, line 46
def message
  body = response['soap:Envelope']['soap:Body']
  # This will be picked up by either the EmptyResponse or the
  # FaultResponse check. Whatever it is, it's not a MissingProperty issue.
  return '' if body["#{action}Response"].nil?
  result = body["#{action}Response"]["#{action}Result"]
  # There are no Messages nodes in a successful
  # GetYardiGuestActivity_Search response
  return '' if result['Messages'].nil?
  messages = result['Messages']['Message']
  messages.is_a?(Hash) ? messages['__content__'] : ''
end
valid_property?() click to toggle source
# File lib/yardi/validator/missing_property.rb, line 28
def valid_property?
  message !~ UNCONFIGURED_PROPERTY_REGEX
end