Sha256: f73af1958ae9ee4ebdb480a87e31d039f6235dc8e72f0f0efed3de55ba905032

Contents?: true

Size: 1.55 KB

Versions: 6

Compression:

Stored size: 1.55 KB

Contents

require 'yardi/validator'
require_relative 'base'

module Yardi
  module Validator
    class ResidentEventing < Base
      attr_reader :action, :response, :params

      # Send parased response's individual resident data to Snowflake via event tracker
      def initialize(action:, parsed_response:, params:)
        @action = action
        @response = parsed_response
        @params = params
      end

      # @raise [Yardi::Error::EmptyResponse] if the response is effectively
      #   empty
      def validate!
        return if response.nil?

        body = if response['soap:Envelope']
                 response['soap:Envelope']['soap:Body']
               else
                 response['Envelope']['Body']
               end
        result_node = body["#{action}Response"]["#{action}Result"]
        path = %w[MITS_ResidentData PropertyResidents Residents Resident]
        results = [result_node.dig(*path)].flatten.compact
        results.map { |resident| send_all_events(resident) }
      end

      def send_all_events(resident)
        resident['import_resident_id'] = import_resident_id(params)
        send_pms_resident_event(lease: resident, resident_type: 'PRIMARY', params: params)
        roommate_nodes = resident.dig('OtherOccupants', 'OtherOccupant')
        unless roommate_nodes.nil?
          [roommate_nodes].flatten.map do |roommate|
            roommate['import_resident_id'] = import_resident_id(params)
            send_pms_resident_event(lease: roommate, resident_type: 'ROOMMATE', params: params)
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
yardi-4.11.4 lib/yardi/validator/resident_eventing.rb
yardi-4.11.3 lib/yardi/validator/resident_eventing.rb
yardi-5.0.1 lib/yardi/validator/resident_eventing.rb
yardi-4.11.2 lib/yardi/validator/resident_eventing.rb
yardi-4.11.1 lib/yardi/validator/resident_eventing.rb
yardi-4.11.0 lib/yardi/validator/resident_eventing.rb