tolliver 2.0.0 → 2.0.1
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 +4 -4
- data/README.md +51 -3
- data/app/views/tolliver/notification_mailer/notify.html.erb +1 -1
- data/lib/tolliver.rb +16 -5
- data/lib/tolliver/mailers/notification_mailer.rb +2 -2
- data/lib/tolliver/services/methods/email.rb +14 -1
- data/lib/tolliver/services/methods/email/mailgun.rb +55 -0
- data/lib/tolliver/services/methods/email/smtp.rb +28 -0
- data/lib/tolliver/services/methods/sms.rb +5 -2
- data/lib/tolliver/services/methods/sms/plivo.rb +6 -7
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e7ab72e7ba150c2828de6e3f3defebf06f50bbf09495b9f3bafcc32d4858cf0
|
4
|
+
data.tar.gz: 4dd7b0a65c105f2f11fcf336675a515d41cac6cc278580fd24951891073b60dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c538087c0161c0968e4f2f4fa31c8ce6ad1a54ea1ee0b924b851f81aa537ed631c839cadb0e258b86a5ba24dee3affa2b5b6dc46983c1f5d16960b91cf562a4
|
7
|
+
data.tar.gz: 05fa597679610a2694f6397992040c4463b9bb9d9458e7f1193431e302c7e2446c67c096838273b5c4fcc42e714f0d53a61d0612abc3a114e6f1ab1b6af06eab
|
data/README.md
CHANGED
@@ -3,8 +3,8 @@ A long serving Junior Postman Tolliver Groat. With this gem you can create
|
|
3
3
|
notifications based on templates defined by the system administrator and
|
4
4
|
send it in a batch with different delivery methods:
|
5
5
|
|
6
|
-
- E-mail
|
7
|
-
- SMS
|
6
|
+
- E-mail with SMTP aor Mailgun provider
|
7
|
+
- SMS with Plivo provider
|
8
8
|
- Whatever custom delivery method
|
9
9
|
|
10
10
|
## Installation
|
@@ -20,13 +20,29 @@ Add database migrations to you application (you can modify DB structure accordin
|
|
20
20
|
$ rake tolliver:install:migrations
|
21
21
|
$ rake db:migrate
|
22
22
|
|
23
|
+
### Plivo support
|
24
|
+
|
25
|
+
Add gem to your Gemfile:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
gem 'plivo'
|
29
|
+
```
|
30
|
+
|
31
|
+
### Mailgun support
|
32
|
+
|
33
|
+
Add gem to your Gemfile:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
gem 'mailgun-ruby'
|
37
|
+
```
|
38
|
+
|
23
39
|
## Configuration
|
24
40
|
|
25
41
|
You can configure module through `config/initializers/tolliver.rb` file:
|
26
42
|
|
27
43
|
```ruby
|
28
44
|
Tolliver.setup do |config|
|
29
|
-
config.
|
45
|
+
config.email_sender = 'no-reply@domain.com'
|
30
46
|
config.delivery_methods = [
|
31
47
|
:email
|
32
48
|
]
|
@@ -42,11 +58,43 @@ Available options:
|
|
42
58
|
- notification_template_model
|
43
59
|
- email_sender
|
44
60
|
- email_sender_name
|
61
|
+
- email_provider
|
62
|
+
- email_provider_params
|
45
63
|
- sms_sender
|
46
64
|
- sms_provider
|
47
65
|
- sms_provider_params
|
48
66
|
- delivery_methods
|
49
67
|
|
68
|
+
### Plivo support
|
69
|
+
|
70
|
+
Set Plivo as SMS provider and add Plivo auth ID and token into Tolliver configuration file:
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
Tolliver.setup do |config|
|
74
|
+
...
|
75
|
+
config.sms_provider = :plivo
|
76
|
+
config.sms_provider_params = {
|
77
|
+
auth_id: 'secret',
|
78
|
+
auth_token: 'secret'
|
79
|
+
}
|
80
|
+
end
|
81
|
+
```
|
82
|
+
|
83
|
+
### Mailgun support
|
84
|
+
|
85
|
+
Set Mailgun as e-mail provider and add Mailgun API key and domain into Tolliver configuration file:
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
Tolliver.setup do |config|
|
89
|
+
...
|
90
|
+
config.email_provider = :mailgun
|
91
|
+
config.email_provider_params = {
|
92
|
+
api_key: 'key-secret',
|
93
|
+
domain: 'domain.tld'
|
94
|
+
}
|
95
|
+
end
|
96
|
+
```
|
97
|
+
|
50
98
|
## Usage
|
51
99
|
|
52
100
|
To enter new notification into the system, just call `notify` method:
|
@@ -1 +1 @@
|
|
1
|
-
<%= @notification.message.html_safe %>
|
1
|
+
<%= @notification.message.to_s.html_safe %>
|
data/lib/tolliver.rb
CHANGED
@@ -25,7 +25,10 @@ require "tolliver/services/delivery"
|
|
25
25
|
require "tolliver/services/policies/batch"
|
26
26
|
require "tolliver/services/policies/instantly"
|
27
27
|
require "tolliver/services/methods/email"
|
28
|
+
require "tolliver/services/methods/email/smtp"
|
29
|
+
require "tolliver/services/methods/email/mailgun"
|
28
30
|
require "tolliver/services/methods/sms"
|
31
|
+
require "tolliver/services/methods/sms/plivo"
|
29
32
|
|
30
33
|
# Mailers
|
31
34
|
require "tolliver/mailers/notification_mailer"
|
@@ -149,16 +152,24 @@ module Tolliver
|
|
149
152
|
mattr_accessor :email_sender_name
|
150
153
|
#@@email_sender_name = "Test sender" to be set in module initializer if needed
|
151
154
|
|
155
|
+
# Used e-mail provider
|
156
|
+
mattr_accessor :email_provider
|
157
|
+
@@email_provider = :smtp
|
158
|
+
|
159
|
+
# E-mail provider params
|
160
|
+
mattr_accessor :email_provider_params
|
161
|
+
@@email_provider_params = {}
|
162
|
+
|
163
|
+
# Used SMS provider
|
164
|
+
mattr_accessor :sms_sender
|
165
|
+
#@@sms_sender = "+420 123 456 789" to be set in module initializer if needed
|
166
|
+
|
152
167
|
# Used SMS provider
|
153
168
|
mattr_accessor :sms_provider
|
154
|
-
@@sms_provider =
|
169
|
+
@@sms_provider = nil
|
155
170
|
|
156
171
|
# SMS provider params
|
157
172
|
mattr_accessor :sms_provider_params
|
158
173
|
@@sms_provider_params = {}
|
159
174
|
|
160
|
-
# Used SMS provider
|
161
|
-
mattr_accessor :sms_sender
|
162
|
-
#@@sms_sender = "+420 123 456 789" to be set in module initializer if needed
|
163
|
-
|
164
175
|
end
|
@@ -18,7 +18,7 @@ module Tolliver
|
|
18
18
|
|
19
19
|
# Sender
|
20
20
|
@sender_email = Tolliver.email_sender
|
21
|
-
raise Tolliver::Errors::StandardError.new("Please specify sender.") if @sender_email.nil?
|
21
|
+
raise Tolliver::Errors::StandardError.new("Please specify e-mail sender.") if @sender_email.nil?
|
22
22
|
unless Tolliver.email_sender_name.blank?
|
23
23
|
@sender_email = "#{Tolliver.email_sender_name} <#{@sender_email}>"
|
24
24
|
end
|
@@ -33,7 +33,7 @@ module Tolliver
|
|
33
33
|
end
|
34
34
|
|
35
35
|
# Mail
|
36
|
-
mail(from: @sender_email, to: @notification_receiver.receiver_contact, subject: @notification.subject)
|
36
|
+
mail(from: @sender_email, to: @notification_receiver.receiver_contact.to_s, subject: @notification.subject)
|
37
37
|
end
|
38
38
|
|
39
39
|
end
|
@@ -15,11 +15,14 @@ module Tolliver
|
|
15
15
|
class Email
|
16
16
|
|
17
17
|
def deliver(notification_receiver)
|
18
|
+
return false if provider.nil?
|
19
|
+
|
20
|
+
# Prepare notification
|
18
21
|
notification = notification_receiver.notification_delivery.notification
|
19
22
|
|
20
23
|
# Send email
|
21
24
|
begin
|
22
|
-
|
25
|
+
provider.deliver(notification, notification_receiver)
|
23
26
|
notification_receiver.status = 'sent'
|
24
27
|
#rescue Net::SMTPFatalError, Net::SMTPSyntaxError
|
25
28
|
rescue StandardError => e
|
@@ -36,6 +39,16 @@ module Tolliver
|
|
36
39
|
true
|
37
40
|
end
|
38
41
|
|
42
|
+
protected
|
43
|
+
|
44
|
+
def provider
|
45
|
+
if @provider.nil? && Tolliver.email_provider
|
46
|
+
provider_class_name = "Tolliver::Services::Methods::Email::#{Tolliver.email_provider.to_s.camelize}"
|
47
|
+
@provider = provider_class_name.constantize.new(Tolliver.email_provider_params)
|
48
|
+
end
|
49
|
+
@provider
|
50
|
+
end
|
51
|
+
|
39
52
|
end
|
40
53
|
end
|
41
54
|
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# *****************************************************************************
|
2
|
+
# * Copyright (c) 2019 Matěj Outlý
|
3
|
+
# *****************************************************************************
|
4
|
+
# *
|
5
|
+
# * Mailgun e-mail provider
|
6
|
+
# *
|
7
|
+
# * Author: Matěj Outlý
|
8
|
+
# * Date : 1. 12. 2017
|
9
|
+
# *
|
10
|
+
# *****************************************************************************
|
11
|
+
|
12
|
+
module Tolliver
|
13
|
+
module Services
|
14
|
+
module Methods
|
15
|
+
class Email
|
16
|
+
class Mailgun
|
17
|
+
|
18
|
+
def initialize(params = {})
|
19
|
+
require 'mailgun-ruby'
|
20
|
+
if params[:api_key].blank? || params[:domain].blank?
|
21
|
+
raise Tolliver::Errors::StandardError.new('Please provide API key and domain in e-mail provider params.')
|
22
|
+
end
|
23
|
+
@client = ::Mailgun::Client.new(params[:api_key])
|
24
|
+
@domain = params[:domain]
|
25
|
+
end
|
26
|
+
|
27
|
+
def deliver(notification, notification_receiver)
|
28
|
+
|
29
|
+
# Sender
|
30
|
+
raise Tolliver::Errors::StandardError.new("Please specify e-mail sender.") if Tolliver.email_sender.nil?
|
31
|
+
|
32
|
+
# Message builder
|
33
|
+
message = ::Mailgun::MessageBuilder.new
|
34
|
+
message.from(Tolliver.email_sender, {'full_name' => Tolliver.email_sender_name})
|
35
|
+
message.add_recipient(:to, notification_receiver.receiver_contact.to_s)
|
36
|
+
message.reply_to(notification_receiver.notification_delivery.sender_contact.to_s) unless notification_receiver.notification_delivery.sender_contact.blank?
|
37
|
+
message.subject(notification.subject)
|
38
|
+
message.body_text(ActionController::Base.helpers.strip_tags(notification.message.to_s))
|
39
|
+
message.body_html(notification.message)
|
40
|
+
notification.notification_attachments.each do |notification_attachment|
|
41
|
+
message.add_attachment(StringIO.new(notification_attachment.attachment), notification_attachment.name)
|
42
|
+
end
|
43
|
+
response = @client.send_message(@domain, message)
|
44
|
+
if response.code != 200
|
45
|
+
raise Tolliver::Errors::StandardError.new(response.body)
|
46
|
+
end
|
47
|
+
|
48
|
+
true
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# *****************************************************************************
|
2
|
+
# * Copyright (c) 2019 Matěj Outlý
|
3
|
+
# *****************************************************************************
|
4
|
+
# *
|
5
|
+
# * SMTP e-mail provider
|
6
|
+
# *
|
7
|
+
# * Author: Matěj Outlý
|
8
|
+
# * Date : 1. 12. 2017
|
9
|
+
# *
|
10
|
+
# *****************************************************************************
|
11
|
+
|
12
|
+
module Tolliver
|
13
|
+
module Services
|
14
|
+
module Methods
|
15
|
+
class Email
|
16
|
+
class Smtp
|
17
|
+
|
18
|
+
def initialize(params = {}) end
|
19
|
+
|
20
|
+
def deliver(notification, notification_receiver)
|
21
|
+
Tolliver::NotificationMailer.notify(notification, notification_receiver).deliver_now
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -15,11 +15,14 @@ module Tolliver
|
|
15
15
|
class Sms
|
16
16
|
|
17
17
|
def deliver(notification_receiver)
|
18
|
+
return false if provider.nil?
|
19
|
+
|
20
|
+
# Prepare notification
|
18
21
|
notification = notification_receiver.notification_delivery.notification
|
19
22
|
|
20
23
|
# Send SMS
|
21
24
|
begin
|
22
|
-
provider.deliver(
|
25
|
+
provider.deliver(notification, notification_receiver)
|
23
26
|
notification_receiver.status = 'sent'
|
24
27
|
rescue StandardError => e
|
25
28
|
notification_receiver.status = 'error'
|
@@ -38,7 +41,7 @@ module Tolliver
|
|
38
41
|
protected
|
39
42
|
|
40
43
|
def provider
|
41
|
-
if @provider.nil?
|
44
|
+
if @provider.nil? && Tolliver.sms_provider
|
42
45
|
provider_class_name = "Tolliver::Services::Methods::Sms::#{Tolliver.sms_provider.to_s.camelize}"
|
43
46
|
@provider = provider_class_name.constantize.new(Tolliver.sms_provider_params)
|
44
47
|
end
|
@@ -9,24 +9,23 @@
|
|
9
9
|
# *
|
10
10
|
# *****************************************************************************
|
11
11
|
|
12
|
-
require 'plivo'
|
13
|
-
|
14
12
|
module Tolliver
|
15
13
|
module Services
|
16
14
|
module Methods
|
17
|
-
|
15
|
+
class Sms
|
18
16
|
class Plivo
|
19
17
|
|
20
18
|
def initialize(params = {})
|
19
|
+
require 'plivo'
|
21
20
|
if params[:auth_id].blank? || params[:auth_token].blank?
|
22
|
-
raise Tolliver::Errors::StandardError.new('Please provide Auth ID and Auth Token in provider params.')
|
21
|
+
raise Tolliver::Errors::StandardError.new('Please provide Auth ID and Auth Token in SMS provider params.')
|
23
22
|
end
|
24
23
|
@auth_id = params[:auth_id]
|
25
24
|
@auth_token = params[:auth_token]
|
26
25
|
@api = ::Plivo::RestAPI.new(@auth_id, @auth_token)
|
27
26
|
end
|
28
27
|
|
29
|
-
def deliver(
|
28
|
+
def deliver(notification, notification_receiver)
|
30
29
|
|
31
30
|
# Check message length.
|
32
31
|
if message.bytesize > 200
|
@@ -36,8 +35,8 @@ module Tolliver
|
|
36
35
|
# Request API
|
37
36
|
response = @api.send_message({
|
38
37
|
'src' => Tolliver.sms_sender, # TODO: This should be improved to take sender from number pool and remember number / message mapping
|
39
|
-
'dst' =>
|
40
|
-
'text' => message.to_s,
|
38
|
+
'dst' => notification_receiver.receiver_contact.to_s,
|
39
|
+
'text' => ActionController::Base.helpers.strip_tags(notification.message.to_s),
|
41
40
|
'method' => 'POST'
|
42
41
|
})
|
43
42
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tolliver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matěj Outlý
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -63,6 +63,8 @@ files:
|
|
63
63
|
- lib/tolliver/models/notification_template.rb
|
64
64
|
- lib/tolliver/services/delivery.rb
|
65
65
|
- lib/tolliver/services/methods/email.rb
|
66
|
+
- lib/tolliver/services/methods/email/mailgun.rb
|
67
|
+
- lib/tolliver/services/methods/email/smtp.rb
|
66
68
|
- lib/tolliver/services/methods/sms.rb
|
67
69
|
- lib/tolliver/services/methods/sms/plivo.rb
|
68
70
|
- lib/tolliver/services/notification.rb
|