ffcrm_cloudfuji 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ %tr
2
+ %td
3
+ .label Ido ID:
4
+ = f.text_field :ido_id
@@ -2,11 +2,12 @@ module FatFreeCRM
2
2
  module Cloudfuji
3
3
  module EventObservers
4
4
  class AppObserver < ::Cloudfuji::EventObserver
5
+ include FatFreeCRM::Cloudfuji::EventObservers::Base
6
+
5
7
  def app_claimed
6
8
  # Be verbose in development environment
7
9
  debug = Rails.env == 'development'
8
10
 
9
- data = params['data']
10
11
  ido_id = data.try(:[], 'ido_id')
11
12
 
12
13
  if user = User.find(:first, :conditions => ["email = ? OR ido_id = ?", data['email'], data['ido_id']])
@@ -0,0 +1,65 @@
1
+ module FatFreeCRM
2
+ module Cloudfuji
3
+ module EventObservers
4
+ module Base
5
+ # Shared methods for observers
6
+
7
+ def find_lead_by_data
8
+ # Look up Lead by ido_id or email address.
9
+ lead = Lead.find_by_ido_id(data['customer_ido_id']) if data['customer_ido_id'].present?
10
+ lead ||= Lead.find_by_email(email)
11
+ update_ido_id_if_blank(lead)
12
+ lead
13
+ end
14
+
15
+
16
+ def find_or_create_activity_subject!
17
+ models = [Lead, Contact, Account]
18
+ models.each do |model|
19
+ has_ido_id = model.new.respond_to?(:ido_id)
20
+
21
+ if data['customer_ido_id'].present? && has_ido_id
22
+ asset = model.find_by_ido_id(data['customer_ido_id'])
23
+ return asset if asset
24
+ end
25
+
26
+ if asset = model.find_by_email(email)
27
+ update_ido_id_if_blank(asset) if has_ido_id
28
+ return asset if asset
29
+ end
30
+ end
31
+
32
+ puts "No pre-existing records found, creating a lead"
33
+ lead = Lead.create!(
34
+ :email => email,
35
+ :ido_id => data['customer_ido_id'],
36
+ :first_name => email.split("@").first,
37
+ :last_name => email.split("@").last,
38
+ :user => User.first)
39
+ lead
40
+ end
41
+
42
+
43
+ private
44
+
45
+ def update_ido_id_if_blank(asset)
46
+ # If lead was found by email and has blank ido_id,
47
+ # but customer_ido_id is present, then update ido_id
48
+ if asset && asset.respond_to?(:ido_id) &&
49
+ asset.ido_id.blank? && data['customer_ido_id'].present?
50
+ asset.update_attribute :ido_id, data['customer_ido_id']
51
+ end
52
+ end
53
+
54
+ def data
55
+ params['data']
56
+ end
57
+
58
+ def email
59
+ data['email'] || data['recipient']
60
+ end
61
+
62
+ end
63
+ end
64
+ end
65
+ end
@@ -2,6 +2,8 @@ module FatFreeCRM
2
2
  module Cloudfuji
3
3
  module EventObservers
4
4
  class CustomerObserver < ::Cloudfuji::EventObserver
5
+ include FatFreeCRM::Cloudfuji::EventObservers::Base
6
+
5
7
  # "customer_created"
6
8
  # :account_balance => 0
7
9
  # :object => "customer"
@@ -30,34 +32,6 @@ module FatFreeCRM
30
32
  subject.versions.create! :event => message
31
33
  end
32
34
 
33
- def data
34
- params['data']
35
- end
36
-
37
- def find_or_create_activity_subject!
38
- lookups = [Account, Lead, Contact]
39
- lookups.each do |model|
40
- puts "#{model}.find_by_email( #{data['email']} )" if @debug
41
- result = model.find_by_email(data['email'])
42
- return result if result
43
- end
44
-
45
- lead = if data['customer_ido_id'].present?
46
- Lead.find_by_ido_id(data['customer_ido_id'])
47
- else
48
- Lead.find_by_email(data['email'])
49
- end
50
- lead ||= Lead.new
51
-
52
- lead.email = data['email']
53
- lead.ido_id = data['customer_ido_id']
54
- lead.first_name = data['first_name'] || data['email'].split("@").first if lead.first_name.blank?
55
- lead.last_name = data['last_name'] || data['email'].split("@").last if lead.last_name.blank?
56
- lead.user ||= User.first
57
- lead.save!
58
-
59
- lead
60
- end
61
35
  end
62
36
  end
63
37
  end
@@ -2,7 +2,7 @@ module FatFreeCRM
2
2
  module Cloudfuji
3
3
  module EventObservers
4
4
  class EmailObserver < ::Cloudfuji::EventObserver
5
- # NOTE: It'd be nice to have a before_filter.
5
+ include FatFreeCRM::Cloudfuji::EventObservers::Base
6
6
 
7
7
  # "email_delivered"
