Sha256: 98922d3009e59991648dc6d1f4dea0fd5d7fb6835031caa3e3b4bc9b70f9e3a9
Contents?: true
Size: 1.84 KB
Versions: 1
Compression:
Stored size: 1.84 KB
Contents
module FatFreeCRM module Cloudfuji module EventObservers class CustomerObserver < ::Cloudfuji::EventObserver # "customer_created" # :account_balance => 0 # :object => "customer" # :email => "s+cfdemo@cloudfuji.com" # :created => 1332269951 # :id => "cus_cpkg4h0KfLD3lp" # :livemode => true # :human => "Customer CREATED (cus_cpkg4h0KfLD3lp), s+cfdemo@cloudfuji.com"} def customer_created note_customer_activity("#{data['email']} created as a customer with external id #{data['id']}") if data['livemode'] end def customer_signed_up note_customer_activity("#{data['first_name']} #{data['last_name']} (#{data['email']}) signed up as a customer") end private def note_customer_activity(message) subject = find_or_create_activity_subject! puts "Found subject: #{subject.inspect}" subject.versions.create! :event => message end def data params['data'] end def recipient data['recipient'] end def find_or_create_activity_subject! lookups = [Account, Lead, Contact] lookups.each do |model| puts "#{model}.find_by_email( #{data['email']} )" result = model.find_by_email(data['email']) return result if result end lead = Lead.find_by_email(data['email']) lead ||= Lead.new lead.email = data['email'] lead.first_name ||= data['first_name'] || recipient.split("@").first if lead.first_name.blank? lead.last_name ||= data['last_name'] || recipient.split("@").last if lead.last_name.blank? lead.save! lead end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ffcrm_cloudfuji-0.1.6 | lib/fat_free_crm/cloudfuji/event_observers/customer_observer.rb |