mail-notify 1.2.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c0bb3a1c360012ed7c00ce1544b93a7994fafc60e8a7df21d20542b1a7d9937f
4
- data.tar.gz: b36c42e947350e3c3e4b4ff9c3a8bf63ca94a270d71ca700c5fa3f5f52e839f5
3
+ metadata.gz: c412b0f242555ce3f351f10a14e854cdf32cb66198e3e3c269bef95f24f99e3c
4
+ data.tar.gz: 91c8452c20b65db1cb90f59b3158e70064890e58dfb2261545373f9489dea4c5
5
5
  SHA512:
6
- metadata.gz: d98056a429727f3738452fe35b1e1b929d5a28dfd733b3bffecc6618b25535138416289cda426f080e1a88e50643daf9e23b8b563a1aae8a3962435a8d3f819e
7
- data.tar.gz: 2264de8dd3ace229b47decc1605de243115207c57d3eb30073317d8ed26be57309d752564621eeb38720c1ff0cca5094df058e6ab979f46051e6ceaba8546ff3
6
+ metadata.gz: 8d37cc3ef9b1f522b9f0b08d691e422b587bb5dc5d9392d1464fe7ba851607df1578d2234c02cde82f067c30e921710b208a8de126a516220ddb4046811fe125
7
+ data.tar.gz: feee1c413377caf9b55aec343f60c0b5090d2c354755c6868258f7aa4979a8be028c5da555c6432611982cb0bc33499e2a58439b0ece3ca170f3cdbad739a489
@@ -0,0 +1,21 @@
1
+ name: CI
2
+ on: [push, pull_request]
3
+ jobs:
4
+ lint-and-test:
5
+ name: Linting, specs and coverage
6
+ runs-on: ubuntu-latest
7
+ steps:
8
+ - name: Checkout code
9
+ uses: actions/checkout@v4
10
+ - name: Set up Ruby
11
+ uses: ruby/setup-ruby@v1
12
+ with:
13
+ bundler-cache: true
14
+ - name: Run linting
15
+ run: bin/standardrb
16
+ - name: Run specs
17
+ run: bin/rspec
18
+ - name: Run coverage report
19
+ uses: coverallsapp/github-action@v2
20
+ with:
21
+ fail-on-error: false
@@ -9,7 +9,7 @@ jobs:
9
9
  build:
10
10
  runs-on: ubuntu-latest
11
11
  steps:
12
- - uses: actions/checkout@v3
12
+ - uses: actions/checkout@v4
13
13
  - name: Set up Ruby
14
14
  uses: ruby/setup-ruby@v1
15
15
  - name: Setup Rubygems
