mailkick 0.1.4 → 1.0.1
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.
- checksums.yaml +5 -5
- data/CHANGELOG.md +72 -11
- data/LICENSE.txt +1 -1
- data/README.md +152 -97
- data/app/controllers/mailkick/subscriptions_controller.rb +41 -20
- data/app/models/mailkick/opt_out.rb +1 -1
- data/app/models/mailkick/subscription.rb +9 -0
- data/app/views/mailkick/subscriptions/show.html.erb +1 -1
- data/config/routes.rb +3 -1
- data/lib/generators/mailkick/install_generator.rb +6 -17
- data/lib/generators/mailkick/templates/install.rb.tt +11 -0
- data/lib/mailkick/engine.rb +13 -5
- data/lib/mailkick/legacy.rb +70 -0
- data/lib/mailkick/model.rb +11 -21
- data/lib/mailkick/service/aws_ses.rb +47 -0
- data/lib/mailkick/service/mailchimp.rb +5 -5
- data/lib/mailkick/service/mailgun.rb +1 -1
- data/lib/mailkick/service/mandrill.rb +6 -2
- data/lib/mailkick/service/postmark.rb +41 -0
- data/lib/mailkick/service/sendgrid.rb +4 -1
- data/lib/mailkick/service/sendgrid_v2.rb +52 -0
- data/lib/mailkick/service.rb +1 -15
- data/lib/mailkick/url_helper.rb +8 -0
- data/lib/mailkick/version.rb +1 -1
- data/lib/mailkick.rb +32 -65
- metadata +21 -39
- data/.gitignore +0 -22
- data/Gemfile +0 -4
- data/Rakefile +0 -1
- data/app/helpers/mailkick/url_helper.rb +0 -13
- data/lib/generators/mailkick/templates/install.rb +0 -16
- data/lib/mailkick/mailer.rb +0 -11
- data/lib/mailkick/processor.rb +0 -27
- data/mailkick.gemspec +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e84a6786c23946b6e27a67a14d75c01da5cde231928d19c65edd2b591de9a153
|
4
|
+
data.tar.gz: 1a944d065c7bf4c164db038aabe0073b3759e96a232ec22b29e86cf746ffc02f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ed9f0315dc5c60ed5b2cc524fd13763566b6126bafceb665dbddcdc2a182f4408a370e267fdcc8ab97cbe616684c7ff5ab91b0fe717d39a65deac854cd3b958
|
7
|
+
data.tar.gz: 82c2c1d7a1d0077eb60df59a9d672039b17750462a435afdef19125e26f3c122600a2a8f394c06a3119a64c773d4a6ef7a1f61dc5081dca587735eda80c4a9c3
|
data/CHANGELOG.md
CHANGED
@@ -1,46 +1,107 @@
|
|
1
|
-
## 0.1
|
1
|
+
## 1.0.1 (2021-06-20)
|
2
|
+
|
3
|
+
- Fixed error message when process out-opts not configured
|
4
|
+
|
5
|
+
## 1.0.0 (2021-06-03)
|
6
|
+
|
7
|
+
- Switched from opt-outs to subscriptions
|
8
|
+
- Dropped support for Ruby < 2.6 and Rails < 5.2
|
9
|
+
|
10
|
+
## 0.4.3 (2020-11-01)
|
11
|
+
|
12
|
+
- Added support for AWS SES
|
13
|
+
|
14
|
+
## 0.4.2 (2020-04-06)
|
15
|
+
|
16
|
+
- Added support for official SendGrid gem
|
17
|
+
- Fixed deprecation warning
|
18
|
+
|
19
|
+
## 0.4.1 (2019-10-27)
|
20
|
+
|
21
|
+
- Added Postmark support
|
22
|
+
|
23
|
+
## 0.4.0 (2019-07-15)
|
24
|
+
|
25
|
+
- Fixed error with model methods and `email_key` option
|
26
|
+
- Fixed bug with `opted_out` scope
|
27
|
+
- Dropped support for Action Mailer 4.2
|
28
|
+
|
29
|
+
## 0.3.1 (2018-04-21)
|
30
|
+
|
31
|
+
- Fixed `Secret should not be nil` error in Rails 5.2
|
32
|
+
- Gracefully handle missing email
|
33
|
+
- Added `user` option to `mailkick_unsubscribe_url`
|
34
|
+
|
35
|
+
## 0.3.0 (2018-04-20)
|
36
|
+
|
37
|
+
- Improved performance
|
38
|
+
- Fixed `Subscription not found` for Rails 5.2
|
39
|
+
- Use `references` in migration
|
40
|
+
- Use `smtp_settings[:domain]` for Mailgun
|
41
|
+
- Dropped support for Action Mailer < 4.2
|
42
|
+
|
43
|
+
## 0.2.1 (2017-10-30)
|
44
|
+
|
45
|
+
- Fixed errors with Rails 5+
|
46
|
+
- Fixed errors with the latest version of Gibbon
|
47
|
+
|
48
|
+
## 0.2.0 (2017-05-01)
|
49
|
+
|
50
|
+
- Added support for Rails 5.1
|
51
|
+
|
52
|
+
## 0.1.6 (2017-01-10)
|
53
|
+
|
54
|
+
- Fixed error with frozen strings
|
55
|
+
|
56
|
+
## 0.1.5 (2016-12-06)
|
57
|
+
|
58
|
+
- Use `safely`
|
59
|
+
- Only discover services if not manually set
|
60
|
+
- Added `mount` option
|
61
|
+
|
62
|
+
## 0.1.4 (2016-02-20)
|
2
63
|
|
3
64
|
- Use `Module#prepend` instead of `alias_method_chain`
|
4
65
|
|
5
|
-
## 0.1.3
|
66
|
+
## 0.1.3 (2015-06-29)
|
6
67
|
|
7
68
|
- Fixed issue with double escaping tokens
|
8
69
|
|
9
|
-
## 0.1.2
|
70
|
+
## 0.1.2 (2015-06-07)
|
10
71
|
|
11
72
|
- Added support for Mailgun
|
12
73
|
|
13
|
-
## 0.1.1
|
74
|
+
## 0.1.1 (2015-01-31)
|
14
75
|
|
15
76
|
- Fixed tokens with `+` in them
|
16
77
|
|
17
|
-
## 0.1.0
|
78
|
+
## 0.1.0 (2014-08-31)
|
18
79
|
|
19
80
|
- Fixed secret token for Rails 4.1
|
20
81
|
|
21
|
-
## 0.0.6
|
82
|
+
## 0.0.6 (2014-05-09)
|
22
83
|
|
23
84
|
- Rails 3 fix
|
24
85
|
|
25
|
-
## 0.0.5
|
86
|
+
## 0.0.5 (2014-05-05)
|
26
87
|
|
27
88
|
- Fixed bug with subscriptions page
|
28
89
|
|
29
|
-
## 0.0.4
|
90
|
+
## 0.0.4 (2014-05-05)
|
30
91
|
|
31
92
|
- Added `email_key` option to `mailkick_user`
|
32
93
|
|
33
|
-
## 0.0.3
|
94
|
+
## 0.0.3 (2014-05-04)
|
34
95
|
|
35
96
|
- Added support for multiple lists
|
36
97
|
- Changed `mailkick_user` method names - sorry early adopters :(
|
37
98
|
|
38
|
-
## 0.0.2
|
99
|
+
## 0.0.2 (2014-05-04)
|
39
100
|
|
40
101
|
- Added Mailchimp service
|
41
102
|
- Fixed Mandrill service
|
42
103
|
- Added `uniq` to `subscribed` scope
|
43
104
|
|
44
|
-
## 0.0.1
|
105
|
+
## 0.0.1 (2014-05-04)
|
45
106
|
|
46
107
|
- First release
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
# Mailkick
|
2
2
|
|
3
|
-
|
3
|
+
Email subscriptions for Rails
|
4
4
|
|
5
5
|
- Add one-click unsubscribe links to your emails
|
6
6
|
- Fetch bounces and spam reports from your email service
|
7
7
|
|
8
|
-
|
8
|
+
**Mailkick 1.0 was recently released** - see [how to upgrade](#upgrading)
|
9
9
|
|
10
10
|
:postbox: Check out [Ahoy Email](https://github.com/ankane/ahoy_email) for analytics
|
11
11
|
|
12
|
+
[](https://github.com/ankane/mailkick/actions)
|
13
|
+
|
12
14
|
## Installation
|
13
15
|
|
14
16
|
Add this line to your application’s Gemfile:
|
@@ -17,205 +19,249 @@ Add this line to your application’s Gemfile:
|
|
17
19
|
gem 'mailkick'
|
18
20
|
```
|
19
21
|
|
20
|
-
And run the generator. This creates a
|
22
|
+
And run the generator. This creates a table to store subscriptions.
|
21
23
|
|
22
24
|
```sh
|
25
|
+
bundle install
|
23
26
|
rails generate mailkick:install
|
24
|
-
|
27
|
+
rails db:migrate
|
25
28
|
```
|
26
29
|
|
27
|
-
##
|
28
|
-
|
29
|
-
Add an unsubscribe link to your emails.
|
30
|
+
## Getting Started
|
30
31
|
|
31
|
-
|
32
|
+
Add `has_subscriptions` to your user model:
|
32
33
|
|
33
|
-
```
|
34
|
-
|
34
|
+
```ruby
|
35
|
+
class User < ApplicationRecord
|
36
|
+
has_subscriptions
|
37
|
+
end
|
35
38
|
```
|
36
39
|
|
37
|
-
|
40
|
+
Subscribe to a list
|
38
41
|
|
39
|
-
```
|
40
|
-
|
42
|
+
```ruby
|
43
|
+
user.subscribe("sales")
|
41
44
|
```
|
42
45
|
|
43
|
-
|
44
|
-
|
45
|
-
To customize the view, run:
|
46
|
+
Unsubscribe from a list
|
46
47
|
|
47
|
-
```
|
48
|
-
|
48
|
+
```ruby
|
49
|
+
user.unsubscribe("sales")
|
49
50
|
```
|
50
51
|
|
51
|
-
|
52
|
-
|
53
|
-
## Sending Emails
|
52
|
+
Check if subscribed
|
54
53
|
|
55
|
-
|
54
|
+
```ruby
|
55
|
+
user.subscribed?("sales")
|
56
|
+
```
|
56
57
|
|
57
|
-
|
58
|
+
Get subscribers for a list (use this for sending emails)
|
58
59
|
|
59
60
|
```ruby
|
60
|
-
|
61
|
-
mailkick_user
|
62
|
-
end
|
61
|
+
User.subscribed("sales")
|
63
62
|
```
|
64
63
|
|
65
|
-
|
64
|
+
## Unsubscribe Links
|
66
65
|
|
67
|
-
|
68
|
-
|
66
|
+
Add an unsubscribe link to your emails. For HTML emails, use:
|
67
|
+
|
68
|
+
```erb
|
69
|
+
<%= link_to "Unsubscribe", mailkick_unsubscribe_url(@user, "sales") %>
|
69
70
|
```
|
70
71
|
|
71
|
-
|
72
|
+
For text emails, use:
|
72
73
|
|
73
|
-
```
|
74
|
-
|
74
|
+
```erb
|
75
|
+
Unsubscribe: <%= mailkick_unsubscribe_url(@user, "sales") %>
|
75
76
|
```
|
76
77
|
|
77
|
-
|
78
|
+
When a user unsubscribes, they are taken to a mobile-friendly page and given the option to resubscribe. To customize the view, run:
|
78
79
|
|
79
|
-
```
|
80
|
-
|
80
|
+
```sh
|
81
|
+
rails generate mailkick:views
|
81
82
|
```
|
82
83
|
|
84
|
+
which copies the view into `app/views/mailkick`.
|
85
|
+
|
83
86
|
## Bounces and Spam Reports
|
84
87
|
|
85
|
-
Fetch bounces, spam reports, and unsubscribes from your email service.
|
88
|
+
Fetch bounces, spam reports, and unsubscribes from your email service. Create `config/initializers/mailkick.rb` with a method to handle opt outs.
|
86
89
|
|
87
90
|
```ruby
|
88
|
-
Mailkick.
|
89
|
-
|
91
|
+
Mailkick.process_opt_outs_method = lambda do |opt_outs|
|
92
|
+
emails = opt_outs.map { |v| v[:email] }
|
93
|
+
subscribers = User.includes(:mailkick_subscriptions).where(email: emails).index_by(&:email)
|
90
94
|
|
91
|
-
|
95
|
+
opt_outs.each do |opt_out|
|
96
|
+
subscriber = subscribers[opt_out[:email]]
|
97
|
+
next unless subscriber
|
92
98
|
|
93
|
-
|
99
|
+
subscriber.mailkick_subscriptions.each do |subscription|
|
100
|
+
subscription.destroy if subscription.created_at < opt_out[:time]
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
```
|
105
|
+
|
106
|
+
And run:
|
94
107
|
|
95
108
|
```ruby
|
96
|
-
|
109
|
+
Mailkick.fetch_opt_outs
|
97
110
|
```
|
98
111
|
|
99
|
-
|
112
|
+
The following services are supported:
|
100
113
|
|
101
|
-
|
114
|
+
- [AWS SES](#aws-ses)
|
115
|
+
- [Mailchimp](#mailchimp)
|
116
|
+
- [Mailgun](#mailgun)
|
117
|
+
- [Mandrill](#mandrill)
|
118
|
+
- [Postmark](#postmark)
|
119
|
+
- [SendGrid](#sendgrid)
|
120
|
+
|
121
|
+
Will gladly accept pull requests for others.
|
122
|
+
|
123
|
+
#### AWS SES
|
124
|
+
|
125
|
+
Add the gem
|
102
126
|
|
103
127
|
```ruby
|
104
|
-
gem '
|
128
|
+
gem 'aws-sdk-sesv2'
|
105
129
|
```
|
106
130
|
|
107
|
-
|
131
|
+
And [configure your AWS credentials](https://github.com/aws/aws-sdk-ruby#configuration). Requires `ses:ListSuppressedDestinations` permission.
|
132
|
+
|
133
|
+
If you started using Amazon SES [before November 25, 2019](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/sending-email-suppression-list.html#sending-email-suppression-list-considerations), you have to manually [enable account-level suppression list feature](https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_PutAccountSuppressionAttributes.html).
|
108
134
|
|
109
135
|
#### Mailchimp
|
110
136
|
|
137
|
+
Add the gem
|
138
|
+
|
111
139
|
```ruby
|
112
|
-
gem 'gibbon'
|
140
|
+
gem 'gibbon', '>= 2'
|
113
141
|
```
|
114
142
|
|
115
|
-
|
143
|
+
And set `ENV["MAILCHIMP_API_KEY"]` and `ENV["MAILCHIMP_LIST_ID"]`.
|
116
144
|
|
117
145
|
#### Mailgun
|
118
146
|
|
147
|
+
Add the gem
|
148
|
+
|
119
149
|
```ruby
|
120
150
|
gem 'mailgun-ruby'
|
121
151
|
```
|
122
152
|
|
123
|
-
|
153
|
+
And set `ENV["MAILGUN_API_KEY"]`.
|
124
154
|
|
125
|
-
####
|
126
|
-
|
127
|
-
Will gladly accept pull requests.
|
128
|
-
|
129
|
-
### Advanced
|
155
|
+
#### Mandrill
|
130
156
|
|
131
|
-
|
157
|
+
Add the gem
|
132
158
|
|
133
159
|
```ruby
|
134
|
-
|
135
|
-
Mailkick::Service::Sendgrid.new(api_key: "API_KEY"),
|
136
|
-
Mailkick::Service::Mandrill.new(api_key: "API_KEY")
|
137
|
-
]
|
160
|
+
gem 'mandrill-api'
|
138
161
|
```
|
139
162
|
|
140
|
-
|
163
|
+
And set `ENV["MANDRILL_APIKEY"]`.
|
141
164
|
|
142
|
-
|
165
|
+
#### Postmark
|
143
166
|
|
144
|
-
|
167
|
+
Add the gem
|
145
168
|
|
146
169
|
```ruby
|
147
|
-
|
170
|
+
gem 'postmark'
|
171
|
+
```
|
148
172
|
|
149
|
-
|
150
|
-
headers[:mailkick_list] = "order_reminders"
|
151
|
-
# ...
|
152
|
-
end
|
173
|
+
And set `ENV["POSTMARK_API_KEY"]`.
|
153
174
|
|
154
|
-
|
155
|
-
```
|
175
|
+
#### SendGrid
|
156
176
|
|
157
|
-
|
177
|
+
Add the gem
|
158
178
|
|
159
179
|
```ruby
|
160
|
-
|
161
|
-
User.not_opted_out(list: "order_reminders")
|
162
|
-
user.opted_out?(list: "order_reminders")
|
180
|
+
gem 'sendgrid-ruby'
|
163
181
|
```
|
164
182
|
|
165
|
-
|
183
|
+
And set `ENV["SENDGRID_API_KEY"]`. The API key requires only the `Suppressions` permission.
|
166
184
|
|
167
|
-
|
185
|
+
### Advanced
|
168
186
|
|
169
|
-
|
187
|
+
For more control over services, set them by hand.
|
170
188
|
|
171
189
|
```ruby
|
172
|
-
|
190
|
+
Mailkick.services = [
|
191
|
+
Mailkick::Service::SendGridV2.new(api_key: "API_KEY"),
|
192
|
+
Mailkick::Service::Mailchimp.new(api_key: "API_KEY", list_id: "LIST_ID")
|
193
|
+
]
|
173
194
|
```
|
174
195
|
|
175
|
-
|
196
|
+
## Reference
|
197
|
+
|
198
|
+
Access the subscription model directly
|
176
199
|
|
177
200
|
```ruby
|
178
|
-
|
201
|
+
Mailkick::Subscription.all
|
179
202
|
```
|
180
203
|
|
181
|
-
##
|
182
|
-
|
183
|
-
More great gems for email
|
204
|
+
## Upgrading
|
184
205
|
|
185
|
-
|
186
|
-
- [Letter Opener](https://github.com/ryanb/letter_opener) - preview email in development
|
206
|
+
### 1.0
|
187
207
|
|
188
|
-
|
208
|
+
Mailkick 1.0 stores subscriptions instead of opt-outs. To migrate:
|
189
209
|
|
190
|
-
|
191
|
-
- Subscribe to events
|
210
|
+
1. Add a table to store subscriptions
|
192
211
|
|
193
|
-
|
212
|
+
```sh
|
213
|
+
rails generate mailkick:install
|
214
|
+
rails db:migrate
|
215
|
+
```
|
194
216
|
|
195
|
-
Change
|
217
|
+
2. Change the following methods in your code:
|
196
218
|
|
197
|
-
|
198
|
-
|
199
|
-
|
219
|
+
- `mailkick_user` to `has_subscriptions`
|
220
|
+
- `User.not_opted_out` to `User.subscribed(list)`
|
221
|
+
- `opt_in` to `subscribe(list)`
|
222
|
+
- `opt_out` to `unsubscribe(list)`
|
200
223
|
|
201
|
-
|
224
|
+
3. Add a user and list to `mailkick_unsubscribe_url`
|
202
225
|
|
203
226
|
```ruby
|
204
|
-
|
227
|
+
mailkick_unsubscribe_url(user, list)
|
205
228
|
```
|
206
229
|
|
207
|
-
|
230
|
+
4. Migrate data for each of your lists
|
208
231
|
|
209
232
|
```ruby
|
210
|
-
|
233
|
+
opted_out_emails = Mailkick::Legacy.opted_out_emails(list: nil)
|
234
|
+
opted_out_users = Mailkick::Legacy.opted_out_users(list: nil)
|
235
|
+
|
236
|
+
User.find_in_batches do |users|
|
237
|
+
users.reject! { |u| opted_out_emails.include?(u.email) }
|
238
|
+
users.reject! { |u| opted_out_users.include?(u) }
|
239
|
+
|
240
|
+
now = Time.now
|
241
|
+
records =
|
242
|
+
users.map do |user|
|
243
|
+
{
|
244
|
+
subscriber_type: user.class.name,
|
245
|
+
subscriber_id: user.id,
|
246
|
+
list: "sales",
|
247
|
+
created_at: now,
|
248
|
+
updated_at: now
|
249
|
+
}
|
250
|
+
end
|
251
|
+
|
252
|
+
# use create! for Active Record < 6
|
253
|
+
Mailkick::Subscription.insert_all!(records)
|
254
|
+
end
|
211
255
|
```
|
212
256
|
|
213
|
-
|
257
|
+
5. Drop the `mailkick_opt_outs` table
|
214
258
|
|
215
259
|
```ruby
|
216
|
-
|
260
|
+
drop_table :mailkick_opt_outs
|
217
261
|
```
|
218
262
|
|
263
|
+
Also, if you use `Mailkick.fetch_opt_outs`, [add a method](#bounces-and-spam-reports) to handle opt outs.
|
264
|
+
|
219
265
|
## History
|
220
266
|
|
221
267
|
View the [changelog](https://github.com/ankane/mailkick/blob/master/CHANGELOG.md)
|
@@ -228,3 +274,12 @@ Everyone is encouraged to help improve this project. Here are a few ways you can
|
|
228
274
|
- Fix bugs and [submit pull requests](https://github.com/ankane/mailkick/pulls)
|
229
275
|
- Write, clarify, or fix documentation
|
230
276
|
- Suggest or add new features
|
277
|
+
|
278
|
+
To get started with development and testing:
|
279
|
+
|
280
|
+
```sh
|
281
|
+
git clone https://github.com/ankane/mailkick.git
|
282
|
+
cd mailkick
|
283
|
+
bundle install
|
284
|
+
bundle exec rake test
|
285
|
+
```
|
@@ -1,42 +1,51 @@
|
|
1
1
|
module Mailkick
|
2
2
|
class SubscriptionsController < ActionController::Base
|
3
|
-
|
3
|
+
protect_from_forgery with: :exception
|
4
|
+
|
5
|
+
before_action :set_subscription
|
4
6
|
|
5
7
|
def show
|
6
8
|
end
|
7
9
|
|
8
10
|
def unsubscribe
|
9
|
-
|
11
|
+
subscription.delete_all
|
12
|
+
|
13
|
+
Mailkick::Legacy.opt_out(legacy_options) if Mailkick::Legacy.opt_outs?
|
14
|
+
|
10
15
|
redirect_to subscription_path(params[:id])
|
11
16
|
end
|
12
17
|
|
13
18
|
def subscribe
|
14
|
-
|
19
|
+
subscription.first_or_create!
|
20
|
+
|
21
|
+
Mailkick::Legacy.opt_in(legacy_options) if Mailkick::Legacy.opt_outs?
|
22
|
+
|
15
23
|
redirect_to subscription_path(params[:id])
|
16
24
|
end
|
17
25
|
|
18
26
|
protected
|
19
27
|
|
20
|
-
def
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
if user_type
|
25
|
-
# on the unprobabilistic chance user_type is compromised, not much damage
|
26
|
-
@user = user_type.constantize.find(user_id)
|
27
|
-
end
|
28
|
-
@options = {
|
29
|
-
email: @email,
|
30
|
-
user: @user,
|
31
|
-
list: @list
|
32
|
-
}
|
33
|
-
rescue ActiveSupport::MessageVerifier::InvalidSignature
|
34
|
-
render text: "Subscription not found", status: :bad_request
|
35
|
-
end
|
28
|
+
def set_subscription
|
29
|
+
@email, @subscriber_id, @subscriber_type, @list = Mailkick.message_verifier.verify(params[:id])
|
30
|
+
rescue ActiveSupport::MessageVerifier::InvalidSignature
|
31
|
+
render plain: "Subscription not found", status: :bad_request
|
36
32
|
end
|
37
33
|
|
34
|
+
def subscription
|
35
|
+
Mailkick::Subscription.where(
|
36
|
+
subscriber_id: @subscriber_id,
|
37
|
+
subscriber_type: @subscriber_type,
|
38
|
+
list: @list
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
def subscribed?
|
43
|
+
subscription.exists?
|
44
|
+
end
|
45
|
+
helper_method :subscribed?
|
46
|
+
|
38
47
|
def opted_out?
|
39
|
-
|
48
|
+
!subscribed?
|
40
49
|
end
|
41
50
|
helper_method :opted_out?
|
42
51
|
|
@@ -49,5 +58,17 @@ module Mailkick
|
|
49
58
|
unsubscribe_subscription_path(params[:id])
|
50
59
|
end
|
51
60
|
helper_method :unsubscribe_url
|
61
|
+
|
62
|
+
def legacy_options
|
63
|
+
if @subscriber_type
|
64
|
+
# on the unprobabilistic chance subscriber_type is compromised, not much damage
|
65
|
+
user = @subscriber_type.constantize.find(@subscriber_id)
|
66
|
+
end
|
67
|
+
{
|
68
|
+
email: @email,
|
69
|
+
user: user,
|
70
|
+
list: @list
|
71
|
+
}
|
72
|
+
end
|
52
73
|
end
|
53
74
|
end
|
data/config/routes.rb
CHANGED
@@ -1,28 +1,17 @@
|
|
1
|
-
# taken from https://github.com/collectiveidea/audited/blob/master/lib/generators/audited/install_generator.rb
|
2
|
-
require "rails/generators"
|
3
|
-
require "rails/generators/migration"
|
4
|
-
require "active_record"
|
5
1
|
require "rails/generators/active_record"
|
6
2
|
|
7
3
|
module Mailkick
|
8
4
|
module Generators
|
9
5
|
class InstallGenerator < Rails::Generators::Base
|
10
|
-
include
|
6
|
+
include ActiveRecord::Generators::Migration
|
7
|
+
source_root File.join(__dir__, "templates")
|
11
8
|
|
12
|
-
|
13
|
-
|
14
|
-
# Implement the required interface for Rails::Generators::Migration.
|
15
|
-
def self.next_migration_number(dirname) #:nodoc:
|
16
|
-
next_migration_number = current_migration_number(dirname) + 1
|
17
|
-
if ActiveRecord::Base.timestamped_migrations
|
18
|
-
[Time.now.utc.strftime("%Y%m%d%H%M%S"), "%.14d" % next_migration_number].max
|
19
|
-
else
|
20
|
-
"%.3d" % next_migration_number
|
21
|
-
end
|
9
|
+
def copy_migration
|
10
|
+
migration_template "install.rb", "db/migrate/create_mailkick_subscriptions.rb", migration_version: migration_version
|
22
11
|
end
|
23
12
|
|
24
|
-
def
|
25
|
-
|
13
|
+
def migration_version
|
14
|
+
"[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
|
26
15
|
end
|
27
16
|
end
|
28
17
|
end
|