Module: FatFreeCRM::Cloudfuji::EventObservers::Base
- Included in:
- AppObserver, CustomerObserver, EmailObserver, ErrorObserver, EventRulesObserver, PaymentObserver, UserObserver
- Defined in:
- lib/fat_free_crm/cloudfuji/event_observers/base.rb
Instance Method Summary collapse
-
#find_lead_by_data ⇒ Object
Shared methods for observers.
- #find_or_create_activity_subject! ⇒ Object
Instance Method Details
#find_lead_by_data ⇒ Object
Shared methods for observers
7 8 9 10 11 12 13 |
# File 'lib/fat_free_crm/cloudfuji/event_observers/base.rb', line 7 def find_lead_by_data # Look up Lead by ido_id or email address. lead = Lead.find_by_ido_id(data['customer_ido_id']) if data['customer_ido_id'].present? lead ||= Lead.find_by_email(email) update_ido_id_if_blank(lead) lead end |
#find_or_create_activity_subject! ⇒ Object
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 |
# File 'lib/fat_free_crm/cloudfuji/event_observers/base.rb', line 16 def find_or_create_activity_subject! models = [Lead, Contact, Account] models.each do |model| has_ido_id = model.new.respond_to?(:ido_id) if data['customer_ido_id'].present? && has_ido_id asset = model.find_by_ido_id(data['customer_ido_id']) return asset if asset end if asset = model.find_by_email(email) update_ido_id_if_blank(asset) if has_ido_id return asset if asset end end puts "No pre-existing records found, creating a lead" lead = Lead.new( :email => email, :ido_id => data['customer_ido_id'], :first_name => email.split("@").first, :last_name => email.split("@").last, :user => User.first) lead.first_name = data['first_name'] if data['first_name'].present? lead.last_name = data['last_name'] if data['last_name'].present? lead.save! lead end |