Class: SalesforceIntegration::SalesforceIntegrationLead

Inherits:
Object
  • Object
show all
Defined in:
lib/salesforceintegration.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ SalesforceIntegrationLead

Returns a new instance of SalesforceIntegrationLead.



9
10
11
12
13
14
15
16
17
# File 'lib/salesforceintegration.rb', line 9

def initialize(options)
  raise "It's necessary to inform client_id, client_secret, url, username and password!" unless options.has_key?(:client_id) and options.has_key?(:client_secret) and options.has_key?(:url) and options.has_key?(:username) and options.has_key?(:password)

  client = Databasedotcom::Client.new(:client_id => options[:client_id], :client_secret => options[:client_secret], :host => options[:url])
  client.authenticate(:username => options[:username], :password => options[:password])

  client.materialize("Lead")
  client.materialize("User")
end

Instance Method Details

#create_lead_on_salesforce(fields) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/salesforceintegration.rb', line 19

def create_lead_on_salesforce(fields)
  raise "The fields last_name and company are required"    unless fields.has_key?(:last_name) and fields.has_key?(:company)
  raise "The fields last_name and company cannot be blank"     if fields[:last_name].blank?    or fields[:company].blank? 
  raise "Email must be valid" unless fields[:email].blank? or 
                                      fields[:email] =~ /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/

  lead = Lead.new
  user = User.first

  lead['OwnerId'] = user.Id
  lead['FirstName'] = fields[:first_name]
  lead['LastName'] = fields[:last_name]
  lead['Email'] = fields[:email]
  lead['Company'] = fields[:company]
  lead['Title'] = fields[:job_title]
  lead['Phone'] = fields[:phone]
  lead['Website'] = fields[:website]
  lead['IsConverted'] = false
  lead['IsUnreadByOwner'] = true
  lead.save
  lead.Id
end