Sha256: 4bf57c9ed81e0a141c3d9bf6d8247113f0d7765b1bb518a391a366aa16f48eb9

Contents?: true

Size: 1.2 KB

Versions: 6

Compression:

Stored size: 1.2 KB

Contents

require 'yardi/validator'
require_relative 'base'

module Yardi
  module Validator
    class ProspectEventing < Base
      # Sends parased response's roommate and prospect data to Snowflake via event tracker
      def initialize(action:, parsed_response:, params:)
        @action = action
        @response = parsed_response
        @params = params
      end

      def validate!
        return if response.nil?

        send_prospect_events
      end

      private

      attr_reader :action, :response, :params

      def send_prospect_events
        body = if response['soap:Envelope']
                 response['soap:Envelope']['soap:Body']
               else
                 response['Envelope']['Body']
               end

        result_node = body["#{action}Response"]["#{action}Result"]
        prospects = result_node['LeadManagement']['Prospects']['Prospect']
        prospects = [prospects] unless prospects.is_a?(Array)
        prospects.map do |prospect|
          events = prospect.dig('Events', 'Event') || []
          events_array = events.is_a?(Array) ? events : [events]
          events_array.each { |event| send_pms_prospect_event(params: params, event: event) }
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

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