mailkick 0.1.1 → 0.1.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 +4 -0
- data/Gemfile +1 -1
- data/README.md +9 -1
- data/Rakefile +0 -1
- data/app/controllers/mailkick/subscriptions_controller.rb +1 -2
- data/app/helpers/mailkick/url_helper.rb +0 -2
- data/lib/generators/mailkick/install_generator.rb +0 -1
- data/lib/generators/mailkick/views_generator.rb +0 -1
- data/lib/mailkick/mailer.rb +0 -2
- data/lib/mailkick/model.rb +1 -4
- data/lib/mailkick/processor.rb +1 -2
- data/lib/mailkick/service/mailchimp.rb +0 -2
- data/lib/mailkick/service/mailgun.rb +46 -0
- data/lib/mailkick/service/mandrill.rb +0 -1
- data/lib/mailkick/service/sendgrid.rb +0 -2
- data/lib/mailkick/service.rb +1 -3
- data/lib/mailkick/version.rb +1 -1
- data/lib/mailkick.rb +4 -6
- data/mailkick.gemspec +4 -4
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b352637be3b03e2c64e52936662205cf4524aa93
|
4
|
+
data.tar.gz: 5c3340840799c56a44c246667f86c13e22ad375c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a0b3d37bc1d3e883e30518960d486784850ab703ba4a8108cc4d1ca5b0d9d78fe0981bbf130fec0188db53d3011d0e5b9cd8ad8c9832b3491f77eb5263da92f
|
7
|
+
data.tar.gz: 1524cf7d6fd3d9a297a1ca9854868cccda35c42bff1ff325ade4f38b37ce6862cca05ce4ab91d00c70a2b0d353f82b9f733e520471e047b385454b1398e87065
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -114,6 +114,14 @@ gem 'gibbon'
|
|
114
114
|
|
115
115
|
Be sure `ENV["MAILCHIMP_API_KEY"]` and `ENV["MAILCHIMP_LIST_ID"]` are set.
|
116
116
|
|
117
|
+
#### Mailgun
|
118
|
+
|
119
|
+
```ruby
|
120
|
+
gem 'mailgun-ruby'
|
121
|
+
```
|
122
|
+
|
123
|
+
Be sure `ENV["MAILGUN_API_KEY"]` is set.
|
124
|
+
|
117
125
|
#### Other
|
118
126
|
|
119
127
|
Will gladly accept pull requests.
|
@@ -139,7 +147,7 @@ Set the list in the mailer.
|
|
139
147
|
class UserMailer < ActionMailer::Base
|
140
148
|
|
141
149
|
def order_reminder(user)
|
142
|
-
|
150
|
+
headers[:mailkick_list] = "order_reminders"
|
143
151
|
# ...
|
144
152
|
end
|
145
153
|
|
data/Rakefile
CHANGED
data/lib/mailkick/mailer.rb
CHANGED
data/lib/mailkick/model.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
module Mailkick
|
2
2
|
module Model
|
3
|
-
|
4
3
|
def mailkick_user(options = {})
|
5
4
|
email_key = options[:email_key] || :email
|
6
5
|
class_eval do
|
@@ -12,7 +11,7 @@ module Mailkick
|
|
12
11
|
else
|
13
12
|
query = "mailkick_opt_outs.list IS NULL"
|
14
13
|
end
|
15
|
-
where("#{options[:not] ?
|
14
|
+
where("#{options[:not] ? 'NOT ' : ''}EXISTS(SELECT * FROM mailkick_opt_outs WHERE (#{table_name}.#{email_key} = mailkick_opt_outs.email OR (#{table_name}.#{primary_key} = mailkick_opt_outs.user_id AND mailkick_opt_outs.user_type = ?)) AND mailkick_opt_outs.active = ? AND #{query})", *binds)
|
16
15
|
}
|
17
16
|
scope :not_opted_out, proc {|options = {}|
|
18
17
|
opted_out(options.merge(not: true))
|
@@ -29,9 +28,7 @@ module Mailkick
|
|
29
28
|
def opt_in(options = {})
|
30
29
|
Mailkick.opt_in({email: email, user: self}.merge(options))
|
31
30
|
end
|
32
|
-
|
33
31
|
end
|
34
32
|
end
|
35
|
-
|
36
33
|
end
|
37
34
|
end
|
data/lib/mailkick/processor.rb
CHANGED
@@ -20,9 +20,8 @@ module Mailkick
|
|
20
20
|
|
21
21
|
parts = message.parts.any? ? message.parts : [message]
|
22
22
|
parts.each do |part|
|
23
|
-
part.body.raw_source.gsub!(/%7B%7BMAILKICK_TOKEN%7D%7D/, CGI
|
23
|
+
part.body.raw_source.gsub!(/%7B%7BMAILKICK_TOKEN%7D%7D/, CGI.escape(token))
|
24
24
|
end
|
25
25
|
end
|
26
|
-
|
27
26
|
end
|
28
27
|
end
|
@@ -3,7 +3,6 @@
|
|
3
3
|
module Mailkick
|
4
4
|
class Service
|
5
5
|
class Mailchimp < Mailkick::Service
|
6
|
-
|
7
6
|
def initialize(options = {})
|
8
7
|
@gibbon = ::Gibbon::API.new(options[:api_key] || ENV["MAILCHIMP_API_KEY"])
|
9
8
|
@list_id = options[:list_id] || ENV["MAILCHIMP_LIST_ID"]
|
@@ -37,7 +36,6 @@ module Mailkick
|
|
37
36
|
}
|
38
37
|
end
|
39
38
|
end
|
40
|
-
|
41
39
|
end
|
42
40
|
end
|
43
41
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# https://github.com/mailgun/mailgun-ruby
|
2
|
+
|
3
|
+
module Mailkick
|
4
|
+
class Service
|
5
|
+
class Mailgun < Mailkick::Service
|
6
|
+
def initalize(options = {})
|
7
|
+
require 'mailgun'
|
8
|
+
mailgun_client = ::Mailgun::Client.new(options[:api_key] || ENV["MAILGUN_API_KEY"])
|
9
|
+
domain = options[:domain] || ActionMailer::Base.default_url_options[:host]
|
10
|
+
@mailgun_events = ::Mailgun::Events.new(mailgun_client, domain)
|
11
|
+
end
|
12
|
+
|
13
|
+
def opt_outs
|
14
|
+
unsubscribes + spam_reports + bounces
|
15
|
+
end
|
16
|
+
|
17
|
+
def unsubscribes
|
18
|
+
fetch(@mailgun_events.get({event: 'unsubscribed'}), 'unsubscribe')
|
19
|
+
end
|
20
|
+
|
21
|
+
def spam_reports
|
22
|
+
fetch(@mailgun_events.get({event: 'complained'}), 'spam')
|
23
|
+
end
|
24
|
+
|
25
|
+
def bounces
|
26
|
+
fetch(@mailgun_events.get({event: 'failed'}), 'bounce')
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.discoverable?
|
30
|
+
!!(defined?(::Mailgun) && ENV["MAILGUN_API_KEY"])
|
31
|
+
end
|
32
|
+
|
33
|
+
protected
|
34
|
+
|
35
|
+
def fetch(response, reason)
|
36
|
+
response.to_h['items'].map do |record|
|
37
|
+
{
|
38
|
+
email: record['recipient'],
|
39
|
+
time: ActiveSupport::TimeZone['UTC'].at(record['timestamp']),
|
40
|
+
reason: reason
|
41
|
+
}
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -3,7 +3,6 @@
|
|
3
3
|
module Mailkick
|
4
4
|
class Service
|
5
5
|
class Sendgrid < Mailkick::Service
|
6
|
-
|
7
6
|
def initialize(options = {})
|
8
7
|
@api_user = options[:api_user] || ENV["SENDGRID_USERNAME"]
|
9
8
|
@api_key = options[:api_key] || ENV["SENDGRID_PASSWORD"]
|
@@ -41,7 +40,6 @@ module Mailkick
|
|
41
40
|
}
|
42
41
|
end
|
43
42
|
end
|
44
|
-
|
45
43
|
end
|
46
44
|
end
|
47
45
|
end
|
data/lib/mailkick/service.rb
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
module Mailkick
|
2
2
|
class Service
|
3
|
-
|
4
3
|
def fetch_opt_outs
|
5
4
|
opt_outs.each do |api_data|
|
6
5
|
email = api_data[:email]
|
7
6
|
time = api_data[:time]
|
8
7
|
|
9
8
|
opt_out = Mailkick::OptOut.where(email: email).order("updated_at desc").first
|
10
|
-
if !opt_out
|
9
|
+
if !opt_out || (time > opt_out.updated_at && !opt_out.active)
|
11
10
|
Mailkick.opt_out(
|
12
11
|
email: email,
|
13
12
|
user: Mailkick.user_method ? Mailkick.user_method.call(email) : nil,
|
@@ -18,6 +17,5 @@ module Mailkick
|
|
18
17
|
end
|
19
18
|
true
|
20
19
|
end
|
21
|
-
|
22
20
|
end
|
23
21
|
end
|
data/lib/mailkick/version.rb
CHANGED
data/lib/mailkick.rb
CHANGED
@@ -7,17 +7,16 @@ require "mailkick/service"
|
|
7
7
|
require "mailkick/service/mailchimp"
|
8
8
|
require "mailkick/service/mandrill"
|
9
9
|
require "mailkick/service/sendgrid"
|
10
|
+
require "mailkick/service/mailgun"
|
10
11
|
require "set"
|
11
12
|
|
12
13
|
module Mailkick
|
13
14
|
mattr_accessor :services, :user_method, :secret_token
|
14
15
|
self.services = []
|
15
|
-
self.user_method = proc{|email| User.where(email: email).first rescue nil }
|
16
|
+
self.user_method = proc { |email| User.where(email: email).first rescue nil }
|
16
17
|
|
17
18
|
def self.fetch_opt_outs
|
18
|
-
services.each
|
19
|
-
service.fetch_opt_outs
|
20
|
-
end
|
19
|
+
services.each(&:fetch_opt_outs)
|
21
20
|
end
|
22
21
|
|
23
22
|
def self.discover_services
|
@@ -33,7 +32,7 @@ module Mailkick
|
|
33
32
|
end
|
34
33
|
|
35
34
|
def self.opt_out(options)
|
36
|
-
|
35
|
+
unless opted_out?(options)
|
37
36
|
time = options[:time] || Time.now
|
38
37
|
Mailkick::OptOut.create! do |o|
|
39
38
|
o.email = options[:email]
|
@@ -90,7 +89,6 @@ module Mailkick
|
|
90
89
|
def self.opted_out_users(options = {})
|
91
90
|
Set.new(opt_outs(options).where("user_id IS NOT NULL").map(&:user))
|
92
91
|
end
|
93
|
-
|
94
92
|
end
|
95
93
|
|
96
94
|
ActionMailer::Base.send :include, Mailkick::Mailer
|
data/mailkick.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
lib = File.expand_path(
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
4
|
+
require "mailkick/version"
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "mailkick"
|
8
8
|
spec.version = Mailkick::VERSION
|
9
9
|
spec.authors = ["Andrew Kane"]
|
10
10
|
spec.email = ["andrew@chartkick.com"]
|
11
|
-
spec.summary =
|
12
|
-
spec.description =
|
11
|
+
spec.summary = "Email subscriptions made easy"
|
12
|
+
spec.description = "Email subscriptions made easy"
|
13
13
|
spec.homepage = "https://github.com/ankane/mailkick"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mailkick
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,6 +66,7 @@ files:
|
|
66
66
|
- lib/mailkick/processor.rb
|
67
67
|
- lib/mailkick/service.rb
|
68
68
|
- lib/mailkick/service/mailchimp.rb
|
69
|
+
- lib/mailkick/service/mailgun.rb
|
69
70
|
- lib/mailkick/service/mandrill.rb
|
70
71
|
- lib/mailkick/service/sendgrid.rb
|
71
72
|
- lib/mailkick/version.rb
|
@@ -95,3 +96,4 @@ signing_key:
|
|
95
96
|
specification_version: 4
|
96
97
|
summary: Email subscriptions made easy
|
97
98
|
test_files: []
|
99
|
+
has_rdoc:
|