caffeinate 2.0.5 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -1
- data/app/controllers/caffeinate/campaign_subscriptions_controller.rb +2 -2
- data/app/models/caffeinate/campaign_subscription.rb +17 -0
- data/app/models/caffeinate/mailing.rb +8 -0
- data/app/services/campaign_subscriptions/refuel_service.rb +33 -0
- data/lib/caffeinate/dripper/base.rb +2 -0
- data/lib/caffeinate/dripper/delivery.rb +1 -0
- data/lib/caffeinate/dripper/rescuable.rb +25 -0
- data/lib/caffeinate/version.rb +1 -1
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ee66cd0cefbff81f194970176755cde5fe49ccc8acd9307f3081bc13f71bd2f
|
4
|
+
data.tar.gz: 25380078f2edd4c8ccb7fdd4adc5903a783ce1f123ea59981def0bf5ee08698c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5fe9f92105e1acf59ce7f931a75a3e5d7e7a7ed5a58ee19d1b9cd1ce661c3f86011e3e910576fdad058009a8a2b2e54ab1e99eb073f11ec5a4d6bd27a9c30f47
|
7
|
+
data.tar.gz: 397e39515c8d7bf8e7bfb1d794b0beb434bb916af1f4ac310a027c9a9f21fb8ef0a74abf99acc53f6f59e8efd6b32ac50239e75cb329241d5d3ca8cc3a876405
|
data/README.md
CHANGED
@@ -20,7 +20,7 @@ Caffeinate is a drip email engine for managing, creating, and sending scheduled
|
|
20
20
|
|
21
21
|
Caffeinate provides a simple DSL to create scheduled email sequences which can be used by ActionMailer without any additional configuration.
|
22
22
|
|
23
|
-
There's a cool demo
|
23
|
+
There's a cool demo app you can spin up [here](https://github.com/joshmn/caffeinate-marketing).
|
24
24
|
|
25
25
|
## Is this thing dead?
|
26
26
|
|
@@ -28,6 +28,10 @@ No! Not at all!
|
|
28
28
|
|
29
29
|
There's not a lot of activity here because it's stable and working! I am more than happy to entertain new features.
|
30
30
|
|
31
|
+
## Oh my gosh, a web UI!
|
32
|
+
|
33
|
+
See https://github.com/joshmn/caffeinate-webui for an accompanying lightweight UI for simple administrative tasks and overview.
|
34
|
+
|
31
35
|
## Do you suffer from ActionMailer tragedies?
|
32
36
|
|
33
37
|
If you have _anything_ like this is your codebase, **you need Caffeinate**:
|
@@ -19,11 +19,11 @@ module Caffeinate
|
|
19
19
|
private
|
20
20
|
|
21
21
|
def caffeinate_subscribe_url(**options)
|
22
|
-
Caffeinate::UrlHelpers.caffeinate_subscribe_url(@campaign_subscription, options)
|
22
|
+
Caffeinate::UrlHelpers.caffeinate_subscribe_url(@campaign_subscription, **options)
|
23
23
|
end
|
24
24
|
|
25
25
|
def caffeinate_unsubscribe_url(**options)
|
26
|
-
Caffeinate::UrlHelpers.caffeinate_unsubscribe_url(@campaign_subscription, options)
|
26
|
+
Caffeinate::UrlHelpers.caffeinate_unsubscribe_url(@campaign_subscription, **options)
|
27
27
|
end
|
28
28
|
|
29
29
|
def find_campaign_subscription!
|
@@ -16,6 +16,7 @@
|
|
16
16
|
# created_at :datetime not null
|
17
17
|
# updated_at :datetime not null
|
18
18
|
#
|
19
|
+
|
19
20
|
module Caffeinate
|
20
21
|
# If a record tries to be `unsubscribed!` or `ended!` or `resubscribe!` and it's in a state that is not
|
21
22
|
# correct, raise this
|
@@ -59,6 +60,22 @@ module Caffeinate
|
|
59
60
|
|
60
61
|
after_commit :on_complete, if: :completed?
|
61
62
|
|
63
|
+
# Add (new) drips to a `CampaignSubscriber`.
|
64
|
+
#
|
65
|
+
# Useful if you added new drips to a `Campaign` and have existing `CampaignSubscription`
|
66
|
+
# which you want to add them to.
|
67
|
+
#
|
68
|
+
# Pass `:created_at` if you want to offset `Mailing#send_at` time from the time the `CampaignSubscription`
|
69
|
+
# was originally created. That is to say that if you add a new drip for 5 days from now, the mailing will be sent
|
70
|
+
# 5 days from when the `CampaignSubscription` was created.
|
71
|
+
#
|
72
|
+
# Pass `:current` to offset from the current time (doesn't offset anything, actually)
|
73
|
+
def refuel!(offset: :created_at)
|
74
|
+
::CampaignSubscriptions::RefuelService.new(self, offset: offset).call
|
75
|
+
|
76
|
+
true
|
77
|
+
end
|
78
|
+
|
62
79
|
# Actually deliver and process the mail
|
63
80
|
def deliver!(mailing)
|
64
81
|
caffeinate_campaign.to_dripper.deliver!(mailing)
|
@@ -32,6 +32,14 @@ module Caffeinate
|
|
32
32
|
|
33
33
|
after_touch :end_if_no_mailings!
|
34
34
|
|
35
|
+
def self.find_or_initialize_from_drip(campaign_subscription, drip)
|
36
|
+
find_or_initialize_by(
|
37
|
+
caffeinate_campaign_subscription: campaign_subscription,
|
38
|
+
mailer_class: drip.options[:mailer_class],
|
39
|
+
mailer_action: drip.action
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
35
43
|
def initialize_dup(args)
|
36
44
|
super
|
37
45
|
self.send_at = nil
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module CampaignSubscriptions
|
2
|
+
class RefuelService
|
3
|
+
|
4
|
+
def initialize(campaign_subscription, offset: :created_at)
|
5
|
+
raise ArgumentError, "must be either :current or :created_at" unless [:created_at, :current].include?(offset.to_sym)
|
6
|
+
|
7
|
+
@campaign_subscription = campaign_subscription
|
8
|
+
@campaign = @campaign_subscription.caffeinate_campaign
|
9
|
+
@offset = offset.to_sym
|
10
|
+
end
|
11
|
+
|
12
|
+
def call
|
13
|
+
mailings = []
|
14
|
+
|
15
|
+
@campaign.to_dripper.drips.each do |drip|
|
16
|
+
mailing = Caffeinate::Mailing.find_or_initialize_from_drip(@campaign_subscription, drip)
|
17
|
+
if mailing.new_record?
|
18
|
+
mailing.send_at = drip.send_at(@campaign_subscription)
|
19
|
+
if @offset == :created_at
|
20
|
+
mailing.send_at + (Caffeinate.config.now.call - @campaign_subscription.created_at)
|
21
|
+
elsif @offset == :current
|
22
|
+
# do nothing on purpose!
|
23
|
+
end
|
24
|
+
|
25
|
+
mailing.save!
|
26
|
+
mailings << mailing
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
mailings
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -9,6 +9,7 @@ require 'caffeinate/dripper/drip'
|
|
9
9
|
require 'caffeinate/dripper/inferences'
|
10
10
|
require 'caffeinate/dripper/perform'
|
11
11
|
require 'caffeinate/dripper/periodical'
|
12
|
+
require 'caffeinate/dripper/rescuable'
|
12
13
|
require 'caffeinate/dripper/subscriber'
|
13
14
|
|
14
15
|
module Caffeinate
|
@@ -24,6 +25,7 @@ module Caffeinate
|
|
24
25
|
include Inferences
|
25
26
|
include Perform
|
26
27
|
include Periodical
|
28
|
+
include Rescuable
|
27
29
|
include Subscriber
|
28
30
|
end
|
29
31
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Caffeinate
|
4
|
+
module Dripper
|
5
|
+
module Rescuable
|
6
|
+
def self.included(klass)
|
7
|
+
klass.include ::ActiveSupport::Rescuable
|
8
|
+
klass.extend ClassMethods
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
def deliver!(mailing)
|
13
|
+
begin
|
14
|
+
super
|
15
|
+
rescue Exception => exception
|
16
|
+
if self.rescue_with_handler(exception, object: mailing)
|
17
|
+
return
|
18
|
+
end
|
19
|
+
raise
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/caffeinate/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: caffeinate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Brody
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -153,6 +153,7 @@ files:
|
|
153
153
|
- app/models/caffeinate/campaign.rb
|
154
154
|
- app/models/caffeinate/campaign_subscription.rb
|
155
155
|
- app/models/caffeinate/mailing.rb
|
156
|
+
- app/services/campaign_subscriptions/refuel_service.rb
|
156
157
|
- app/views/caffeinate/campaign_subscriptions/subscribe.html.erb
|
157
158
|
- app/views/caffeinate/campaign_subscriptions/unsubscribe.html.erb
|
158
159
|
- app/views/layouts/_caffeinate.html.erb
|
@@ -179,6 +180,7 @@ files:
|
|
179
180
|
- lib/caffeinate/dripper/inferences.rb
|
180
181
|
- lib/caffeinate/dripper/perform.rb
|
181
182
|
- lib/caffeinate/dripper/periodical.rb
|
183
|
+
- lib/caffeinate/dripper/rescuable.rb
|
182
184
|
- lib/caffeinate/dripper/subscriber.rb
|
183
185
|
- lib/caffeinate/dripper_collection.rb
|
184
186
|
- lib/caffeinate/engine.rb
|
@@ -200,7 +202,7 @@ homepage: https://github.com/joshmn/caffeinate
|
|
200
202
|
licenses:
|
201
203
|
- MIT
|
202
204
|
metadata: {}
|
203
|
-
post_install_message:
|
205
|
+
post_install_message:
|
204
206
|
rdoc_options: []
|
205
207
|
require_paths:
|
206
208
|
- lib
|
@@ -216,7 +218,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
216
218
|
version: '0'
|
217
219
|
requirements: []
|
218
220
|
rubygems_version: 3.1.4
|
219
|
-
signing_key:
|
221
|
+
signing_key:
|
220
222
|
specification_version: 4
|
221
223
|
summary: Create, manage, and send scheduled email sequences and drip campaigns from
|
222
224
|
your Rails app.
|