class RealPage::Validator::ProspectsData
Sends parased response's roommate and prospect data to Snowflake via event tracker
Attributes
guest_cards[R]
request_name[R]
request_params[R]
response[R]
Public Class Methods
new(response, request_params, request_name)
click to toggle source
# File lib/real_page/validator/prospects_data.rb, line 11 def initialize(response, request_params, request_name) @response = response @request_params = request_params @request_name = request_name @guest_cards = guest_cards end
Public Instance Methods
validate!()
click to toggle source
# File lib/real_page/validator/prospects_data.rb, line 18 def validate! return if guest_cards.blank? send_data_to_snowflake end
Private Instance Methods
format_date(field)
click to toggle source
# File lib/real_page/validator/prospects_data.rb, line 97 def format_date(field) return nil if field.blank? DateTime.parse(field).to_time end
import_resident_id()
click to toggle source
# File lib/real_page/validator/prospects_data.rb, line 102 def import_resident_id "#{request_params[:import_id]}-#{SecureRandom.alphanumeric(15)}" end
parsed_response()
click to toggle source
# File lib/real_page/validator/prospects_data.rb, line 78 def parsed_response body = response['s:Envelope']['s:Body'] response_key = body.keys.detect { |key| key !~ /^xmlns/ } contents_response = body.fetch(response_key) result_key = contents_response.keys.detect { |key| key !~ /^xmlns/ } contents_result = contents_response.fetch(result_key) result = contents_result.values.first end
phones_count(prospect)
click to toggle source
# File lib/real_page/validator/prospects_data.rb, line 87 def phones_count(prospect) phone_numbers_hash = prospect.dig('Numbers', 'PhoneNumber') return 0 if phone_numbers_hash.blank? if !phone_numbers_hash.is_a?(Array) return 0 if phone_numbers_hash['Number'].blank? return 1 end phone_numbers_hash.select { |phone_number| !phone_number['Number'].blank? }.length end
prospects(guest_card)
click to toggle source
# File lib/real_page/validator/prospects_data.rb, line 71 def prospects(guest_card) prospects_hash = guest_card.dig('Prospects', 'Prospect') return [] if prospects_hash.nil? return [prospects_hash] unless prospects_hash.is_a?(Array) prospects_hash end
send_data_to_snowflake()
click to toggle source
# File lib/real_page/validator/prospects_data.rb, line 27 def send_data_to_snowflake guest_cards.each do |guest_card| prospects_of_current_guest_card = prospects(guest_card) send_roommates_data_to_snowflake(prospects_of_current_guest_card) send_prospects_data_to_snowflake(prospects_of_current_guest_card, guest_card) end end
send_prospects_data_to_snowflake(prospects, guest_card)
click to toggle source
# File lib/real_page/validator/prospects_data.rb, line 52 def send_prospects_data_to_snowflake(prospects, guest_card) prospects.each do |prospect| Utils::SnowflakeEventTracker.track_pms_prospect_event( resident_type: 'PRIMARY', request_params: request_params, contact_date: format_date(guest_card['CreateDate']), contact_source: guest_card['PrimaryLeadSource'], remote_prospect_id: guest_card['GuestCardID'] ) end end
send_roommates_data_to_snowflake(prospects)
click to toggle source
# File lib/real_page/validator/prospects_data.rb, line 35 def send_roommates_data_to_snowflake(prospects) prospects.each do |prospect| prospect['ImportResidentId'] = import_resident_id Utils::SnowflakeEventTracker.track_pms_resident_event( import_resident_id: prospect['ImportResidentId'], resident_type: 'ROOMMATE', api_name: request_name, request_params: request_params, first_name_present: !prospect['FirstName'].blank?, last_name_present: !prospect['LastName'].blank?, email_present: !prospect['Email'].blank?, phones_count: phones_count(prospect), unit_name: '' ) end end