sendgrid-actionmailer 3.1.1 → 3.2.0

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: 68926bb0db0f0f622282b8429b3df0f86911ca0d72c0146bcaf181966130e290
4
- data.tar.gz: '048ca01e72420c6f88be723ada69126d31c831f300b0aa539f8f7d236e3c500f'
3
+ metadata.gz: bb577847afaccad306f73fa0c34b928298b8dda4de873f8d0459dd96f41bee34
4
+ data.tar.gz: 9e9fa4dc9d9301aa0473f90ce3c1ae683a91d4313945333c636fc302dcb0f624
5
5
  SHA512:
6
- metadata.gz: 5999a6b88c2eb27869872a42c0f7300198cb9870f20087a9c38c68909b0bdcd6a960d0adc2eb01dfa39c530ff6eabee727e0ad9762b19294d57be8fd26e598f0
7
- data.tar.gz: a26c201d0a9466684796371b82d2cb3d2aaad48efd1fc6a5c1ffd22b410bcdb71203379c498c8ae504653d0a2692206003ac3176ecfd32025e555fb38ebc0d2e
6
+ metadata.gz: f387f4d44937198fcbbad709ec316b27d0e8bbbbd87b997fbeb5fdb5ec6a26a8f1b72f226bbae55b6e23692711b6dabcce9ea6aa240c7789a55ca776a7761cdf
7
+ data.tar.gz: 309ea7246ece21e445746f2faab91ad30b6f37392da0db1c00ec51e4033362cee300b86e546ee2c6e6cd18d4b2012454fa50d2fee31d43dcf1f9b6ee50b5062f
@@ -0,0 +1,35 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Ruby
9
+
10
+ on:
11
+ push:
12
+ branches: [ master ]
13
+ pull_request:
14
+ branches: [ master ]
15
+
16
+ jobs:
17
+ test:
18
+
19
+ runs-on: ubuntu-latest
20
+ strategy:
21
+ matrix:
22
+ ruby-version: ['2.6', '2.7', '3.0']
23
+
24
+ steps:
25
+ - uses: actions/checkout@v2
26
+ - name: Set up Ruby
27
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
28
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
29
+ # uses: ruby/setup-ruby@v1
30
+ uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
31
+ with:
32
+ ruby-version: ${{ matrix.ruby-version }}
33
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
34
+ - name: Run tests
35
+ run: bundle exec rake
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Change Log
2
2
 
3
+ ## 3.2.0 - 2020-02-16
4
+ - #107 Feature/sendgrid api settings, expand settings/options to allow for other SendGrid::Api client settings
5
+ - #106 The SendGrid API simple error handling
6
+ - #105 Github Actions CI
7
+ - #102 Add http_options to configurable in mailer settings
8
+ - #101 Railtie should use ActiveSupport.on_load
9
+
3
10
  ## 3.1.1 - 2020-11-06
4
11
  - #92 globally configured mail_settings
5
12
  - #95 add_mail_settings - support global settings
@@ -14,13 +14,14 @@ module SendGridActionMailer
14
14
  raise_delivery_errors: false
15
15
  }.freeze
16
16
 
17
- attr_accessor :settings, :api_key
17
+ attr_accessor :settings, :options
18
18
 
19
19
  def initialize(params = {})
20
20
  self.settings = DEFAULTS.merge(params)
21
21
  end
22
22
 
23
23
  def deliver!(mail)
24
+ self.options = {}
24
25
  sendgrid_mail = Mail.new.tap do |m|
25
26
  m.from = to_email(mail.from)
26
27
  m.reply_to = to_email(mail.reply_to)
@@ -28,7 +29,7 @@ module SendGridActionMailer
28
29
  end
29
30
 
30
31
  add_personalizations(sendgrid_mail, mail)
31
- add_api_key(sendgrid_mail, mail)
32
+ add_options(sendgrid_mail, mail)
32
33
  add_content(sendgrid_mail, mail)
33
34
  add_send_options(sendgrid_mail, mail)
34
35
  add_mail_settings(sendgrid_mail, mail)
@@ -45,8 +46,14 @@ module SendGridActionMailer
45
46
 
46
47
  private
47
48
 
49
+ def client_options
50
+ options.dup
51
+ .select { |key, value| key.to_s.match(/(api_key|host|request_headers|version|impersonate_subuser)/) }
52
+ .merge(http_options: settings.fetch(:http_options, {}))
53
+ end
54
+
48
55
  def client
49
- @client = SendGrid::API.new(api_key: api_key).client
56
+ @client = SendGrid::API.new(**client_options).client
50
57
  end
51
58
 
52
59
  # type should be either :plain or :html
@@ -146,10 +153,10 @@ module SendGridActionMailer
146
153
  content_disp.disposition_type
147
154
  end
148
155
 
149
- def add_api_key(sendgrid_mail, mail)
150
- self.api_key = settings.fetch(:api_key)
151
- if mail['delivery-method-options'] && mail['delivery-method-options'].value.include?('api_key')
152
- self.api_key = mail['delivery-method-options'].unparsed_value['api_key']
156
+ def add_options(sendgrid_mail, mail)
157
+ self.options.merge!(**self.class.transform_keys(self.settings, &:to_sym))
158
+ if !!(mail['delivery-method-options'])
159
+ self.options.merge!(**self.class.transform_keys(mail['delivery-method-options'].unparsed_value , &:to_sym))
153
160
  end
