email_campaign 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -20,22 +20,25 @@ class EmailCampaign::Campaign < ActiveRecord::Base
|
|
20
20
|
unsubscribed = 0
|
21
21
|
|
22
22
|
new_recipients.each do |rcpt|
|
23
|
-
subscriber_id = rcpt.subscriber_id
|
23
|
+
subscriber_id = rcpt.respond_to?(:subscriber_id) ? rcpt.subscriber_id : rcpt.id
|
24
24
|
|
25
25
|
if subscriber_id && recipients.where(:subscriber_id => subscriber_id).count > 0
|
26
26
|
skipped += 1
|
27
27
|
next
|
28
28
|
end
|
29
29
|
|
30
|
-
r = recipients.create(:name => rcpt.name.strip, :email_address => rcpt.email_address.strip,
|
31
|
-
:subscriber_class_name => rcpt.class.name, :subscriber_id => subscriber_id)
|
32
|
-
|
33
30
|
processed += 1
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
31
|
+
r = recipients.build(:name => rcpt.name.strip, :email_address => rcpt.email_address.strip,
|
32
|
+
:subscriber_class_name => rcpt.class.name, :subscriber_id => subscriber_id)
|
33
|
+
if r.save
|
34
|
+
case
|
35
|
+
when r.unsubscribed then unsubscribed += 1
|
36
|
+
when r.duplicate then duplicate += 1
|
37
|
+
when r.invalid_email then invalid += 1
|
38
|
+
else valid += 1
|
39
|
+
end
|
40
|
+
else
|
41
|
+
invalid += 1
|
39
42
|
end
|
40
43
|
|
41
44
|
r.queue
|
@@ -69,7 +72,11 @@ class EmailCampaign::Campaign < ActiveRecord::Base
|
|
69
72
|
end
|
70
73
|
|
71
74
|
def process_delivery
|
72
|
-
recipients.where(:ready => true).each
|
75
|
+
recipients.where(:ready => true).each { |r| r.delay.deliver }
|
76
|
+
end
|
77
|
+
|
78
|
+
def queued_recipients
|
79
|
+
recipients.where(:ready => true)
|
73
80
|
end
|
74
81
|
|
75
82
|
end
|
@@ -155,6 +155,7 @@ class EmailCampaign::Recipient < ActiveRecord::Base
|
|
155
155
|
self.clicked = true
|
156
156
|
self.clicked_at ||= Time.now.utc
|
157
157
|
self.clicks += 1
|
158
|
+
save
|
158
159
|
end
|
159
160
|
end
|
160
161
|
|
@@ -180,7 +181,7 @@ class EmailCampaign::Recipient < ActiveRecord::Base
|
|
180
181
|
def resubscribe(params = nil)
|
181
182
|
self.class.transaction do
|
182
183
|
self.class.where(:email_address => email_address, :unsubscribed => true).each do |r|
|
183
|
-
r.update_attributes(:unsubscribed
|
184
|
+
r.update_attributes(:unsubscribed => false)
|
184
185
|
end
|
185
186
|
end
|
186
187
|
end
|