mail-notify 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +5 -3
- data/Gemfile.lock +1 -1
- data/README.md +34 -15
- data/lib/mail/notify.rb +2 -0
- data/lib/mail/notify/delivery_method.rb +7 -8
- data/lib/mail/notify/mailer.rb +15 -0
- data/lib/mail/notify/personalisation.rb +26 -0
- data/lib/mail/notify/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a39b418b67958ee80a979be7f33d0367c9b122914d3640bfc65e59db8fd6ba8
|
4
|
+
data.tar.gz: 48fe8389d949853835b6f4cba7510cb1f2aea18c47899bb56bb2e52ddcc17eb4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04e90ef052082fb609bd0e5ca3b680df6794d05a21b133c2ee268d4292ae1175eb35c7e2aaaff4085317a74ad413e06d3f7edb072d8f7c6e1e4b715d10582129
|
7
|
+
data.tar.gz: 8a874ac8124e9a1126d887fc5ba8d543ac999a30fa26c6ab3703c1f2e9a56aa6e6861b4c495f7fc7e64b7f523dad010d54b5e8353019968d00d9b7133f82c55c
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -20,8 +20,7 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
$ gem install mail-notify
|
22
22
|
|
23
|
-
Then, add the following to your `config/environments/*.rb` (where * is `test`, `development`, `production` or
|
24
|
-
whatever other environment(s) you have) file(s):
|
23
|
+
Then, add the following to your `config/environments/*.rb` (where * is `test`, `development`, `production` or whatever other environment(s) you have) file(s):
|
25
24
|
|
26
25
|
```ruby
|
27
26
|
config.action_mailer.delivery_method = :notify
|
@@ -30,34 +29,54 @@ config.action_mailer.notify_settings = {
|
|
30
29
|
}
|
31
30
|
```
|
32
31
|
|
33
|
-
|
32
|
+
### Mailers
|
34
33
|
|
35
|
-
|
36
|
-
in the subject line, and a `((body))` variable in the body field, as below:
|
34
|
+
There are two options for using `Mail::Notify`, either templating in Rails with a view, or templating in Notify. Whichever way you choose, you'll need your mailers to inherit from `Mail::Notify::Mailer` like so:
|
37
35
|
|
38
|
-
|
36
|
+
```ruby
|
37
|
+
class MyMailer < Mail::Notify::Mailer
|
38
|
+
end
|
39
|
+
```
|
39
40
|
|
40
|
-
|
41
|
+
#### With a view
|
41
42
|
|
42
|
-
|
43
|
+
Out of the box, Notify offers support for templating, with some rudimentary logic included. If you'd rather have your templating logic included with your source code for ease of access, or you want to do some more complex logic that's not supported by Notify, you can template your mailer views in erb.
|
44
|
+
|
45
|
+
For this to work with Notify, you'll need a very simple template set up in Notify, with a `((subject))` variable in the subject line, and a `((body))` variable in the body field, as below:
|
46
|
+
|
47
|
+
![Example screenshot](docs/screenshot.png)
|
43
48
|
|
44
|
-
|
49
|
+
Next, in your mailer you'll need to call `view_mail` with the first parameter being the ID of the notify template, followed by a hash of email headers e.g:
|
45
50
|
|
46
51
|
```ruby
|
47
|
-
class MyMailer <
|
52
|
+
class MyMailer < Mail::Notify::Mailer
|
48
53
|
def send_email
|
49
|
-
|
54
|
+
notify_mail('YOUR_TEMPLATE_ID_GOES_HERE',
|
50
55
|
to: 'mail@somewhere.com',
|
51
|
-
subject: 'Subject line goes here'
|
52
|
-
template_id: 'YOUR_TEMPLATE_ID_GOES_HERE'
|
56
|
+
subject: 'Subject line goes here'
|
53
57
|
)
|
54
58
|
end
|
55
59
|
end
|
56
60
|
```
|
57
61
|
|
58
|
-
|
62
|
+
Your view can then be a simple `text.erb` file. You can add some markdown for headers, bullet points and links etc. These are handled in the same way as standard action_mailer views.
|
59
63
|
|
60
|
-
|
64
|
+
#### With Notify templating
|
65
|
+
|
66
|
+
You can also send your customisations in the more traditional way, and do your templating in Notify if you prefer. For this, you'll need to call `template_mail`, again with the first parameter being the ID of the template, and a hash of email headers, including your personalisations, e.g:
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
class MyMailer < Mail::Notify::Mailer
|
70
|
+
def send_email
|
71
|
+
template_mail('YOUR_TEMPLATE_ID_GOES_HERE',
|
72
|
+
to: 'mail@somewhere.com',
|
73
|
+
personalisations: {
|
74
|
+
foo: 'bar'
|
75
|
+
}
|
76
|
+
)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
```
|
61
80
|
|
62
81
|
## Development
|
63
82
|
|
data/lib/mail/notify.rb
CHANGED
@@ -10,7 +10,9 @@ module Mail
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def deliver!(mail)
|
13
|
-
|
13
|
+
@mail = mail
|
14
|
+
@personalisation = Personalisation.new(@mail)
|
15
|
+
initialize_params
|
14
16
|
send_email
|
15
17
|
end
|
16
18
|
|
@@ -20,14 +22,11 @@ module Mail
|
|
20
22
|
@client ||= Notifications::Client.new(@settings[:api_key])
|
21
23
|
end
|
22
24
|
|
23
|
-
def initialize_params
|
25
|
+
def initialize_params
|
24
26
|
@email_params = {
|
25
|
-
email_address: mail.to.first,
|
26
|
-
template_id: mail[:template_id].to_s,
|
27
|
-
personalisation:
|
28
|
-
body: mail.body.raw_source,
|
29
|
-
subject: mail.subject
|
30
|
-
}
|
27
|
+
email_address: @mail.to.first,
|
28
|
+
template_id: @mail[:template_id].to_s,
|
29
|
+
personalisation: @personalisation.to_h
|
31
30
|
}
|
32
31
|
end
|
33
32
|
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Mail
|
4
|
+
module Notify
|
5
|
+
class Mailer < ActionMailer::Base
|
6
|
+
def view_mail(template_id, headers)
|
7
|
+
mail(headers.merge(template_id: template_id))
|
8
|
+
end
|
9
|
+
|
10
|
+
def template_mail(template_id, headers)
|
11
|
+
mail(headers.merge(body: '', subject: '', template_id: template_id))
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Mail
|
4
|
+
module Notify
|
5
|
+
class Personalisation
|
6
|
+
def initialize(mail)
|
7
|
+
@body = mail.body.raw_source
|
8
|
+
@subject = mail.subject
|
9
|
+
@personalisation = mail[:personalisation]&.unparsed_value || {}
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_h
|
13
|
+
merged_options.reject { |_k, v| v.blank? }
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def merged_options
|
19
|
+
{
|
20
|
+
body: @body,
|
21
|
+
subject: @subject
|
22
|
+
}.merge(@personalisation)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/mail/notify/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mail-notify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stuart Harrison
|
@@ -148,6 +148,8 @@ files:
|
|
148
148
|
- docs/screenshot.png
|
149
149
|
- lib/mail/notify.rb
|
150
150
|
- lib/mail/notify/delivery_method.rb
|
151
|
+
- lib/mail/notify/mailer.rb
|
152
|
+
- lib/mail/notify/personalisation.rb
|
151
153
|
- lib/mail/notify/railtie.rb
|
152
154
|
- lib/mail/notify/version.rb
|
153
155
|
- mail-notify.gemspec
|