tolliver 1.0.0 → 2.1.2
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 +71 -13
- data/app/models/tolliver/notification.rb +0 -1
- data/app/models/tolliver/notification_attachment.rb +16 -0
- data/app/models/tolliver/notification_delivery.rb +1 -3
- data/app/models/tolliver/notification_receiver.rb +0 -2
- data/app/models/tolliver/notification_template.rb +0 -1
- data/app/views/tolliver/notification_mailer/notify.html.erb +1 -0
- data/app/views/tolliver/notification_mailer/notify.text.erb +1 -0
- data/config/locales/en.yml +1 -1
- data/db/migrate/20160121093817_create_notifications.rb +1 -12
- data/db/migrate/20160121094838_create_notification_receivers.rb +6 -4
- data/db/migrate/20160509144238_create_notification_templates.rb +4 -4
- data/db/migrate/20170630190600_create_notification_deliveries.rb +10 -3
- data/db/migrate/20201027150000_create_notification_attachments.rb +17 -0
- data/db/migrate/20210415120000_add_notification_attachments_url.rb +6 -0
- data/lib/tolliver.rb +66 -54
- data/lib/tolliver/errors/bad_request.rb +17 -0
- data/lib/tolliver/errors/not_found.rb +17 -0
- data/lib/tolliver/errors/standard_error.rb +17 -0
- data/lib/tolliver/jobs/batch_policy_job.rb +19 -0
- data/lib/tolliver/jobs/delivery_job.rb +18 -0
- data/lib/tolliver/mailers/notification_mailer.rb +10 -13
- data/lib/tolliver/models/notification.rb +11 -64
- data/lib/tolliver/models/notification_attachment.rb +47 -0
- data/lib/tolliver/models/notification_delivery.rb +32 -40
- data/lib/tolliver/models/notification_receiver.rb +3 -25
- data/lib/tolliver/models/notification_template.rb +6 -10
- data/lib/tolliver/services/delivery_service.rb +63 -0
- data/lib/tolliver/services/methods/email.rb +55 -0
- data/lib/tolliver/services/methods/email/mailgun.rb +55 -0
- data/lib/tolliver/services/{delivery.rb → methods/email/smtp.rb} +11 -13
- data/lib/tolliver/services/methods/sms.rb +54 -0
- data/lib/tolliver/services/methods/sms/plivo.rb +50 -0
- data/lib/tolliver/services/notification_service.rb +179 -0
- data/lib/tolliver/services/policies/batch.rb +82 -0
- data/lib/tolliver/services/policies/instantly.rb +50 -0
- metadata +27 -16
- data/app/views/notification_mailer/notify.html.erb +0 -1
- data/app/views/notification_mailer/notify.text.erb +0 -1
- data/lib/tolliver/models/notification_delivery/batch.rb +0 -77
- data/lib/tolliver/models/notification_delivery/instantly.rb +0 -55
- data/lib/tolliver/models/notification_receiver/email.rb +0 -46
- data/lib/tolliver/models/notification_receiver/sms.rb +0 -45
- data/lib/tolliver/services/notification.rb +0 -234
- data/lib/tolliver/services/sms/plivo.rb +0 -49
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a1110eda739a5bb9763c51608a6a251c356962bc02690b2b5b81d06239d0893
|
4
|
+
data.tar.gz: 4ab466afccc3086a66c4d50ecc7c87214b89aa734553f64b8e7f73c93ec491a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5901317de7117ceca9fcc6396706d018d62d99ebaf69b7361fe2118766c9bf87a6ac684c8169815818b9ac66fe06e9cd6c0326d86ea6f46202abc6352f7d9365
|
7
|
+
data.tar.gz: 65913171587f3632ed28e43a00827b109a84b8497ffd39651f1002da4ce7cc0a57a8ccaa43982ecf1ef949e3e0e45f7b9fc85328009784c2b88e51a29d2a6d3f
|
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
|
@@ -12,7 +12,7 @@ send it in a batch with different delivery methods:
|
|
12
12
|
Add gem to your Gemfile:
|
13
13
|
|
14
14
|
```ruby
|
15
|
-
gem
|
15
|
+
gem 'tolliver'
|
16
16
|
```
|
17
17
|
|
18
18
|
Add database migrations to you application (you can modify DB structure accordingly before migrating):
|
@@ -20,37 +20,95 @@ 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.
|
30
|
-
config.
|
45
|
+
config.email_sender = 'no-reply@domain.com'
|
46
|
+
config.delivery_methods = [
|
31
47
|
:email
|
32
48
|
]
|
33
|
-
config.template_refs = [
|
34
|
-
:user_new_password,
|
35
|
-
]
|
36
49
|
end
|
37
50
|
```
|
38
51
|
|
39
52
|
Available options:
|
40
53
|
|
41
54
|
- notification_model
|
55
|
+
- notification_attachment_model
|
42
56
|
- notification_delivery_model
|
43
57
|
- notification_receiver_model
|
44
58
|
- notification_template_model
|
45
|
-
-
|
46
|
-
-
|
47
|
-
-
|
48
|
-
-
|
59
|
+
- email_sender
|
60
|
+
- email_sender_name
|
61
|
+
- email_provider
|
62
|
+
- email_provider_params
|
63
|
+
- sms_sender
|
64
|
+
- sms_provider
|
65
|
+
- sms_provider_params
|
66
|
+
- delivery_methods
|
67
|
+
|
68
|
+
### Plivo support
|
49
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:
|
53
101
|
|
54
102
|
```ruby
|
55
|
-
Tolliver.notify(
|
103
|
+
Tolliver.notify(
|
104
|
+
template: :template_ref,
|
105
|
+
params: [
|
106
|
+
{key: :key_1, value: :value_1},
|
107
|
+
{key: :key_2, value: :value_2}
|
108
|
+
],
|
109
|
+
receivers: [
|
110
|
+
{ref: :receiver_1, contact: "receiver_1@domain.tld"},
|
111
|
+
{ref: :receiver_2, contact: "receiver_2@domain.tld"},
|
112
|
+
]
|
113
|
+
)
|
56
114
|
```
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# *****************************************************************************
|
2
|
+
# * Copyright (c) 2019 Matěj Outlý
|
3
|
+
# *****************************************************************************
|
4
|
+
# *
|
5
|
+
# * Notification attachment
|
6
|
+
# *
|
7
|
+
# * Author: Matěj Outlý
|
8
|
+
# * Date : 27. 10. 2020
|
9
|
+
# *
|
10
|
+
# *****************************************************************************
|
11
|
+
|
12
|
+
module Tolliver
|
13
|
+
class NotificationAttachment < ActiveRecord::Base
|
14
|
+
include Tolliver::Models::NotificationAttachment
|
15
|
+
end
|
16
|
+
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
# * Copyright (c) 2019 Matěj Outlý
|
3
3
|
# *****************************************************************************
|
4
4
|
# *
|
5
|
-
# * Notification
|
5
|
+
# * Notification delivery
|
6
6
|
# *
|
7
7
|
# * Author: Matěj Outlý
|
8
8
|
# * Date : 30. 6. 2017
|
@@ -13,7 +13,5 @@ module Tolliver
|
|
13
13
|
class NotificationDelivery < ActiveRecord::Base
|
14
14
|
include Tolliver::Utils::Enum
|
15
15
|
include Tolliver::Models::NotificationDelivery
|
16
|
-
include Tolliver::Models::NotificationDelivery::Batch
|
17
|
-
include Tolliver::Models::NotificationDelivery::Instantly
|
18
16
|
end
|
19
17
|
end
|
@@ -13,7 +13,5 @@ module Tolliver
|
|
13
13
|
class NotificationReceiver < ActiveRecord::Base
|
14
14
|
include Tolliver::Utils::Enum
|
15
15
|
include Tolliver::Models::NotificationReceiver
|
16
|
-
include Tolliver::Models::NotificationReceiver::Email
|
17
|
-
include Tolliver::Models::NotificationReceiver::Sms
|
18
16
|
end
|
19
17
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= @notification.message.to_s.html_safe %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= ActionController::Base.helpers.strip_tags(@notification.message.to_s) %>
|
data/config/locales/en.yml
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
class CreateNotifications < ActiveRecord::Migration
|
1
|
+
class CreateNotifications < ActiveRecord::Migration[6.0]
|
2
2
|
def change
|
3
3
|
create_table :notifications do |t|
|
4
4
|
|
@@ -8,21 +8,10 @@ class CreateNotifications < ActiveRecord::Migration
|
|
8
8
|
# Association to template
|
9
9
|
t.integer :notification_template_id, index: true
|
10
10
|
|
11
|
-
# Kind
|
12
|
-
t.string :kind
|
13
|
-
|
14
11
|
# Message
|
15
12
|
t.string :subject
|
16
13
|
t.text :message
|
17
14
|
|
18
|
-
# Attachments
|
19
|
-
t.string :url
|
20
|
-
t.string :attachment
|
21
|
-
|
22
|
-
# Sender
|
23
|
-
t.integer :sender_id, index: true
|
24
|
-
t.string :sender_type, index: true
|
25
|
-
|
26
15
|
end
|
27
16
|
end
|
28
17
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class CreateNotificationReceivers < ActiveRecord::Migration
|
1
|
+
class CreateNotificationReceivers < ActiveRecord::Migration[6.0]
|
2
2
|
def change
|
3
3
|
create_table :notification_receivers do |t|
|
4
4
|
|
@@ -9,11 +9,13 @@ class CreateNotificationReceivers < ActiveRecord::Migration
|
|
9
9
|
|
10
10
|
# Relations
|
11
11
|
t.integer :notification_delivery_id, index: true
|
12
|
-
|
13
|
-
|
12
|
+
|
13
|
+
# Receiver
|
14
|
+
t.string :receiver_ref, index: true
|
15
|
+
t.string :receiver_contact
|
14
16
|
|
15
17
|
# State
|
16
|
-
t.string :
|
18
|
+
t.string :status
|
17
19
|
t.string :error_message
|
18
20
|
|
19
21
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class CreateNotificationTemplates < ActiveRecord::Migration
|
1
|
+
class CreateNotificationTemplates < ActiveRecord::Migration[6.0]
|
2
2
|
def change
|
3
3
|
create_table :notification_templates do |t|
|
4
4
|
|
@@ -6,15 +6,15 @@ class CreateNotificationTemplates < ActiveRecord::Migration
|
|
6
6
|
t.timestamps null: true
|
7
7
|
|
8
8
|
# Identification
|
9
|
-
t.string :ref
|
9
|
+
t.string :ref, index: true
|
10
10
|
|
11
11
|
# Message
|
12
12
|
t.string :subject
|
13
13
|
t.text :message
|
14
14
|
|
15
15
|
# Handlers
|
16
|
-
t.boolean :
|
17
|
-
t.boolean :
|
16
|
+
t.boolean :is_disabled
|
17
|
+
t.boolean :is_dry
|
18
18
|
|
19
19
|
end
|
20
20
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class CreateNotificationDeliveries < ActiveRecord::Migration
|
1
|
+
class CreateNotificationDeliveries < ActiveRecord::Migration[6.0]
|
2
2
|
def change
|
3
3
|
create_table :notification_deliveries do |t|
|
4
4
|
|
@@ -9,8 +9,15 @@ class CreateNotificationDeliveries < ActiveRecord::Migration
|
|
9
9
|
# Relations
|
10
10
|
t.integer :notification_id, index: true
|
11
11
|
|
12
|
-
# Delivery
|
13
|
-
t.string :
|
12
|
+
# Delivery method (email, SMS, ...)
|
13
|
+
t.string :method
|
14
|
+
|
15
|
+
# Sender
|
16
|
+
t.string :sender_ref, index: true
|
17
|
+
t.string :sender_contact
|
18
|
+
|
19
|
+
# Postpone
|
20
|
+
t.boolean :is_postponed
|
14
21
|
|
15
22
|
# Statistics
|
16
23
|
t.integer :receivers_count
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class CreateNotificationAttachments < ActiveRecord::Migration[6.0]
|
2
|
+
def change
|
3
|
+
create_table :notification_attachments do |t|
|
4
|
+
|
5
|
+
# Timestamps
|
6
|
+
t.timestamps null: true
|
7
|
+
|
8
|
+
# Relations
|
9
|
+
t.integer :notification_id, index: true
|
10
|
+
|
11
|
+
# Data
|
12
|
+
t.string :name
|
13
|
+
t.string :attachment
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/tolliver.rb
CHANGED
@@ -14,17 +14,25 @@ require "tolliver/engine"
|
|
14
14
|
|
15
15
|
# Models
|
16
16
|
require "tolliver/models/notification"
|
17
|
+
require "tolliver/models/notification_attachment"
|
17
18
|
require "tolliver/models/notification_delivery"
|
18
|
-
require "tolliver/models/notification_delivery/batch"
|
19
|
-
require "tolliver/models/notification_delivery/instantly"
|
20
19
|
require "tolliver/models/notification_receiver"
|
21
|
-
require "tolliver/models/notification_receiver/email"
|
22
|
-
require "tolliver/models/notification_receiver/sms"
|
23
20
|
require "tolliver/models/notification_template"
|
24
21
|
|
25
22
|
# Services
|
26
|
-
require "tolliver/services/
|
27
|
-
require "tolliver/services/
|
23
|
+
require "tolliver/services/notification_service"
|
24
|
+
require "tolliver/services/delivery_service"
|
25
|
+
require "tolliver/services/policies/batch"
|
26
|
+
require "tolliver/services/policies/instantly"
|
27
|
+
require "tolliver/services/methods/email"
|
28
|
+
require "tolliver/services/methods/email/smtp"
|
29
|
+
require "tolliver/services/methods/email/mailgun"
|
30
|
+
require "tolliver/services/methods/sms"
|
31
|
+
require "tolliver/services/methods/sms/plivo"
|
32
|
+
|
33
|
+
# Jobs
|
34
|
+
require "tolliver/jobs/delivery_job"
|
35
|
+
require "tolliver/jobs/batch_policy_job"
|
28
36
|
|
29
37
|
# Mailers
|
30
38
|
require "tolliver/mailers/notification_mailer"
|
@@ -32,6 +40,11 @@ require "tolliver/mailers/notification_mailer"
|
|
32
40
|
# Utils
|
33
41
|
require "tolliver/utils/enum"
|
34
42
|
|
43
|
+
# Errors
|
44
|
+
require "tolliver/errors/standard_error"
|
45
|
+
require "tolliver/errors/bad_request"
|
46
|
+
require "tolliver/errors/not_found"
|
47
|
+
|
35
48
|
module Tolliver
|
36
49
|
|
37
50
|
# This will keep Rails Engine from generating all table prefixes with the engines name
|
@@ -42,8 +55,21 @@ module Tolliver
|
|
42
55
|
# Services
|
43
56
|
# *************************************************************************
|
44
57
|
|
45
|
-
|
46
|
-
|
58
|
+
def self.notify(options)
|
59
|
+
Tolliver::Services::NotificationService.instance.notify(options)
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.deliver(notification)
|
63
|
+
Tolliver::Services::DeliveryService.instance.deliver(notification)
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.enqueue_for_delivery(notification)
|
67
|
+
Tolliver::Services::DeliveryService.instance.enqueue_for_delivery(notification)
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.reset_delivery(notification)
|
71
|
+
Tolliver::Services::DeliveryService.instance.reset_delivery(notification)
|
72
|
+
end
|
47
73
|
|
48
74
|
# *************************************************************************
|
49
75
|
# Configuration
|
@@ -54,18 +80,6 @@ module Tolliver
|
|
54
80
|
yield self
|
55
81
|
end
|
56
82
|
|
57
|
-
# *************************************************************************
|
58
|
-
# SMS
|
59
|
-
# *************************************************************************
|
60
|
-
|
61
|
-
def self.sms_provider_obj
|
62
|
-
if @sms_provider_obj.nil?
|
63
|
-
sms_provider_class_name = "Tolliver::Services::Sms::#{Tolliver.sms_provider.to_s.to_camel}"
|
64
|
-
@sms_provider_obj = sms_provider_class_name.constantize.new(Tolliver.sms_provider_params)
|
65
|
-
end
|
66
|
-
return @sms_provider_obj
|
67
|
-
end
|
68
|
-
|
69
83
|
# *************************************************************************
|
70
84
|
# Config options
|
71
85
|
# *************************************************************************
|
@@ -79,6 +93,15 @@ module Tolliver
|
|
79
93
|
|
80
94
|
@@notification_model = "Tolliver::Notification"
|
81
95
|
|
96
|
+
# Notification attachment model
|
97
|
+
mattr_accessor :notification_attachment_model
|
98
|
+
|
99
|
+
def self.notification_attachment_model
|
100
|
+
return @@notification_attachment_model.constantize
|
101
|
+
end
|
102
|
+
|
103
|
+
@@notification_attachment_model = "Tolliver::NotificationAttachment"
|
104
|
+
|
82
105
|
# Notification delivery model
|
83
106
|
mattr_accessor :notification_delivery_model
|
84
107
|
|
@@ -106,33 +129,14 @@ module Tolliver
|
|
106
129
|
|
107
130
|
@@notification_template_model = "Tolliver::NotificationTemplate"
|
108
131
|
|
109
|
-
#
|
110
|
-
mattr_accessor :people_selector_model
|
111
|
-
|
112
|
-
def self.people_selector_model
|
113
|
-
return @@people_selector_model.constantize
|
114
|
-
end
|
115
|
-
|
116
|
-
@@people_selector_model = nil
|
117
|
-
|
118
|
-
# Available notification template refs. For each defined ref there will be
|
119
|
-
# an automatically created record in the notification_templates table.
|
120
|
-
# System administrator can define content of this template via admin
|
121
|
-
# interface.
|
122
|
-
mattr_accessor :template_refs
|
123
|
-
@@template_refs = [
|
124
|
-
# :some_notification_ref_1,
|
125
|
-
# :some_notification_ref_2,
|
126
|
-
]
|
127
|
-
|
128
|
-
# Delivery kinds
|
132
|
+
# Delivery methods
|
129
133
|
#
|
130
|
-
# Available
|
134
|
+
# Available methods:
|
131
135
|
# - email
|
132
136
|
# - sms
|
133
137
|
# - whatever
|
134
|
-
mattr_accessor :
|
135
|
-
@@
|
138
|
+
mattr_accessor :delivery_methods
|
139
|
+
@@delivery_methods = [
|
136
140
|
:email
|
137
141
|
]
|
138
142
|
|
@@ -144,24 +148,32 @@ module Tolliver
|
|
144
148
|
mattr_accessor :load_balance
|
145
149
|
@@load_balance = nil
|
146
150
|
|
147
|
-
#
|
148
|
-
mattr_accessor :
|
149
|
-
#@@
|
151
|
+
# E-mail sender
|
152
|
+
mattr_accessor :email_sender
|
153
|
+
#@@email_sender = "test@domain.com" to be set in module initializer if needed
|
154
|
+
|
155
|
+
# E-mail sender name
|
156
|
+
mattr_accessor :email_sender_name
|
157
|
+
#@@email_sender_name = "Test sender" to be set in module initializer if needed
|
158
|
+
|
159
|
+
# Used e-mail provider
|
160
|
+
mattr_accessor :email_provider
|
161
|
+
@@email_provider = :smtp
|
150
162
|
|
151
|
-
#
|
152
|
-
mattr_accessor :
|
153
|
-
|
163
|
+
# E-mail provider params
|
164
|
+
mattr_accessor :email_provider_params
|
165
|
+
@@email_provider_params = {}
|
166
|
+
|
167
|
+
# Used SMS provider
|
168
|
+
mattr_accessor :sms_sender
|
169
|
+
#@@sms_sender = "+420 123 456 789" to be set in module initializer if needed
|
154
170
|
|
155
171
|
# Used SMS provider
|
156
172
|
mattr_accessor :sms_provider
|
157
|
-
@@sms_provider =
|
173
|
+
@@sms_provider = nil
|
158
174
|
|
159
175
|
# SMS provider params
|
160
176
|
mattr_accessor :sms_provider_params
|
161
177
|
@@sms_provider_params = {}
|
162
178
|
|
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
|
-
|
167
179
|
end
|