mailkick 0.4.2 → 0.4.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 00db7fdae2daa66b3d994ac64b34a084c385fb76d3dfa81d379955d4df0249d3
4
- data.tar.gz: f78fce2a60960fc4c821f788bee0458e28f2c005655b972cccc95078abda4952
3
+ metadata.gz: 5a3e1a782d63a1ad223871a87aab2875c73c1a7860f614801184d005113d4d82
4
+ data.tar.gz: 802fdb1f89e3ca6c25761bb61fd085b1936336ea5fd6bc6a020a1b79a21859c0
5
5
  SHA512:
6
- metadata.gz: ed17bf62b821fd7627152d62d02b572d304bbb6221032d76d07ab8c05afeab7304aa1ae2c12e35aa164ec0e081fac5580a00ec215a53ee7cbcffdfee5dc5afaf
7
- data.tar.gz: 05a745028f412d6d7c626bd9fa5a20ebd40acd77ee84893078878176ca3f30f37e263676119c29bf142f30c6d2e3963e35b297a9746fbfe1d76557f2a0d3bb8e
6
+ metadata.gz: e93ee8b3bcf05fa1536141e2f9ef639e30efd236eb9d280bb88bc7e234f6a6aa9a246eb91bd6aee188c74226e11cf0cdcb67e636ffafeb76f525f89096ec5eda
7
+ data.tar.gz: 23441f577b0f294a46f47e61cc66c994a319d1e3d89ff310bd26d997c5b6bdbd2270318fda74de96e588f7da58691c63d3c188853be382a41a3608803034435d
@@ -1,3 +1,7 @@
1
+ ## 0.4.3 (2020-11-01)
2
+
3
+ - Added support for AWS SES
4
+
1
5
  ## 0.4.2 (2020-04-06)
2
6
 
3
7
  - Added support for official SendGrid gem
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Mailkick
2
2
 
3
- Email subscriptions made easy
3
+ Email unsubscribes 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
@@ -91,6 +91,7 @@ Mailkick.fetch_opt_outs
91
91
 
92
92
  The following services are supported:
93
93
 
