Class: Yardi::Validator::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/yardi/validator/base.rb

Instance Method Summary collapse

Instance Method Details

#import_resident_id(params) ⇒ Object



101
102
103
# File 'lib/yardi/validator/base.rb', line 101

def import_resident_id(params)
  "#{params[:import_id]}-#{SecureRandom.alphanumeric(15)}"
end

#parse_date(date) ⇒ Object



97
98
99
# File 'lib/yardi/validator/base.rb', line 97

def parse_date(date)
  (date && Date.strptime(date, '%m/%d/%Y'))&.to_time
end

#pms_prospect_request_params(params) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
# File 'lib/yardi/validator/base.rb', line 85

def pms_prospect_request_params(params)
  {
    property_id: params[:billing_config]&.property_id,
    billing_config_id: params[:billing_config]&.id,
    remote_id: params[:property_id],
    import_id: params[:import_id],
    pmc_id: params[:pmc_id],
    import_resident_id: params[:import_resident_id],
    prospect_id: params[:prospect]&.yardi_prospect_id
  }
end

#pms_resident_request_params(params) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/yardi/validator/base.rb', line 50

def pms_resident_request_params(params)
  {
    start_date: params[:start_date]&.to_time,
    end_date: params[:end_date]&.to_time,
    prospect_id: nil,
    pmc_id: params[:pmc_id],
    remote_id: params[:property_id],
    traffic_source_id: nil,
    import_id: params[:import_id],
    billing_config_id: params[:billing_config]&.id,
    property_id: params[:billing_config]&.property_id
  }
end

#remote_id(customer, id_type) ⇒ Object



105
106
107
108
109
110
111
# File 'lib/yardi/validator/base.rb', line 105

def remote_id(customer, id_type)
  desired_id_node = customer['Identification']&.detect do |id_node|
    id_node['IDType'] == id_type
  end

  desired_id_node['IDValue']
end

#send_pms_prospect_event(params:, event: nil, error_message: nil) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/yardi/validator/base.rb', line 64

def send_pms_prospect_event(params:, event: nil, error_message: nil)
  if event
    contact_date = event['EventDate']&.to_time
    contact_source = event['TransactionSource']
  else
    contact_date, contact_source = [nil] * 2
  end
  Utils::SnowflakeEventTracker.track_pms_prospect_event(
    remote_lease_id: nil,
    request_params: pms_prospect_request_params(params),
    first_name_present: params[:prospect]&.first_name.present?,
    last_name_present: params[:prospect]&.last_name.present?,
    email_present: params[:prospect]&.email.present?,
    phone_present: params[:prospect]&.phone.present?,
    contact_date: contact_date,
    contact_source: contact_source,
    remote_prospect_id: params[:prospect]&.yardi_prospect_id,
    error: error_message
  )
end

#send_pms_resident_event(lease:, resident_type:, params:, error_message: nil) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/yardi/validator/base.rb', line 11

def send_pms_resident_event(lease:, resident_type:, params:, error_message: nil)
  if lease
    remote_lease_id = lease['tCode']
    import_resident_id = lease['import_resident_id']
    move_in_date = parse_date(lease['MoveInDate'])
    lease_to = parse_date(lease['LeaseToDate'])
    lease_from = parse_date(lease['LeaseFromDate'])
    first_name_present = lease['FirstName'].present?
    last_name_present = lease['LastName'].present?
    email_present = lease['Email'].present?
    phones_count = (Utils::PhoneParser.parse(lease['Phone']) || []).length
    unit_name = lease['UnitCode'] || ''
    resident_id = lease['tCode']
  else
    remote_lease_id, move_in_date, lease_to, lease_from = [nil] * 4
    import_resident_id = params[:import_id]
    first_name_present, last_name_present, email_present = [false] * 3
    phones_count = 0
    unit_name = ''
    resident_id = nil
  end
  Utils::SnowflakeEventTracker.track_pms_resident_event(
    remote_lease_id: remote_lease_id,
    import_resident_id: import_resident_id,
    resident_type: resident_type,
    request_params: pms_resident_request_params(params),
    move_in_date: move_in_date,
    lease_to: lease_to,
    lease_from: lease_from,
    first_name_present: first_name_present,
    last_name_present: last_name_present,
    email_present: email_present,
    phones_count: phones_count,
    unit_name: unit_name,
    resident_id: resident_id,
    error: error_message
  )
end