effective_postmark 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/mailers/concerns/effective_postmark_mailer.rb +6 -1
- data/app/models/concerns/effective_postmark_user.rb +9 -0
- data/app/models/effective/postmark_api.rb +33 -2
- data/lib/effective_postmark/version.rb +1 -1
- data/lib/effective_postmark.rb +4 -0
- data/lib/tasks/effective_postmark_tasks.rake +23 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c54904eee89796343bceb312989b4ac5396eaafbd300e60aac6d5f9574421494
|
4
|
+
data.tar.gz: 76956ccf6a60141ab891c5cd8f1959fb240b84de12d102d970425628dc3806b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b4a3721507412cee63854db7f40b266dc74d3e8624f9f8372dfb3f6f26f76cb2413507c9bf537ba4edb244124520d381e677175fc3b477ade6ad882a103aa2a
|
7
|
+
data.tar.gz: 0bb3550864a845eac196ac9c26cb6755a4c8ba347210a1882bbb28945ffde11e5a2b615ae2b9851ef9406b74a254edd59ece41c5fa40bd8ca96f6b8291114173
|
@@ -9,7 +9,7 @@ module EffectivePostmarkMailer
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
rescue_from(::StandardError, with: :effective_postmark_error)
|
12
|
+
#rescue_from(::StandardError, with: :effective_postmark_error)
|
13
13
|
rescue_from(::Postmark::InactiveRecipientError, with: :effective_postmark_inactive_recipient_error)
|
14
14
|
end
|
15
15
|
|
@@ -59,6 +59,11 @@ module EffectivePostmarkMailer
|
|
59
59
|
Rails.logger.info "\e[31m\e[1mEMAIL FAILED\e[0m\e[22m" # bold red
|
60
60
|
Rails.logger.info "#{exception.inspect}"
|
61
61
|
|
62
|
+
EffectiveLogger.error(exception.message) if defined?(EffectiveLogger)
|
63
|
+
ExceptionNotifier.notify_exception(exception) if defined?(ExceptionNotifier)
|
64
|
+
|
65
|
+
raise(exception) if Rails.env.test? || Rails.env.development?
|
66
|
+
|
62
67
|
true
|
63
68
|
end
|
64
69
|
|
@@ -38,6 +38,15 @@ module EffectivePostmarkUser
|
|
38
38
|
update_columns(email_delivery_error: 'Inactive Recipient', email_delivery_error_at: Time.zone.now)
|
39
39
|
end
|
40
40
|
|
41
|
+
# Assigned by the rake task effective_postmark:assign_email_delivery_errors
|
42
|
+
def postmark_suppression!(reason:, date:)
|
43
|
+
return if email_delivery_error.present? # If we already marked invalid, don't mark again
|
44
|
+
|
45
|
+
date = (Time.zone.parse(date) rescue Time.zone.now) if date.kind_of?(String)
|
46
|
+
|
47
|
+
update_columns(email_delivery_error: reason, email_delivery_error_at: date)
|
48
|
+
end
|
49
|
+
|
41
50
|
# Triggered by an admin to reactivate the email address
|
42
51
|
def postmark_reactivate!
|
43
52
|
# Make an API request to reactivate this user
|
@@ -9,6 +9,38 @@ module Effective
|
|
9
9
|
@client = ::Postmark::ApiClient.new(api_token)
|
10
10
|
end
|
11
11
|
|
12
|
+
# [ "outbound", "broadcast-stream" ]
|
13
|
+
def streams()
|
14
|
+
@streams ||= begin
|
15
|
+
client.get_message_streams
|
16
|
+
.select { |stream| ['Broadcasts', 'Transactional'].include?(stream[:message_stream_type]) }
|
17
|
+
.map { |stream| stream[:id] }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def suppressions()
|
22
|
+
streams()
|
23
|
+
.flat_map { |stream| client.dump_suppressions(stream) }
|
24
|
+
.uniq { |suppression| suppression[:email_address] }
|
25
|
+
end
|
26
|
+
|
27
|
+
# Called by rake effective_postmark:assign_email_delivery_errors
|
28
|
+
def assign_email_delivery_errors!(users)
|
29
|
+
raise('expected an effective_postmark_user klass') unless users.try(:effective_postmark_user?)
|
30
|
+
|
31
|
+
suppressions().each do |suppression|
|
32
|
+
email = suppression[:email_address].to_s.downcase.strip
|
33
|
+
next unless email.present?
|
34
|
+
|
35
|
+
user = users.find_for_database_authentication(email: email)
|
36
|
+
next unless user.present?
|
37
|
+
|
38
|
+
user.postmark_suppression!(reason: suppression[:suppression_reason], date: suppression[:created_at])
|
39
|
+
end
|
40
|
+
|
41
|
+
true
|
42
|
+
end
|
43
|
+
|
12
44
|
# EffectivePostmark.api.reactivate(email)
|
13
45
|
def reactivate(user)
|
14
46
|
raise('expected an effective_postmark_user') unless user.class.try(:effective_postmark_user?)
|
@@ -18,8 +50,7 @@ module Effective
|
|
18
50
|
|
19
51
|
# There are multiple streams. outbound / broadcast / inbound
|
20
52
|
begin
|
21
|
-
client.delete_suppressions(
|
22
|
-
client.delete_suppressions(:broadcast, emails)
|
53
|
+
streams().each { |stream| client.delete_suppressions(stream, emails) }
|
23
54
|
true
|
24
55
|
rescue => e
|
25
56
|
false
|
data/lib/effective_postmark.rb
CHANGED
@@ -1,2 +1,25 @@
|
|
1
1
|
namespace :effective_postmark do
|
2
|
+
desc 'Assign email delivery errors to postmark users from suppressions API'
|
3
|
+
task assign_email_delivery_errors: :environment do
|
4
|
+
table = ActiveRecord::Base.connection.table_exists?(:users)
|
5
|
+
blank_tenant = defined?(Tenant) && Tenant.current.blank?
|
6
|
+
|
7
|
+
if table && !blank_tenant && EffectivePostmark.api_present?
|
8
|
+
puts "Assigning postmark email delivery errors"
|
9
|
+
|
10
|
+
klass = User.all
|
11
|
+
raise("expected an effective_postmark_user User class") unless klass.try(:effective_postmark_user?)
|
12
|
+
|
13
|
+
api = EffectivePostmark.api
|
14
|
+
|
15
|
+
begin
|
16
|
+
api.assign_email_delivery_errors!(klass)
|
17
|
+
rescue StandardError => e
|
18
|
+
ExceptionNotifier.notify_exception(e) if defined?(ExceptionNotifier)
|
19
|
+
puts "Error with effective_postmark:assign_email_delivery_errors"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
puts 'All done'
|
24
|
+
end
|
2
25
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_postmark
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|