154
161
  end
155
162
 
@@ -286,9 +293,7 @@ module SendGridActionMailer
286
293
  result = client.mail._('send').post(request_body: email.to_json) # ლ(ಠ益ಠლ) that API
287
294
 
288
295
  if result.status_code && result.status_code.start_with?('4')
289
- message = !(result.body.empty?) ? JSON.parse(result.body).fetch('errors').pop.fetch('message') : 'Sendgrid API Error'
290
- full_message = "Sendgrid delivery failed with #{result.status_code} #{message}"
291
-
296
+ full_message = "Sendgrid delivery failed with #{result.status_code}: #{result.body}"
292
297
  settings[:raise_delivery_errors] ? raise(SendgridDeliveryError, full_message) : warn(full_message)
293
298
  end
294
299
 
@@ -1,7 +1,9 @@
1
1
  module SendGridActionMailer
2
2
  class Railtie < Rails::Railtie
3
3
  initializer 'sendgrid_actionmailer.add_delivery_method', before: 'action_mailer.set_configs' do
4
- ActionMailer::Base.add_delivery_method(:sendgrid_actionmailer, SendGridActionMailer::DeliveryMethod)
4
+ ActiveSupport.on_load(:action_mailer) do
5
+ ActionMailer::Base.add_delivery_method(:sendgrid_actionmailer, SendGridActionMailer::DeliveryMethod)
6
+ end
5
7
  end
6
8
  end
7
9
  end
@@ -1,3 +1,3 @@
1
1
  module SendGridActionMailer
2
- VERSION = '3.1.1'.freeze
2
+ VERSION = '3.2.0'.freeze
3
3
  end
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
  spec.require_paths = ['lib']
21
21
 
22
22
  spec.add_dependency 'mail', '~> 2.7'
23
- spec.add_dependency 'sendgrid-ruby', '~> 6.0'
23
+ spec.add_dependency 'sendgrid-ruby', '~> 6.4'
24
24
 
25
25
  spec.add_development_dependency 'appraisal', '~> 2.1.0'
26
26
  spec.add_development_dependency 'bundler'
@@ -40,6 +40,11 @@ module SendGridActionMailer
40
40
  expect(m.settings[:api_key]).to eq('ABCDEFG')
41
41
  end
42
42
 
43
+ it 'has correct host' do
44
+ m = DeliveryMethod.new(host: 'example.com')
45
+ expect(m.settings[:host]).to eq('example.com')
46
+ end
47
+
43
48
  it 'default raise_delivery_errors' do
44
49
  m = DeliveryMethod.new()
45
50
  expect(m.settings[:raise_delivery_errors]).to eq(false)
@@ -64,6 +69,11 @@ module SendGridActionMailer
64
69
  m = DeliveryMethod.new(perform_send_request: false)
65
70
  expect(m.settings[:perform_send_request]).to eq(false)
66
71
  end
72
+
73
+ it 'sets http_options' do
74
+ m = DeliveryMethod.new(http_options: {open_timeout: 40})
75
+ expect(m.settings[:http_options]).to eq({open_timeout: 40})
76
+ end
67
77
  end
68
78
 
69
79
  describe '#deliver!' do
@@ -106,11 +116,11 @@ module SendGridActionMailer
106
116
  end
107
117
 
108
118
  it 'sets dynamic api_key, but should revert to default settings api_key' do
109
- expect(SendGrid::API).to receive(:new).with(api_key: 'key')
119
+ expect(SendGrid::API).to receive(:new).with(api_key: 'key', http_options: {})
110
120
  mailer.deliver!(default)
111
- expect(SendGrid::API).to receive(:new).with(api_key: 'test_key')
121
+ expect(SendGrid::API).to receive(:new).with(api_key: 'test_key', http_options: {})
112
122
  mailer.deliver!(mail)
113
- expect(SendGrid::API).to receive(:new).with(api_key: 'key')
123
+ expect(SendGrid::API).to receive(:new).with(api_key: 'key', http_options: {})
114
124
  mailer.deliver!(default)
115
125
  end
116
126
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sendgrid-actionmailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.1
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eddie Zaneski
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-11-06 00:00:00.000000000 Z
13
+ date: 2021-02-16 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: mail
@@ -32,14 +32,14 @@ dependencies:
32
32
  requirements:
33
33
  - - "~>"
34
34
  - !ruby/object:Gem::Version
35
- version: '6.0'
35
+ version: '6.4'
36
36
  type: :runtime
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
40
  - - "~>"
41
41
  - !ruby/object:Gem::Version
42
- version: '6.0'
42
+ version: '6.4'
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: appraisal
45
45
  requirement: !ruby/object:Gem::Requirement
@@ -119,9 +119,9 @@ executables: []
119
119
  extensions: []
120
120
  extra_rdoc_files: []
121
121
  files:
122
+ - ".github/workflows/ruby.yml"
122
123
  - ".gitignore"
123
124
  - ".rspec"
124
- - ".travis.yml"
125
125
  - Appraisals
126
126
  - CHANGELOG.md
127
127
  - Gemfile
data/.travis.yml DELETED
@@ -1,13 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.7.1
5
- - 2.6.5
6
- - 2.5.7
7
- - 2.4.9
8
- - 2.3.8
9
- before_install:
10
- - gem update --system
11
- - gem install bundler
12
- gemfile:
13
- - gemfiles/mail_2.7.gemfile