8
8
  # :message_headers => "[[\"Received\", \"by luna.mailgun.net with SMTP mgrt 7313261; Tue, 20 Mar 2012 19:00:58 +0000\"], [\"Received\", \"from localhost.localdomain (ec2-23-20-14-40.compute-1.amazonaws.com [23.20.14.40]) by mxa.mailgun.org with ESMTP id 4f68d3e9.4ddcdf0-luna; Tue, 20 Mar 2012 19:00:57 -0000 (UTC)\"], [\"Date\", \"Tue, 20 Mar 2012 19:00:57 +0000\"], [\"From\", \"Sean Grove <sean@cloudfuji.com>\"], [\"Reply-To\", \"Cloudfuji Team <support@cloudfuji.com>\"], [\"Message-Id\", \"<4f68d3e9ad834_3c29377ea432615@ip-10-190-150-17.mail>\"], [\"X-Mailgun-Campaign-Id\", \"cloudfuji_buddies\"], [\"Repy-To\", \"support@cloudfuji.com\"], [\"To\", \"s+cfdemo@cloudfuji.com\"], [\"Subject\", \"Cloudfuji Beta: Thank you for your early support. Here's a gift for you.\"], [\"List-Unsubscribe\", \"<mailto:u+na6wcn3gmqzdszbsmrrdam3ghfstkzrxgbstgn3fgvtdgzjumvrgmyzgmm6tqnlkgetheplteuzeey3gmrsw23zfgqyge5ltnbus4zdpez2d2jjsietgipjrmi4a@email.cloudfuji.com>\"], [\"X-Mailgun-Sid\", \"WyI2NWQ4MSIsICJzK2NmZGVtb0BidXNoaS5kbyIsICIxYjgiXQ==\"], [\"Sender\", \"sean=cloudfuji.com@cloudfuji.com\"]]"
@@ -66,42 +66,6 @@ module FatFreeCRM
66
66
  subject.versions.create! :event => message
67
67
  end
68
68
 
69
- def data
70
- params['data']
71
- end
72
-
73
- def find_or_create_activity_subject!
74
- lookups = [Account, Lead, Contact]
75
- lookups.each do |model|
76
- puts "#{model}.find_by_email( #{recipient} )"
77
- result = model.find_by_email(recipient)
78
- return result if result
79
- end
80
-
81
- puts "No pre-existing records found, creating a lead"
82
- lead = if data['customer_ido_id'].present?
83
- Lead.find_by_ido_id(data['customer_ido_id'])
84
- else
85
- Lead.find_by_email(recipient)
86
- end
87
- lead ||= Lead.new
88
-
89
- lead.email = recipient
90
- lead.ido_id = data['customer_ido_id']
91
- lead.first_name = recipient.split("@").first if lead.first_name.blank?
92
- lead.last_name = recipient.split("@").last if lead.last_name.blank?
93
- lead.user ||= User.first
94
-
95
- puts "About to save:"
96
- puts lead.inspect
97
-
98
- lead.save!
99
-
100
- puts lead.inspect
101
-
102
- lead
103
- end
104
-
105
69
  # Temp workarounds until umi delivers events properly
106
70
  # Good example of the necessity of deep-schema enforcement for events
107
71
  def headers
@@ -112,10 +76,6 @@ module FatFreeCRM
112
76
  end
113
77
  end
114
78
 
115
- def recipient
116
- data['recipient']
117
- end
118
-
119
79
  def custom_variables
120
80
  JSON(data['custom_variables'])
121
81
  end
@@ -2,6 +2,7 @@ module FatFreeCRM
2
2
  module Cloudfuji
3
3
  module EventObservers
4
4
  class ErrorObserver < ::Cloudfuji::EventObserver
5
+ include FatFreeCRM::Cloudfuji::EventObservers::Base
5
6
  include ActionView::Helpers::TextHelper
6
7
 
7
8
  def error_caught
@@ -11,8 +12,11 @@ module FatFreeCRM
11
12
  lead = Lead.find_by_ido_id(user_attributes['ido_id']) if user_attributes['ido_id'].present?
12
13
  lead ||= Lead.find_by_email(user_attributes['email'])
13
14
  if lead
15
+ # Set ido_id if blank
16
+ user_attributes
17
+
14
18
  occurence = ActiveSupport::Inflector.ordinalize(data['occurrences'])
15
- message = "Error occurred in <strong>#{data['app_name']}</strong> [#{data['environment_name']}] (#{occurence} time): "
19
+ message = "Error experienced in <strong>#{data['app_name']}</strong> [#{data['environment_name']}] (#{occurence} time): "
16
20
  message << "<em>" << truncate(data['message'], :length => 75) << "</em>"
17
21
  message << "<br />View the error at: #{data['url']}" if data['url']
18
22
  lead.versions.create! :event => message
@@ -20,12 +24,6 @@ module FatFreeCRM
20
24
  end
21
25
  end
