mailkick 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +11 -2
- data/app/controllers/mailkick/subscriptions_controller.rb +4 -4
- data/app/helpers/mailkick/url_helper.rb +2 -2
- data/lib/mailkick/model.rb +1 -1
- data/lib/mailkick/service/mailchimp.rb +43 -0
- data/lib/mailkick/service/mandrill.rb +14 -4
- data/lib/mailkick/service/sendgrid.rb +1 -0
- data/lib/mailkick/version.rb +1 -1
- data/lib/mailkick.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 902719cffa741b74a8efa92f326e98c5d359d610
|
4
|
+
data.tar.gz: 0a15d25bf9ea0201eabc5eeace46cba06b878596
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9e635f1f60c3eb5043450aea43133e6a9feb3cccaa1116ca4dfc769c73e1d0f51ecd7dec73d7fc5793f2893e08c4b66f8d774774ac5e2fd8326d890286a9b8b
|
7
|
+
data.tar.gz: f21ad8fed634b2e4bec5801df0a5d8b305656e4ff4922894461df36700fedb5f2f8704ad00c42e6b11ee2f2b6cd2f85affd3235038e0ff1ef2cd5a9600ceb1c2
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -104,7 +104,7 @@ gem 'sendgrid_toolkit'
|
|
104
104
|
|
105
105
|
Be sure `ENV["SENDGRID_USERNAME"]` and `ENV["SENDGRID_PASSWORD"]` are set.
|
106
106
|
|
107
|
-
#### Mandrill
|
107
|
+
#### Mandrill
|
108
108
|
|
109
109
|
```ruby
|
110
110
|
gem 'mandrill-api'
|
@@ -112,9 +112,17 @@ gem 'mandrill-api'
|
|
112
112
|
|
113
113
|
Be sure `ENV["MANDRILL_APIKEY"]` is set.
|
114
114
|
|
115
|
+
#### Mailchimp
|
116
|
+
|
117
|
+
```ruby
|
118
|
+
gem 'gibbon'
|
119
|
+
```
|
120
|
+
|
121
|
+
Be sure `ENV["MAILCHIMP_API_KEY"]` and `ENV["MAILCHIMP_LIST_ID"]` are set.
|
122
|
+
|
115
123
|
#### Other
|
116
124
|
|
117
|
-
|
125
|
+
Will gladly accept pull requests.
|
118
126
|
|
119
127
|
### Advanced
|
120
128
|
|
@@ -136,6 +144,7 @@ Coming soon
|
|
136
144
|
More great gems for email
|
137
145
|
|
138
146
|
- [Roadie](https://github.com/Mange/roadie) - inline CSS
|
147
|
+
- [Letter Opener](https://github.com/ryanb/letter_opener) - preview email in development
|
139
148
|
|
140
149
|
## Reference
|
141
150
|
|
@@ -53,13 +53,13 @@ module Mailkick
|
|
53
53
|
end
|
54
54
|
helper_method :subscribed?
|
55
55
|
|
56
|
-
def subscribe_url
|
57
|
-
subscribe_subscription_path(params[:id])
|
56
|
+
def subscribe_url(options = {})
|
57
|
+
subscribe_subscription_path(params[:id], options)
|
58
58
|
end
|
59
59
|
helper_method :subscribe_url
|
60
60
|
|
61
|
-
def unsubscribe_url
|
62
|
-
unsubscribe_subscription_path(params[:id])
|
61
|
+
def unsubscribe_url(options = {})
|
62
|
+
unsubscribe_subscription_path(params[:id], options)
|
63
63
|
end
|
64
64
|
helper_method :unsubscribe_url
|
65
65
|
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module Mailkick
|
2
2
|
module UrlHelper
|
3
3
|
|
4
|
-
def mailkick_unsubscribe_url
|
4
|
+
def mailkick_unsubscribe_url(options = {})
|
5
5
|
Mailkick::Engine.routes.url_helpers.url_for(
|
6
|
-
Rails.application.config.action_mailer.default_url_options.merge(
|
6
|
+
Rails.application.config.action_mailer.default_url_options.merge(options).merge(
|
7
7
|
controller: "mailkick/subscriptions",
|
8
8
|
action: "unsubscribe",
|
9
9
|
id: "{{MAILKICK_TOKEN}}"
|
data/lib/mailkick/model.rb
CHANGED
@@ -3,7 +3,7 @@ module Mailkick
|
|
3
3
|
|
4
4
|
def mailkick_user(options = {})
|
5
5
|
class_eval do
|
6
|
-
scope :subscribed, proc{ joins(sanitize_sql_array(["LEFT JOIN mailkick_opt_outs ON #{table_name}.email = mailkick_opt_outs.email OR (#{table_name}.id = mailkick_opt_outs.user_id AND mailkick_opt_outs.user_type = ?)", name])).where("active != ?", true) }
|
6
|
+
scope :subscribed, proc{ joins(sanitize_sql_array(["LEFT JOIN mailkick_opt_outs ON #{table_name}.email = mailkick_opt_outs.email OR (#{table_name}.id = mailkick_opt_outs.user_id AND mailkick_opt_outs.user_type = ?)", name])).where("active != ?", true).uniq }
|
7
7
|
|
8
8
|
def opt_outs
|
9
9
|
Mailkick::OptOut.where("email = ? OR (user_id = ? AND user_type = ?)", email, id, self.class.name)
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# https://github.com/amro/gibbon
|
2
|
+
|
3
|
+
module Mailkick
|
4
|
+
class Service
|
5
|
+
class Mailchimp < Mailkick::Service
|
6
|
+
|
7
|
+
def initialize(options = {})
|
8
|
+
@gibbon = ::Gibbon::API.new(options[:api_key] || ENV["MAILCHIMP_API_KEY"])
|
9
|
+
@list_id = options[:list_id] || ENV["MAILCHIMP_LIST_ID"]
|
10
|
+
end
|
11
|
+
|
12
|
+
# TODO paginate
|
13
|
+
def opt_outs
|
14
|
+
unsubscribes + spam_reports
|
15
|
+
end
|
16
|
+
|
17
|
+
def unsubscribes
|
18
|
+
fetch(@gibbon.lists.members(id: @list_id, status: "unsubscribed"), "unsubscribe")
|
19
|
+
end
|
20
|
+
|
21
|
+
def spam_reports
|
22
|
+
fetch(@gibbon.lists.abuse_reports(id: @list_id), "spam")
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.discoverable?
|
26
|
+
!!(defined?(::Gibbon) && ENV["MAILCHIMP_API_KEY"] && ENV["MAILCHIMP_LIST_ID"])
|
27
|
+
end
|
28
|
+
|
29
|
+
protected
|
30
|
+
|
31
|
+
def fetch(response, reason)
|
32
|
+
response["data"].map do |record|
|
33
|
+
{
|
34
|
+
email: record["email"],
|
35
|
+
time: ActiveSupport::TimeZone["UTC"].parse(record["timestamp_opt"] || record["date"]),
|
36
|
+
reason: reason
|
37
|
+
}
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -3,17 +3,27 @@
|
|
3
3
|
module Mailkick
|
4
4
|
class Service
|
5
5
|
class Mandrill < Mailkick::Service
|
6
|
+
REASONS_MAP = {
|
7
|
+
"hard-bounce" => "bounce",
|
8
|
+
"soft-bounce" => "bounce",
|
9
|
+
"spam" => "spam",
|
10
|
+
"unsub" => "unsubscribe"
|
11
|
+
}
|
6
12
|
|
7
13
|
def initialize(options = {})
|
8
14
|
require "mandrill"
|
9
15
|
@mandrill = ::Mandrill::API.new(options[:api_key] || ENV["MANDRILL_APIKEY"])
|
10
16
|
end
|
11
17
|
|
18
|
+
# TODO paginate
|
12
19
|
def opt_outs
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
20
|
+
@mandrill.rejects.list.map do |record|
|
21
|
+
{
|
22
|
+
email: record["email"],
|
23
|
+
time: ActiveSupport::TimeZone["UTC"].parse(record["created_at"]),
|
24
|
+
reason: REASONS_MAP[record["reason"]]
|
25
|
+
}
|
26
|
+
end
|
17
27
|
end
|
18
28
|
|
19
29
|
def self.discoverable?
|
data/lib/mailkick/version.rb
CHANGED
data/lib/mailkick.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mailkick
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
@@ -65,6 +65,7 @@ files:
|
|
65
65
|
- lib/mailkick/model.rb
|
66
66
|
- lib/mailkick/processor.rb
|
67
67
|
- lib/mailkick/service.rb
|
68
|
+
- lib/mailkick/service/mailchimp.rb
|
68
69
|
- lib/mailkick/service/mandrill.rb
|
69
70
|
- lib/mailkick/service/sendgrid.rb
|
70
71
|
- lib/mailkick/version.rb
|