Class: CrmLeadRepository

Inherits:
Object
  • Object
show all
Extended by:
LeadMapping
Defined in:
lib/crm_integration/crm_lead_repository.rb

Class Method Summary collapse

Methods included from LeadMapping

map_from

Class Method Details

.delete(rd_lead) ⇒ Object



14
15
16
17
# File 'lib/crm_integration/crm_lead_repository.rb', line 14

def self.delete(rd_lead)
  crm_lead = load_crm_lead_by_email(rd_lead.email_was)
  RubyZoho::Crm::Lead.delete(crm_lead.leadid)
end

.load_crm_lead_by_email(email) ⇒ Object



19
20
21
22
# File 'lib/crm_integration/crm_lead_repository.rb', line 19

def self.load_crm_lead_by_email(email)
  leads = RubyZoho::Crm::Lead.find_by_email(email)
  leads && !leads.empty? ? leads.first : nil
end

.post(rd_lead) ⇒ Object



4
5
6
7
# File 'lib/crm_integration/crm_lead_repository.rb', line 4

def self.post(rd_lead)
  crm_lead = RubyZoho::Crm::Lead.new(map_from(rd_lead))
  crm_lead.save
end

.put(rd_lead) ⇒ Object



9
10
11
12
# File 'lib/crm_integration/crm_lead_repository.rb', line 9

def self.put(rd_lead)
  crm_lead = load_crm_lead_by_email(rd_lead.email_was)
  RubyZoho::Crm::Lead.update(map_from(rd_lead).merge(:id => crm_lead.leadid))
end