@@ -0,0 +1,231 @@
1
+ name: Rails integration tests
2
+
3
+ on:
4
+ pull_request:
5
+ push:
6
+ branches:
7
+ - v2
8
+
9
+ jobs:
10
+ build-rails-5:
11
+ name: Build Rails 5
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ -
15
+ name: Checkout
16
+ uses: actions/checkout@v4
17
+ -
18
+ name: Set up Docker Buildx
19
+ uses: docker/setup-buildx-action@v3
20
+ -
21
+ name: Build and cache
22
+ uses: docker/build-push-action@v5
23
+ with:
24
+ context: .
25
+ file: ./Dockerfile
26
+ build-args: |
27
+ RAILS_VERSION=5.2.8.1
28
+ MAIL_NOTIFY_BRANCH=${{ github.ref }}
29
+ push: false
30
+ tags: mail-notify-integration-rails-5:latest
31
+ outputs: type=docker, dest=/tmp/rails-5-image.tar
32
+ cache-from: type=gha
33
+ cache-to: type=gha,mode=min
34
+ - name: Upload artifact
35
+ uses: actions/upload-artifact@v4
36
+ with:
37
+ name: rails-5-image
38
+ path: /tmp/rails-5-image.tar
39
+
40
+ rails-5-previews:
41
+ name: Rails 5 mailer previews
42
+ runs-on: ubuntu-latest
43
+ needs: build-rails-5
44
+ steps:
45
+ -
46
+ name: Download image
47
+ uses: actions/download-artifact@v4
48
+ with:
49
+ name: rails-5-image
50
+ path: /tmp
51
+ -
52
+ name: Load image
53
+ run: docker load --input /tmp/rails-5-image.tar
54
+ -
55
+ name: Run integration tests
56
+ env:
57
+ NOTIFY_API_KEY: ${{ secrets.NOTIFY_API_KEY }}
58
+ run: |
59
+ docker run --rm -e "NOTIFY_API_KEY=$NOTIFY_API_KEY" \
60
+ mail-notify-integration-rails-5:latest bin/rails test:system
61
+
62
+
63
+ rails-5-sending:
64
+ name: Rails 5 sending
65
+ runs-on: ubuntu-latest
66
+ needs: build-rails-5
67
+ steps:
68
+ -
69
+ name: Download image
70
+ uses: actions/download-artifact@v4
71
+ with:
72
+ name: rails-5-image
73
+ path: /tmp
74
+ -
75
+ name: Load image
76
+ run: docker load --input /tmp/rails-5-image.tar
77
+ -
78
+ name: Run integration tests
79
+ env:
80
+ NOTIFY_API_KEY: ${{ secrets.NOTIFY_API_KEY }}
81
+ run: |
82
+ docker run --rm -e "NOTIFY_API_KEY=$NOTIFY_API_KEY" \
83
+ mail-notify-integration-rails-5:latest bin/rails test
84
+
85
+ build-rails-6:
86
+ name: Build Rails 6
87
+ runs-on: ubuntu-latest
88
+ steps:
89
+ -
90
+ name: Checkout
91
+ uses: actions/checkout@v4
92
+ -
93
+ name: Set up Docker Buildx
94
+ uses: docker/setup-buildx-action@v3
95
+ -
96
+ name: Build and cache
97
+ uses: docker/build-push-action@v5
98
+ with:
99
+ context: .
100
+ file: ./Dockerfile
101
+ build-args: |
102
+ RAILS_VERSION=6.1.7.6
103
+ MAIL_NOTIFY_BRANCH=${{ github.ref }}
104
+ push: false
105
+ tags: mail-notify-integration-rails-6:latest
106
+ outputs: type=docker, dest=/tmp/rails-6-image.tar
107
+ cache-from: type=gha
108
+ cache-to: type=gha,mode=min
109
+ - name: Upload artifact
110
+ uses: actions/upload-artifact@v4
111
+ with:
112
+ name: rails-6-image
113
+ path: /tmp/rails-6-image.tar
114
+
115
+ rails-6-previews:
116
+ name: Rails 6 mailer previews
117
+ runs-on: ubuntu-latest
118
+ needs: build-rails-6
119
+ steps:
120
+ -
121
+ name: Download image
122
+ uses: actions/download-artifact@v4
123
+ with:
124
+ name: rails-6-image
125
+ path: /tmp
126
+ -
127
+ name: Load image
128
+ run: docker load --input /tmp/rails-6-image.tar
129
+ -
130
+ name: Run integration tests
131
+ env:
132
+ NOTIFY_API_KEY: ${{ secrets.NOTIFY_API_KEY }}
133
+ run: |
134
+ docker run --rm -e "NOTIFY_API_KEY=$NOTIFY_API_KEY" \
135
+ mail-notify-integration-rails-6:latest bin/rails test:system
136
+
137
+ rails-6-sending:
138
+ name: Rails 6 sending
139
+ runs-on: ubuntu-latest
140
+ needs: build-rails-6
141
+ steps:
142
+ -
143
+ name: Download image
144
+ uses: actions/download-artifact@v4
145
+ with:
146
+ name: rails-6-image
147
+ path: /tmp
148
+ -
149
+ name: Load image
150
+ run: docker load --input /tmp/rails-6-image.tar
151
+ -
152
+ name: Run integration tests
153
+ env:
154
+ NOTIFY_API_KEY: ${{ secrets.NOTIFY_API_KEY }}
155
+ run: |
156
+ docker run --rm -e "NOTIFY_API_KEY=$NOTIFY_API_KEY" \
157
+ mail-notify-integration-rails-6:latest bin/rails test
158
+
159
+ build-rails-7:
160
+ name: Build Rails 7
161
+ runs-on: ubuntu-latest
162
+ steps:
163
+ -
164
+ name: Checkout
165
+ uses: actions/checkout@v4
166
+ -
167
+ name: Set up Docker Buildx
168
+ uses: docker/setup-buildx-action@v3
169
+ -
170
+ name: Build and cache
171
+ uses: docker/build-push-action@v5
172
+ with:
173
+ context: .
174
+ file: ./Dockerfile
175
+ build-args: |
176
+ RAILS_VERSION=7.1.3.2
177
+ MAIL_NOTIFY_BRANCH=${{ github.ref }}
178
+ push: false
179
+ tags: mail-notify-integration-rails-7:latest
180
+ outputs: type=docker, dest=/tmp/rails-7-image.tar
181
+ cache-from: type=gha
182
+ cache-to: type=gha,mode=min
183
+ - name: Upload artifact
184
+ uses: actions/upload-artifact@v4
185
+ with:
186
+ name: rails-7-image
187
+ path: /tmp/rails-7-image.tar
188
+
189
+ rails-7-previews:
190
+ name: Rails 7 mailer previews
191
+ runs-on: ubuntu-latest
192
+ needs: build-rails-7
193
+ steps:
194
+ -
195
+ name: Download image
196
+ uses: actions/download-artifact@v4
197
+ with:
198
+ name: rails-7-image
199
+ path: /tmp
200
+ -
201
+ name: Load image
202
+ run: docker load --input /tmp/rails-7-image.tar
203
+ -
204
+ name: Run integration tests
205
+ env:
206
+ NOTIFY_API_KEY: ${{ secrets.NOTIFY_API_KEY }}
207
+ run: |
208
+ docker run --rm -e "NOTIFY_API_KEY=$NOTIFY_API_KEY" \
209
+ mail-notify-integration-rails-7:latest bin/rails test:system
210
+
211
+ rails-7-sending:
212
+ name: Rails 7 sending
213
+ runs-on: ubuntu-latest
214
+ needs: build-rails-7
215
+ steps:
216
+ -
217
+ name: Download image
218
+ uses: actions/download-artifact@v4
219
+ with:
220
+ name: rails-7-image
221
+ path: /tmp
222
+ -
223
+ name: Load image
224
+ run: docker load --input /tmp/rails-7-image.tar
225
+ -
226
+ name: Run integration tests
227
+ env:
228
+ NOTIFY_API_KEY: ${{ secrets.NOTIFY_API_KEY }}
229
+ run: |
230
+ docker run --rm -e "NOTIFY_API_KEY=$NOTIFY_API_KEY" \
231
+ mail-notify-integration-rails-7:latest bin/rails test
data/.gitignore CHANGED
@@ -11,5 +11,9 @@
11
11
  .rspec_status
