sendgrid_actionmailer_adapter 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sendgrid_actionmailer_adapter/configuration.rb +3 -1
- data/lib/sendgrid_actionmailer_adapter/converters/categories.rb +1 -0
- data/lib/sendgrid_actionmailer_adapter/converters/reply_to.rb +1 -0
- data/lib/sendgrid_actionmailer_adapter/converters/send_at.rb +1 -0
- data/lib/sendgrid_actionmailer_adapter/delivery_method.rb +32 -5
- data/lib/sendgrid_actionmailer_adapter/version.rb +1 -1
- metadata +22 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd86c4547fe8aa68707f63e6613531e67e0b8f9b08a454f2bb1d6c4977c2ebf3
|
4
|
+
data.tar.gz: 24d6b1d4aed6f1f359453e8686fec2cad0af806a9cad03b03624deb01798fa07
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea3939b006d894a1e29841fd26642f61ac56b3310ad97c7919c7e59d325d3b11e8d0ce6264e25ccb453ddc5078183f603f045f334a9760e4519fe2b12526131a
|
7
|
+
data.tar.gz: 4ffb01e435809c556efa5290e0bcc2881cd31770c9df4a79cb2b6494a08e49e9c842524e1cec5ff305f386c09abf8661a6179ca574cbc02439fcdc885675acb8
|
@@ -7,7 +7,7 @@ module SendGridActionMailerAdapter
|
|
7
7
|
|
8
8
|
class << self
|
9
9
|
attr_accessor :api_key, :host, :request_headers, :version, :retry_max_count,
|
10
|
-
:retry_wait_seconds, :return_response
|
10
|
+
:retry_wait_seconds, :return_response, :logger
|
11
11
|
|
12
12
|
# Set your configuration with block.
|
13
13
|
def configure
|
@@ -30,6 +30,7 @@ module SendGridActionMailerAdapter
|
|
30
30
|
wait_seconds: retry_wait_seconds || DEFAULT_RETRY_WAIT_SECONDS,
|
31
31
|
},
|
32
32
|
return_response: return_response,
|
33
|
+
logger: logger,
|
33
34
|
}.freeze
|
34
35
|
end
|
35
36
|
|
@@ -42,6 +43,7 @@ module SendGridActionMailerAdapter
|
|
42
43
|
self.retry_max_count = nil
|
43
44
|
self.retry_wait_seconds = nil
|
44
45
|
self.return_response = nil
|
46
|
+
self.logger = nil
|
45
47
|
@settings = nil
|
46
48
|
end
|
47
49
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'logger'
|
3
4
|
require 'sendgrid/client'
|
4
5
|
require_relative 'configuration'
|
5
6
|
require_relative 'converter'
|
@@ -22,6 +23,7 @@ module SendGridActionMailerAdapter
|
|
22
23
|
# @options settings [Integer, Float] :retry_wait_sec Wait seconds for next retry, Default is 1.
|
23
24
|
def initialize(settings)
|
24
25
|
@settings = ::SendGridActionMailerAdapter::Configuration.settings.merge(settings)
|
26
|
+
@logger = @settings[:logger] || ::Logger.new(nil)
|
25
27
|
end
|
26
28
|
|
27
29
|
# Deliver a mail via SendGrid Web API.
|
@@ -33,29 +35,54 @@ module SendGridActionMailerAdapter
|
|
33
35
|
# @raise [SendGridActionMailerAdapter::ApiError] when SendGrid Web API returns error response.
|
34
36
|
def deliver!(mail)
|
35
37
|
sendgrid_mail = ::SendGridActionMailerAdapter::Converter.to_sendgrid_mail(mail)
|
36
|
-
|
37
|
-
|
38
|
+
|
39
|
+
if mail[:remove_from_bounces]
|
40
|
+
remove_to_addrs_from_bounces(sendgrid_mail)
|
41
|
+
end
|
38
42
|
|
39
43
|
with_retry(@settings[:retry]) do
|
40
|
-
|
44
|
+
@logger.info("Calling sendMail API, #{sendgrid_mail.inspect}")
|
45
|
+
response = sendgrid_client.mail._('send').post(request_body: sendgrid_mail.to_json)
|
46
|
+
@logger.info("End calling sendMail API, status_code: #{response.status_code}")
|
41
47
|
handle_response!(response)
|
42
48
|
end
|
43
49
|
end
|
44
50
|
|
45
51
|
private
|
46
52
|
|
53
|
+
def sendgrid_client
|
54
|
+
@sendgrid_client ||= ::SendGrid::API.new(@settings[:sendgrid]).client
|
55
|
+
end
|
56
|
+
|
57
|
+
# @param [::SendGrid::Mail]
|
58
|
+
def remove_to_addrs_from_bounces(sendgrid_mail)
|
59
|
+
sendgrid_mail.personalizations.each do |personalization|
|
60
|
+
personalization['to'].each do |to|
|
61
|
+
@logger.info("Calling deleteBounce API, #{to}")
|
62
|
+
# success => 204, not_found => 404
|
63
|
+
sendgrid_client.suppression.bounces._(to['email']).delete
|
64
|
+
@logger.info('End calling deleteBounce API')
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
47
69
|
def with_retry(max_count:, wait_seconds:)
|
48
70
|
tryable_count = max_count + 1
|
49
71
|
begin
|
50
72
|
tryable_count -= 1
|
51
73
|
yield
|
52
|
-
rescue ::SendGridActionMailerAdapter::ApiClientError =>
|
74
|
+
rescue ::SendGridActionMailerAdapter::ApiClientError => e
|
75
|
+
@logger.error(e)
|
53
76
|
raise
|
54
|
-
rescue =>
|
77
|
+
rescue StandardError => e
|
55
78
|
if tryable_count > 0
|
79
|
+
@logger.warn("Retry mail sending, tryable_count: #{tryable_count}")
|
80
|
+
@logger.warn(e)
|
56
81
|
sleep(wait_seconds)
|
57
82
|
retry
|
58
83
|
end
|
84
|
+
@logger.error('Give up retrying')
|
85
|
+
@logger.error(e)
|
59
86
|
raise
|
60
87
|
end
|
61
88
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sendgrid_actionmailer_adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ryu39
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sendgrid-ruby
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '5.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: actionmailer
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
@@ -53,49 +53,49 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: mail
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0
|
61
|
+
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 0
|
68
|
+
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: rake
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: rspec
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
89
|
+
version: '3.0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - "
|
94
|
+
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
96
|
+
version: '3.0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: ryu39cop
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - ">="
|
@@ -109,7 +109,7 @@ dependencies:
|
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
112
|
+
name: webmock
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - ">="
|
@@ -163,8 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
163
163
|
- !ruby/object:Gem::Version
|
164
164
|
version: '0'
|
165
165
|
requirements: []
|
166
|
-
|
167
|
-
rubygems_version: 2.7.3
|
166
|
+
rubygems_version: 3.0.3
|
168
167
|
signing_key:
|
169
168
|
specification_version: 4
|
170
169
|
summary: A ActionMailer adapter using SendGrid Web API v3
|