22
26
 
23
- private
24
-
25
- def data
26
- params['data']
27
- end
28
-
29
27
  end
30
28
  end
31
29
  end
@@ -2,19 +2,12 @@ module FatFreeCRM
2
2
  module Cloudfuji
3
3
  module EventObservers
4
4
  class EventRulesObserver < ::Cloudfuji::EventObserver
5
+ include FatFreeCRM::Cloudfuji::EventObservers::Base
6
+
5
7
  # Fire for all events
6
8
  def catch_all
7
- data = params['data']
8
- email = data['email'] || data['recipient']
9
- # Look up Lead by ido_id, fall back to email address
10
- lead = if data['customer_ido_id'].present?
11
- Lead.find_by_ido_id(data['customer_ido_id'])
12
- else
13
- Lead.find_by_email(email)
14
- end
15
- if lead
9
+ if lead = find_lead_by_data
16
10
  event_name = "#{params['category']}_#{params['event']}"
17
-
18
11
  EventRule.find_all_by_event_category_and_cloudfuji_event('cloudfuji_event_received', event_name).each do |rule|
19
12
  rule.process(lead, params['data'])
20
13
  end
@@ -2,7 +2,8 @@ module FatFreeCRM
2
2
  module Cloudfuji
3
3
  module EventObservers
4
4
  class PaymentObserver < ::Cloudfuji::EventObserver
5
- # NOTE: It'd be nice to have a before_filter.
5
+ include FatFreeCRM::Cloudfuji::EventObservers::Base
6
+
6
7
  end
7
8
  end
8
9
  end
@@ -2,6 +2,8 @@ module FatFreeCRM
2
2
  module Cloudfuji
3
3
  module EventObservers
4
4
  class UserObserver < ::Cloudfuji::EventObserver
5
+ include FatFreeCRM::Cloudfuji::EventObservers::Base
6
+
5
7
  def user_added
6
8
  data = params['data']
7
9
  ido_id = data['ido_id'].to_s
@@ -4,7 +4,11 @@ module FatFreeCRM
4
4
 
5
5
  # Add lead scoring to summary on lead show page
6
6
  def show_lead_sidebar_bottom(view, context)
7
- view.render(:partial => 'leads/sidebar_show_lead_scoring', :locals => {:lead => context[:lead]})
7
+ view.render(:partial => 'leads/sidebar_show_lead_scoring', :locals => context)
8
+ end
9
+
10
+ def lead_top_section_bottom(view, context)
11
+ view.render(:partial => 'leads/top_section_ido_id', :locals => context)
8
12
  end
9
13
 
10
14
  end
@@ -42,6 +42,7 @@ module FatFreeCRM
42
42
  end
43
43
 
44
44
  def load_observers!
45
+ require File.expand_path("../cloudfuji/event_observers/base", __FILE__)
45
46
  Dir[File.expand_path("../cloudfuji/event_observers/*.rb", __FILE__)].each { |file| require file }
46
47
  end
47
48
 
@@ -1,5 +1,5 @@
1
1
  module FatFreeCRM
2
2
  module Cloudfuji
3
- VERSION = '0.2.5'
3
+ VERSION = '0.2.6'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffcrm_cloudfuji
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-05-28 00:00:00.000000000 Z
13
+ date: 2012-05-29 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec-rails
@@ -118,6 +118,7 @@ files:
118
118
  - app/views/admin/event_rules/index.html.haml
119
119
  - app/views/leads/_lead.html.haml
120
120
  - app/views/leads/_sidebar_show_lead_scoring.html.haml
121
+ - app/views/leads/_top_section_ido_id.html.haml
121
122
  - config.ru
122
123
  - config/database.yml
123
124
  - config/initializers/cloudfuji.rb
@@ -132,6 +133,7 @@ files:
132
133
  - install.rb
133
134
  - lib/fat_free_crm/cloudfuji.rb
134
135
  - lib/fat_free_crm/cloudfuji/event_observers/app_observer.rb
136
+ - lib/fat_free_crm/cloudfuji/event_observers/base.rb
135
137
  - lib/fat_free_crm/cloudfuji/event_observers/customer_observer.rb
136
138
  - lib/fat_free_crm/cloudfuji/event_observers/email_observer.rb
137
139
  - lib/fat_free_crm/cloudfuji/event_observers/error_observer.rb
@@ -166,7 +168,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
166
168
  version: '0'
167
169
  segments:
168
170
  - 0
169
- hash: 1362757599666679150
171
+ hash: 529527583371072573
170
172
  required_rubygems_version: !ruby/object:Gem::Requirement
171
173
  none: false
172
174
  requirements:
@@ -175,7 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
175
177
  version: '0'
176
178
  segments:
177
179
  - 0
178
- hash: 1362757599666679150
180
+ hash: 529527583371072573
179
181
  requirements: []
180
182
  rubyforge_project:
181
183
  rubygems_version: 1.8.24