sendgrid_actionmailer_adapter 0.2.0 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- 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/contents.rb +2 -1
- 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 +40 -6
- data/lib/sendgrid_actionmailer_adapter/version.rb +1 -1
- metadata +26 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d59836f5bb9a8cc47a2a4c45406d5ceb7c13798677676b5f8d04db5adbba15d3
|
4
|
+
data.tar.gz: 07bf50bf757fafa6d18c8848eac7b40e9789329c4aa0cfd2682726d83ee131bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38233870aeb4994d09dd2394e15a521f8fd2cc154b06e43de9d2b70b6301bb62bf5c7867d986cfb263a760c9c3cb09f00f273b72716ac8d01c93ec40f9809df2
|
7
|
+
data.tar.gz: 9c581f63f5ccad65c7881034b50b46ac415beff1225c70e5bdf8c2d8f89617195d44e86771d4d082bb674d86d9428999955af70b85e7f43db68fa5f1ab572089
|
@@ -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
|
@@ -9,7 +9,8 @@ module SendGridActionMailerAdapter
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def convert(mail)
|
12
|
-
|
12
|
+
contents = mail.body.multipart? ? mail.body.parts.select(&:text?) : [mail]
|
13
|
+
contents.map { |c| ::SendGrid::Content.new(type: c.mime_type, value: c.body.to_s) }
|
13
14
|
end
|
14
15
|
|
15
16
|
def assign_attributes(sendgrid_mail, value)
|
@@ -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,33 +35,65 @@ 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
|
-
body = sendgrid_mail.to_json
|
37
|
-
client = ::SendGrid::API.new(@settings[:sendgrid]).client.mail._('send')
|
38
38
|
|
39
|
-
|
40
|
-
|
39
|
+
if mail[:remove_from_bounces]
|
40
|
+
remove_to_addrs_from_bounces(sendgrid_mail)
|
41
|
+
end
|
42
|
+
|
43
|
+
with_retry(**@settings[:retry]) do
|
44
|
+
@logger.info("Calling sendMail API, #{extract_log_info(sendgrid_mail)}")
|
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
|
62
89
|
|
90
|
+
def extract_log_info(sendgrid_mail)
|
91
|
+
{
|
92
|
+
subject: sendgrid_mail.subject,
|
93
|
+
personalizations: sendgrid_mail.personalizations,
|
94
|
+
}
|
95
|
+
end
|
96
|
+
|
63
97
|
# @see https://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/errors.html
|
64
98
|
def handle_response!(response)
|
65
99
|
case response.status_code.to_i
|
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.2
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ryu39
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-03-09 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
|
- - ">="
|
@@ -148,7 +148,7 @@ homepage: https://github.com/ryu39/sendgrid_actionmailer_adapter
|
|
148
148
|
licenses:
|
149
149
|
- MIT
|
150
150
|
metadata: {}
|
151
|
-
post_install_message:
|
151
|
+
post_install_message:
|
152
152
|
rdoc_options: []
|
153
153
|
require_paths:
|
154
154
|
- lib
|
@@ -156,16 +156,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
156
156
|
requirements:
|
157
157
|
- - ">="
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version: '2.
|
159
|
+
version: '2.4'
|
160
160
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
161
161
|
requirements:
|
162
162
|
- - ">="
|
163
163
|
- !ruby/object:Gem::Version
|
164
164
|
version: '0'
|
165
165
|
requirements: []
|
166
|
-
|
167
|
-
|
168
|
-
signing_key:
|
166
|
+
rubygems_version: 3.2.3
|
167
|
+
signing_key:
|
169
168
|
specification_version: 4
|
170
169
|
summary: A ActionMailer adapter using SendGrid Web API v3
|
171
170
|
test_files: []
|