12
12
  .DS_Store
13
13
  /Gemfile.lock
14
- /spec/dummy/log/test.log
15
14
  /vendor
15
+
16
+ # The 'dummy' app used in the test suite
17
+ /spec/dummy/log/*
18
+ /spec/dummy/tmp/*
19
+ /spec/dummy/db/*
data/CHANGELOG.md CHANGED
@@ -6,6 +6,17 @@ The format is based on [Keep a Changelog]
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [2.0.0] - 2024-04-01
10
+
11
+ - Version 2.0.0 rewrites most of the gem, without altering the API
12
+ - The gem no longer prepends code in ActionMailer
13
+ - Previews are now 100% supported in Rails, but will require a Notify API key
14
+ - The preview layout has been updated and uses the Tudor Crown
15
+ - This version fixes a bug that meant not all Rails preview functionality would
16
+ work
17
+ - This version fixes a bug that meant no Rails preview functionality would work
18
+ from version 7.1.0 onwards
19
+
9
20
  ## [1.2.0] - 2023-04-28
10
21
 
11
22
  - Requiring Ruby 2.7.8
@@ -71,7 +82,10 @@ The format is based on [Keep a Changelog]
71
82
 
72
83
  - Initial release
73
84
 
74
- [unreleased]: https://github.com/DFE-Digital/dfe-teachers-payment-service/compare/1.0.3...HEAD
85
+ [unreleased]: https://github.com/dxw/mail-notify/compare/2.0.0...HEAD
86
+ [2.0.0]: https://github.com/dxw/mail-notify/compare/1.2.0...2.0.0
87
+ [1.2.0]: https://github.com/dxw/mail-notify/compare/1.1.0...1.2.0
88
+ [1.1.0]: https://github.com/dxw/mail-notify/compare/1.0.5...1.1.0
75
89
  [1.0.5]: https://github.com/dxw/mail-notify/compare/1.0.4...1.0.5
76
90
  [1.0.4]: https://github.com/dxw/mail-notify/compare/1.0.3...1.0.4
77
91
  [1.0.3]: https://github.com/dxw/mail-notify/compare/1.0.2...1.0.3
data/Dockerfile ADDED
@@ -0,0 +1,68 @@
1
+ # We want to support older Rubies
2
+ ARG RUBY_VERSION=2.7.8
3
+ FROM registry.docker.com/library/ruby:$RUBY_VERSION-slim as base
4
+
5
+ # Rails app lives here
6
+ WORKDIR /rails
7
+
8
+ # Build stage
9
+ FROM base as build
10
+
11
+ # Install packages needed to build gems and node modules
12
+ RUN apt-get update -qq && \
13
+ apt-get install --no-install-recommends -y build-essential curl git
14
+
15
+ # Install Nokigiri version that supports Ruby 2.7.8
16
+ RUN gem install nokogiri -v 1.15.6
17
+
18
+ # Install Rails
19
+ ARG RAILS_VERSION=7.1.3.2
20
+ RUN gem install rails -v ${RAILS_VERSION}
21
+
22
+ # create empty Rails application, we don't need ActiveRecord or JavaScript
23
+ RUN rails new mail-notify-integration --skip-active-record --skip-javascript
24
+
25
+ WORKDIR mail-notify-integration
26
+
27
+ # install the gems into the bundle
28
+ RUN bundle install
29
+
30
+ # remove gems that will not work in Rails 5.2.8.1
31
+ RUN if [ "${RAILS_VERSION}" = "5.2.8.1" ]; then bundle remove selenium-webdriver chromedriver-helper; fi
32
+
33
+ # Final stage for app image
34
+ FROM base
35
+
36
+ # Install packages needed for running the tests
37
+ RUN apt-get update -qq && \
38
+ apt-get install --no-install-recommends -y curl git && \
39
+ rm -rf /var/lib/apt/lists /var/cache/apt/archives
40
+
41
+ # Copy built artifacts: gems, application
42
+ COPY --from=build /usr/local/bundle /usr/local/bundle
43
+ COPY --from=build /rails /rails
44
+
45
+ WORKDIR /rails/mail-notify-integration
46
+
47
+ # add Mail Notify to the Gemfile
48
+ ARG MAIL_NOTIFY_BRANCH=v2
49
+ RUN echo "gem 'mail-notify', git: 'https://github.com/dxw/mail-notify', branch: '${MAIL_NOTIFY_BRANCH}'" >> Gemfile
50
+
51
+ # install the mail-notify gem, we do this here to keep the last container layer small to help caching
52
+ RUN bundle install
53
+
54
+ # Copy over intergration test files
55
+ COPY test/mailers/ test/mailers/
56
+ COPY test/system/ test/system/
57
+ COPY test/integration test/integration
58
+ COPY test/application_system_test_case.rb /test/application_system_test_case.rb
59
+ COPY test/app/mailers/ app/mailers/
60
+ COPY test/app/views/ app/views/
61
+
62
+ # Setup the test environment
63
+ RUN echo "Rails.application.config.action_mailer.show_previews = true" >> config/environments/test.rb
64
+ RUN echo "Rails.application.config.action_mailer.delivery_method = :notify" >>config/environments/test.rb
65
+ RUN echo "Rails.application.config.action_mailer.notify_settings = {api_key: ENV['NOTIFY_API_KEY']}" >> config/environments/test.rb
66
+
67
+ # Run the system tests
68
+ CMD ["./bin/rails", "test:system"]
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
- [![Build Status](https://github.com/dxw/mail-notify/workflows/Build/badge.svg)](https://github.com/dxw/mail-notify/actions)
2
- [![Coverage Status](https://img.shields.io/coveralls/github/pezholio/mail-notify.svg?style=flat-square)](https://coveralls.io/github/pezholio/mail-notify)
1
+ [![Build status](https://github.com/dxw/mail-notify/actions/workflows/ci.yml/badge.svg)](https://github.com/dxw/mail-notify/actions/workflows/ci.yml)
2
+ [![Coverage status](https://coveralls.io/repos/github/dxw/mail-notify/badge.svg?branch=fix-coveralls)](https://coveralls.io/github/dxw/mail-notify?branch=fix-coveralls)
3
3
  [![Gem Version](http://img.shields.io/gem/v/mail-notify.svg?style=flat-square)](https://rubygems.org/gems/mail-notify)
4
4
  [![License](http://img.shields.io/:license-mit-blue.svg)](https://mit-license.org/)
5
5
 
data/Rakefile CHANGED
@@ -1,12 +1,7 @@
1
- # frozen_string_literal: true
2
-
3
1
  require "bundler/gem_tasks"
4
2
  require "rspec/core/rake_task"
5
3
  require "standard/rake"
6
- require "coveralls/rake/task"
7
-
8
- Coveralls::RakeTask.new
9
4
 
10
5
  RSpec::Core::RakeTask.new(:spec)
11
6
 
12
- task default: %i[standard spec coveralls:push]
7
+ task default: %i[standard spec]
@@ -1,14 +1,14 @@
1
- <%# Copied from GOV.UK Notify: https://raw.githubusercontent.com/alphagov/notifications-utils/d69de041d1be7b826e7d9cc56450e157ad361799/notifications_utils/jinja_templates/email_template.jinja2 %>
2
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
1
+ <!-- Template sourced from https://github.com/alphagov/notifications-utils/blob/main/notifications_utils/jinja_templates/email_template.jinja2 -->
2
+ <!DOCTYPE html>
3
+ <html lang="en">
4
4
 
5
5
  <head>
6
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
7
- <meta content="telephone=no" name="format-detection" /> <!-- need to add formatting for real phone numbers -->
8
- <meta name="viewport" content="width=device-width" />
9
- <title>Page title</title>
6
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
7
+ <meta content="telephone=no" name="format-detection"> <!-- need to add formatting for real phone numbers -->
8
+ <meta name="viewport" content="width=device-width">
9
+ <title>{{ subject }}</title>
10
10
 
11
- <style type="text/css">
11
+ <style>
12
12
  @media only screen and (min-device-width: 581px) {
13
13
  .content {
14
14
  width: 580px !important;
@@ -19,7 +19,7 @@
19
19
  </style>
20
20
 
21
21
  <!--[if gte mso 9]>
22
- <style type="text/css">
22
+ <style>
23
23
  li {
24
24
  margin-left: 4px !important;
25
25
  }
@@ -33,8 +33,7 @@
33
33
  </head>
34
34
 
35
35
  <body style="font-family: Helvetica, Arial, sans-serif;font-size: 16px;margin: 0;color:#0b0c0c;">
36
-
37
- <span style="display: none;font-size: 1px;color: #fff; max-height: 0;"></span>
36
+ <span style="display: none;font-size: 1px;color: #fff; max-height: 0;" hidden>{{ preheader }}…</span>
38
37
  <table role="presentation" width="100%" style="border-collapse: collapse;min-width: 100%;width: 100% !important;" cellpadding="0" cellspacing="0" border="0">
39
38
  <tr>
40
39
  <td width="100%" height="53" bgcolor="#0b0c0c">
@@ -51,20 +50,20 @@
51
50
  <tr>
52
51
  <td style="padding-left: 10px">
53
52
  <img
54
- src="https://static.notifications.service.gov.uk/images/gov.uk_logotype_crown.png"
55
- alt=" "
53
+ src="https://static.notifications.service.gov.uk/images/govuk-logotype-tudor-crown.png"
54
+ alt=""
56
55
  height="32"
57
56
  border="0"
58
- style="Margin-top: 4px;"
59
- />
57
+ style="Margin-top: 2px;"
58
+ >
60
59
  </td>
61
- <td style="font-size: 28px; line-height: 1.315789474; Margin-top: 4px; padding-left: 10px;">
60
+ <td style="font-size: 28px; line-height: 1.315789474; Margin-top: 4px; padding-left: 8px;">
62
61
  <span style="
63
62
  font-family: Helvetica, Arial, sans-serif;
64
63
  font-weight: 700;
65
64
  color: #ffffff;
66
65
  text-decoration: none;
67
- vertical-align:top;
66
+ vertical-align:middle;
68
67
  display: inline-block;
69
68
  ">GOV.UK</span>
70
69
  </td>
@@ -102,7 +101,7 @@
102
101
  <![endif]-->
103
102
  <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="border-collapse: collapse;">
104
103
  <tr>
105
- <td bgcolor="#005EA5" width="100%" height="10"></td>
104
+ <td bgcolor="#1D70B8" width="100%" height="10"></td>
106
105
  </tr>
107
106
  </table>
108
107
  <!--[if (gte mso 9)|(IE)]>
@@ -114,7 +113,6 @@
114
113
  <td width="10" valign="middle" height="10"></td>
115
114
  </tr>
116
115
  </table>
117
-
118
116
  <table
119
117
  role="presentation"
120
118
  class="content"
@@ -126,27 +124,27 @@
126
124
  width="100%"
127
125
  >
128
126
  <tr>
129
- <td height="30"><br /></td>
127
+ <td height="30"><br></td>
130
128
  </tr>
131
129
  <tr>
132
- <td width="10" valign="middle"><br /></td>
130
+ <td width="10" valign="middle"><br></td>
133
131
  <td style="font-family: Helvetica, Arial, sans-serif; font-size: 19px; line-height: 1.315789474; max-width: 560px;">
134
132
  <!--[if (gte mso 9)|(IE)]>
135
133
  <table role="presentation" width="560" align="center" cellpadding="0" cellspacing="0" border="0" style="border-collapse: collapse;width: 560px;">
136
134
  <tr>
137
135
  <td style="font-family: Helvetica, Arial, sans-serif; font-size: 19px; line-height: 1.315789474;">
138
- <![endif]-->
139
- <%= yield %>
136
+ <![endif]-->
137
+ <%= yield %>
140
138
  <!--[if (gte mso 9)|(IE)]>
141
139
  </td>
142
140
  </tr>
143
141
  </table>
144
142
  <![endif]-->
145
143
  </td>
146
- <td width="10" valign="middle"><br /></td>
144
+ <td width="10" valign="middle"><br></td>
147
145
  </tr>
148
146
  <tr>
149
- <td height="30"><br /></td>
147
+ <td height="30"><br></td>
150
148
  </tr>
151
149
  </table>
152
150
  </body>
data/bin/console CHANGED
@@ -2,14 +2,9 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'bundler/setup'
5
+ require 'action_mailer'
6
+ require 'action_controller'
5
7
  require 'mail/notify'
8
+ require 'pry'
6
9
 
7
- # You can add fixtures and/or initialization code here to make experimenting
8
- # with your gem easier. You can also use a different console, if you like.
9
-
10
- # (If you use this, don't forget to add pry to your Gemfile!)
11
- # require "pry"
12
- # Pry.start
13
-
14
- require 'irb'
15
- IRB.start(__FILE__)
10
+ Pry.start
data/bin/rspec ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rspec' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
12
+
13
+ bundle_binstub = File.expand_path("bundle", __dir__)
14
+
15
+ if File.file?(bundle_binstub)
16
+ if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
17
+ load(bundle_binstub)
18
+ else
19
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
20
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
21
+ end
22
+ end
23
+
24
+ require "rubygems"
25
+ require "bundler/setup"
26
+
27
+ load Gem.bin_path("rspec-core", "rspec")
data/bin/standardrb ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'standardrb' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
12
+
13
+ bundle_binstub = File.expand_path("bundle", __dir__)
14
+
15
+ if File.file?(bundle_binstub)
16
+ if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
17
+ load(bundle_binstub)
18
+ else
19
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
20
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
21
+ end
22
+ end
23
+
24
+ require "rubygems"
25
+ require "bundler/setup"
26
+
27
+ load Gem.bin_path("standard", "standardrb")
@@ -6,20 +6,28 @@ module Mail
6
6
  attr_accessor :settings, :response
7
7
 
8
8
  def initialize(settings)
9
- raise ArgumentError, "You must specify an API key" if settings[:api_key].blank?
9
+ raise ArgumentError, "You must specify a Notify API key" if settings[:api_key].blank?
10
10
 
11
11
  @settings = settings
12
12
  end
13
13
 
14
- def deliver!(mail)
15
- @mail = mail
16
- @personalisation = Personalisation.new(mail)
17
- send_email
14
+ def deliver!(message)
15
+ params = {
16
+ template_id: message.template_id,
17
+ email_address: message.to.first,
18
+ personalisation: message.personalisation,
19
+ email_reply_to_id: message.reply_to_id,
20
+ reference: message.reference
21
+ }
22
+
23
+ client.send_email(params.compact)
18
24
  end
19
25
 
20
- def preview(mail)
21
- personalisation = Personalisation.new(mail).to_h
22
- template_id = mail[:template_id].to_s
26
+ def preview(message)
27
+ template_id = message.template_id
28
+ personalisation = message.personalisation
29
+
30
+ Rails.logger.info("Getting Notify preview for template id #{template_id}")
23
31
  client.generate_template_preview(template_id, personalisation: personalisation)
24
32
  end
25
33
 
@@ -28,24 +36,6 @@ module Mail
28
36
  def client
29
37
  @client ||= Notifications::Client.new(@settings[:api_key], @settings[:base_url])
30
38
  end
31
-
32
- def email_params
33
- {
34
- email_address: @mail.to.first,
35
- template_id: @mail[:template_id].to_s,
36
- personalisation: @personalisation.to_h,
37
- email_reply_to_id: optional_param(:reply_to_id),
38
- reference: optional_param(:reference)
39
- }
40
- end
41
-
42
- def optional_param(name)
43
- @mail[name].presence&.to_s
44
- end
45
-
46
- def send_email
47
- @response = client.send_email(email_params.compact)
48
- end
49
39
  end
50
40
  end
51
41
  end