94
+ - [AWS SES](#aws-ses)
94
95
  - [Mailchimp](#mailchimp)
95
96
  - [Mailgun](#mailgun)
96
97
  - [Mandrill](#mandrill)
@@ -99,6 +100,16 @@ The following services are supported:
99
100
 
100
101
  Will gladly accept pull requests for others.
101
102
 
103
+ #### AWS SES
104
+
105
+ Add the gem
106
+
107
+ ```ruby
108
+ gem 'aws-sdk-sesv2'
109
+ ```
110
+
111
+ And [configure your AWS credentials](https://github.com/aws/aws-sdk-ruby#configuration). Requires `ses:ListSuppressedDestinations` permission.
112
+
102
113
  #### Mailchimp
103
114
 
104
115
  Add the gem
@@ -7,6 +7,7 @@ require "set"
7
7
  # modules
8
8
  require "mailkick/model"
9
9
  require "mailkick/service"
10
+ require "mailkick/service/aws_ses"
10
11
  require "mailkick/service/mailchimp"
11
12
  require "mailkick/service/mailgun"
12
13
  require "mailkick/service/mandrill"
@@ -65,17 +66,16 @@ module Mailkick
65
66
  def self.opt_outs(options = {})
66
67
  relation = Mailkick::OptOut.where(active: true)
67
68
 
68
- parts = []
69
- binds = []
69
+ contact_relation = Mailkick::OptOut.none
70
70
  if (email = options[:email])
71
- parts << "email = ?"
72
- binds << email
71
+ contact_relation = contact_relation.or(Mailkick::OptOut.where(email: email))
73
72
  end
74
73
  if (user = options[:user])
75
- parts << "(user_id = ? and user_type = ?)"
76
- binds.concat [user.id, user.class.name]
74
+ contact_relation = contact_relation.or(
75
+ Mailkick::OptOut.where("user_id = ? AND user_type = ?", user.id, user.class.name)
76
+ )
77
77
  end
78
- relation = relation.where(parts.join(" OR "), *binds) if parts.any?
78
+ relation = relation.merge(contact_relation) if email || user
79
79
 
80
80
  relation =
81
81
  if options[:list]
@@ -87,13 +87,15 @@ module Mailkick
87
87
  relation
88
88
  end
89
89
 
90
+ # TODO use keyword arguments
90
91
  def self.opted_out_emails(options = {})
91
- Set.new(opt_outs(options).where("email IS NOT NULL").uniq.pluck(:email))
92
+ Set.new(opt_outs(options).where.not(email: nil).distinct.pluck(:email))
92
93
  end
93
94
 
95
+ # TODO use keyword arguments
94
96
  # does not take into account emails
95
97
  def self.opted_out_users(options = {})
96
- Set.new(opt_outs(options).where("user_id IS NOT NULL").map(&:user))
98
+ Set.new(opt_outs(options).where.not(user_id: nil).map(&:user))
97
99
  end
98
100
 
99
101
  def self.message_verifier
@@ -0,0 +1,47 @@
1
+ # https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/SESV2/Client.html
2
+
3
+ module Mailkick
4
+ class Service
5
+ class AwsSes < Mailkick::Service
6
+ REASONS_MAP = {
7
+ "BOUNCE" => "bounce",
8
+ "COMPLAINT" => "spam"
9
+ }
10
+
11
+ def initialize(options = {})
12
+ @options = options
13
+ end
14
+
15
+ def opt_outs
16
+ response = client.list_suppressed_destinations({
17
+ reasons: ["BOUNCE", "COMPLAINT"],
18
+ # TODO make configurable
19
+ start_date: Time.now - (86400 * 365),
20
+ end_date: Time.now
21
+ })
22
+
23
+ opt_outs = []
24
+ response.each do |page|
25
+ page.suppressed_destination_summaries.each do |record|
26
+ opt_outs << {
27
+ email: record.email_address,
28
+ time: record.last_update_time,
29
+ reason: REASONS_MAP[record.reason]
30
+ }
31
+ end
32
+ end
33
+ opt_outs
34
+ end
35
+
36
+ def self.discoverable?
37
+ !!defined?(::Aws::SESV2::Client)
38
+ end
39
+
40
+ private
41
+
42
+ def client
43
+ @client ||= ::Aws::SESV2::Client.new
44
+ end
45
+ end
46
+ end
47
+ end
@@ -1,3 +1,3 @@
1
1
  module Mailkick
2
- VERSION = "0.4.2"
2
+ VERSION = "0.4.3"
3
3
  end
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.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-06 00:00:00.000000000 Z
11
+ date: 2020-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -178,7 +178,7 @@ dependencies:
178
178
  - - ">="
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0'
181
- description:
181
+ description:
182
182
  email: andrew@chartkick.com
183
183
  executables: []
184
184
  extensions: []
@@ -198,6 +198,7 @@ files:
198
198
  - lib/mailkick/engine.rb
199
199
  - lib/mailkick/model.rb
200
200
  - lib/mailkick/service.rb
201
+ - lib/mailkick/service/aws_ses.rb
201
202
  - lib/mailkick/service/mailchimp.rb
202
203
  - lib/mailkick/service/mailgun.rb
203
204
  - lib/mailkick/service/mandrill.rb
@@ -210,7 +211,7 @@ homepage: https://github.com/ankane/mailkick
210
211
  licenses:
211
212
  - MIT
212
213
  metadata: {}
213
- post_install_message:
214
+ post_install_message:
214
215
  rdoc_options: []
215
216
  require_paths:
216
217
  - lib
@@ -225,8 +226,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
225
226
  - !ruby/object:Gem::Version
226
227
  version: '0'
227
228
  requirements: []
228
- rubygems_version: 3.1.2
229
- signing_key:
229
+ rubygems_version: 3.1.4
230
+ signing_key:
230
231
  specification_version: 4
231
- summary: Email subscriptions made easy
232
+ summary: Email unsubscribes for Rails
232
233
  test_files: []