class Yardi::RequestSection::LeadManagement

Generate the LeadManagement section of a Yardi request

Attributes

agent[R]
lead_source[R]
property[R]
reason[R]
user[R]

Public Class Methods

new(agent:, lead_source:, property:, reason:, user:) click to toggle source
# File lib/yardi/request_section/lead_management.rb, line 7
def initialize(agent:, lead_source:, property:, reason:, user:)
  @agent = agent
  @lead_source = lead_source
  @property = property
  @reason = reason
  @user = user
end

Public Instance Methods

generate(xml_builder) click to toggle source
# File lib/yardi/request_section/lead_management.rb, line 15
def generate(xml_builder)
  xml_builder.LeadManagement do |lead_management_xml|
    lead_management_xml.Prospects do |prospects_xml|
      prospect_xml(prospects_xml)
    end
  end
end

Private Instance Methods

agent_xml(xml_builder) click to toggle source
# File lib/yardi/request_section/lead_management.rb, line 121
def agent_xml(xml_builder)
  xml_builder.Agent do |agent_xml|
    agent_xml.AgentName do |agent_name_xml|
      agent_name_xml.FirstName agent.first_name
      agent_name_xml.LastName  agent.last_name
    end
  end
end
apartmentlist_id_attributes() click to toggle source
# File lib/yardi/request_section/lead_management.rb, line 72
def apartmentlist_id_attributes
  {
    'IDType' => 'ThirdPartyID',
    'IDValue' => user.id, # AL User ID
    'OrganizationName' => 'Apartment List'
  }
end
contact_information_xml(xml_builder) click to toggle source
# File lib/yardi/request_section/lead_management.rb, line 58
def contact_information_xml(xml_builder)
  phone_xml(user.contact_info.home_phone, 'home', xml_builder)
  phone_xml(user.contact_info.cell_phone, 'cell', xml_builder)
  xml_builder.Email user.contact_info.email
end
customers_xml(xml_builder) click to toggle source
# File lib/yardi/request_section/lead_management.rb, line 39
def customers_xml(xml_builder)
  xml_builder.Customers do |customers_xml|
    customers_xml.Customer('Type' => 'prospect') do |customer_xml|
      # ID nodes are empty nodes with attributes
      customer_xml.Identification(apartmentlist_id_attributes) {}
      customer_xml.Identification(yardi_id_attributes) {}
      name_xml(customer_xml)
      contact_information_xml(customer_xml)
    end
  end
end
first_contact_event_xml(xml_builder) click to toggle source
# File lib/yardi/request_section/lead_management.rb, line 107
def first_contact_event_xml(xml_builder)
  event_attrs = {
    'EventDate' => property.first_contact_time.iso8601,
    'EventType' => 'Email'
  }
  xml_builder.Event(event_attrs) do |event_xml|
    agent_xml(event_xml)
    event_xml.EventReasons reason
    event_xml.FirstContact true
    event_xml.Comments user.message
    event_xml.TransactionSource lead_source
  end
end
name_xml(xml_builder) click to toggle source
# File lib/yardi/request_section/lead_management.rb, line 51
def name_xml(xml_builder)
  xml_builder.Name do |name_xml|
    name_xml.FirstName user.first_name
    name_xml.LastName user.last_name
  end
end
phone_xml(number, type, xml_builder) click to toggle source
# File lib/yardi/request_section/lead_management.rb, line 64
def phone_xml(number, type, xml_builder)
  if number
    xml_builder.Phone('PhoneType' => type) do |phone_xml|
      phone_xml.PhoneNumber number
    end
  end
end
preferences_xml(xml_builder) click to toggle source
# File lib/yardi/request_section/lead_management.rb, line 88
def preferences_xml(xml_builder)
  xml_builder.CustomerPreferences do |preferences_xml|
    preferences_xml.TargetMoveInDate user.move_in_date.to_s
    preferences_xml.DesiredFloorplan user.preferred_floorplan_id
    # Rent and bedrooms are empty nodes with attributes for values.
    # Yardi doesn't like having an empty string for either of these
    # attributes, so we leave the node out if we don't have any data.
    unless user.price.nil?
      preferences_xml.DesiredRent('Exact' => user.price) {}
    end

    unless user.beds.nil?
      preferences_xml.DesiredNumBedrooms('Exact' => user.beds) {}
    end

    preferences_xml.Comment user.preference_notes
  end
end
prospect_xml(xml_builder) click to toggle source
# File lib/yardi/request_section/lead_management.rb, line 27
def prospect_xml(xml_builder)
  xml_builder.Prospect do |prospect_xml|
    customers_xml(prospect_xml)
    preferences_xml(prospect_xml)

    prospect_xml.Events do |events_xml|
      first_contact_event_xml(events_xml)
      tour_xml(events_xml) unless property.tour_time.nil?
    end
  end
end
tour_xml(xml_builder) click to toggle source
# File lib/yardi/request_section/lead_management.rb, line 130
def tour_xml(xml_builder)
  event_attrs = {
    'EventDate' => property.tour_time.iso8601,
    'EventType' => 'Appointment'
  }
  tour_id_attrs = {
    'IDValue' => property.tour_remote_id || 0,
    'IDType' => user.preferred_unit_id
  }
  xml_builder.Event(event_attrs) do |event_xml|
    event_xml.EventID(tour_id_attrs)
    agent_xml(event_xml)
    event_xml.EventReasons reason
    event_xml.Comments property.tour_notes
  end
end
yardi_id_attributes() click to toggle source
# File lib/yardi/request_section/lead_management.rb, line 80
def yardi_id_attributes
  {
    'IDType' => 'PropertyID',
    'IDValue' => property.remote_id,
    'OrganizationName' => 'Yardi'
  }
end