tolliver 1.0.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.
Files changed (33) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +56 -0
  4. data/app/mailers/tolliver/notification_mailer.rb +16 -0
  5. data/app/models/tolliver/notification.rb +17 -0
  6. data/app/models/tolliver/notification_delivery.rb +19 -0
  7. data/app/models/tolliver/notification_receiver.rb +19 -0
  8. data/app/models/tolliver/notification_template.rb +17 -0
  9. data/app/views/notification_mailer/notify.html.erb +1 -0
  10. data/app/views/notification_mailer/notify.text.erb +1 -0
  11. data/config/locales/cs.yml +86 -0
  12. data/config/locales/en.yml +86 -0
  13. data/config/routes.rb +13 -0
  14. data/db/migrate/20160121093817_create_notifications.rb +28 -0
  15. data/db/migrate/20160121094838_create_notification_receivers.rb +21 -0
  16. data/db/migrate/20160509144238_create_notification_templates.rb +21 -0
  17. data/db/migrate/20170630190600_create_notification_deliveries.rb +20 -0
  18. data/lib/tolliver.rb +167 -0
  19. data/lib/tolliver/engine.rb +17 -0
  20. data/lib/tolliver/mailers/notification_mailer.rb +44 -0
  21. data/lib/tolliver/models/notification.rb +121 -0
  22. data/lib/tolliver/models/notification_delivery.rb +112 -0
  23. data/lib/tolliver/models/notification_delivery/batch.rb +77 -0
  24. data/lib/tolliver/models/notification_delivery/instantly.rb +55 -0
  25. data/lib/tolliver/models/notification_receiver.rb +76 -0
  26. data/lib/tolliver/models/notification_receiver/email.rb +46 -0
  27. data/lib/tolliver/models/notification_receiver/sms.rb +45 -0
  28. data/lib/tolliver/models/notification_template.rb +54 -0
  29. data/lib/tolliver/services/delivery.rb +30 -0
  30. data/lib/tolliver/services/notification.rb +234 -0
  31. data/lib/tolliver/services/sms/plivo.rb +49 -0
  32. data/lib/tolliver/utils/enum.rb +133 -0
  33. metadata +89 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6b51e98fd8b3ff0cdfbb2a9e4c3461367d91e84603b8f0dbc173520c34d2625e
4
+ data.tar.gz: 2cfc09c23fc2e2911c3c6c0bb6f3095a6a929c513fc837e23e9043614dc6682d
5
+ SHA512:
6
+ metadata.gz: bb9d2b1a57c832ee8b6d24859ada4760bc5b8405c799df7dc28ca252b7bb8dd5cc8a3fdb92df530cc2d12e16072bd49afc1f041eddb7f27c409fe25da3d9ef6a
7
+ data.tar.gz: e55ef50ab51b8cc260f3e26c542719109ef2a1518dc775b6c2541b0a0d474dd1263894d973ac40784f70e028a9e35751c5502519b56aa62f779b2088fb8bb462
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Matěj Outlý
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,56 @@
1
+ # Tolliver
2
+ A long serving Junior Postman Tolliver Groat. With this gem you can create
3
+ notifications based on templates defined by the system administrator and
4
+ send it in a batch with different delivery methods:
5
+
6
+ - E-mail
7
+ - SMS
8
+ - Whatever custom delivery method
9
+
10
+ ## Installation
11
+
12
+ Add gem to your Gemfile:
13
+
14
+ ```ruby
15
+ gem "tolliver"
16
+ ```
17
+
18
+ Add database migrations to you application (you can modify DB structure accordingly before migrating):
19
+
20
+ $ rake tolliver:install:migrations
21
+ $ rake db:migrate
22
+
23
+ ## Configuration
24
+
25
+ You can configure module through `config/initializers/tolliver.rb` file:
26
+
27
+ ```ruby
28
+ Tolliver.setup do |config|
29
+ config.mailer_sender = "no-reply@domain.com"
30
+ config.delivery_kinds = [
31
+ :email
32
+ ]
33
+ config.template_refs = [
34
+ :user_new_password,
35
+ ]
36
+ end
37
+ ```
38
+
39
+ Available options:
40
+
41
+ - notification_model
42
+ - notification_delivery_model
43
+ - notification_receiver_model
44
+ - notification_template_model
45
+ - people_selector_model
46
+ - mailer_sender
47
+ - delivery_kinds
48
+ - template_refs
49
+
50
+ ## Usage
51
+
52
+ To enter new notification into the system, just call `notify` method:
53
+
54
+ ```ruby
55
+ Tolliver.notify([:sample_notification_ref, param_1, param_2], [receiver_1, receiver_2], options)
56
+ ```
@@ -0,0 +1,16 @@
1
+ # *****************************************************************************
2
+ # * Copyright (c) 2019 Matěj Outlý
3
+ # *****************************************************************************
4
+ # *
5
+ # * Notification mailer
6
+ # *
7
+ # * Author: Matěj Outlý
8
+ # * Date : 21. 1. 2016
9
+ # *
10
+ # *****************************************************************************
11
+
12
+ module Tolliver
13
+ class NotificationMailer < ::ApplicationMailer
14
+ include Tolliver::Mailers::NotificationMailer
15
+ end
16
+ end
@@ -0,0 +1,17 @@
1
+ # *****************************************************************************
2
+ # * Copyright (c) 2019 Matěj Outlý
3
+ # *****************************************************************************
4
+ # *
5
+ # * Notification
6
+ # *
7
+ # * Author: Matěj Outlý
8
+ # * Date : 21. 1. 2016
9
+ # *
10
+ # *****************************************************************************
11
+
12
+ module Tolliver
13
+ class Notification < ActiveRecord::Base
14
+ include Tolliver::Utils::Enum
15
+ include Tolliver::Models::Notification
16
+ end
17
+ end
@@ -0,0 +1,19 @@
1
+ # *****************************************************************************
2
+ # * Copyright (c) 2019 Matěj Outlý
3
+ # *****************************************************************************
4
+ # *
5
+ # * Notification receiver
6
+ # *
7
+ # * Author: Matěj Outlý
8
+ # * Date : 30. 6. 2017
9
+ # *
10
+ # *****************************************************************************
11
+
12
+ module Tolliver
13
+ class NotificationDelivery < ActiveRecord::Base
14
+ include Tolliver::Utils::Enum
15
+ include Tolliver::Models::NotificationDelivery
16
+ include Tolliver::Models::NotificationDelivery::Batch
17
+ include Tolliver::Models::NotificationDelivery::Instantly
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # *****************************************************************************
2
+ # * Copyright (c) 2019 Matěj Outlý
3
+ # *****************************************************************************
4
+ # *
5
+ # * Notification receiver
6
+ # *
7
+ # * Author: Matěj Outlý
8
+ # * Date : 21. 1. 2016
9
+ # *
10
+ # *****************************************************************************
11
+
12
+ module Tolliver
13
+ class NotificationReceiver < ActiveRecord::Base
14
+ include Tolliver::Utils::Enum
15
+ include Tolliver::Models::NotificationReceiver
16
+ include Tolliver::Models::NotificationReceiver::Email
17
+ include Tolliver::Models::NotificationReceiver::Sms
18
+ end
19
+ end
@@ -0,0 +1,17 @@
1
+ # *****************************************************************************
2
+ # * Copyright (c) 2019 Matěj Outlý
3
+ # *****************************************************************************
4
+ # *
5
+ # * Notification template
6
+ # *
7
+ # * Author: Matěj Outlý
8
+ # * Date : 9. 5. 2016
9
+ # *
10
+ # *****************************************************************************
11
+
12
+ module Tolliver
13
+ class NotificationTemplate < ActiveRecord::Base
14
+ include Tolliver::Utils::Enum
15
+ include Tolliver::Models::NotificationTemplate
16
+ end
17
+ end
@@ -0,0 +1 @@
1
+ <%= @notification.message.html_safe %>
@@ -0,0 +1 @@
1
+ <%= @notification.message.to_s.strip_tags %>
@@ -0,0 +1,86 @@
1
+ cs:
2
+ activerecord:
3
+ attributes:
4
+ tolliver/notification:
5
+ created_at: Vytvořeno
6
+ subject: Předmět
7
+ message: Obsah
8
+ url: URL
9
+ attachment: Příloha
10
+ kind: Typ zprávy
11
+ kind_values:
12
+ notice: Informace
13
+ alert: Chyba
14
+ warning: Varování
15
+ sender: Odesílatel
16
+ sent_at: Odesláno
17
+ done: Hotovo
18
+ deliveries: Metody doručení
19
+ tolliver/notification_delivery:
20
+ sent_at: Odesláno
21
+ done: Hotovo
22
+ receivers: Příjemci
23
+ kind: Doručovací metoda
24
+ kind_values:
25
+ email: E-mail
26
+ sms: SMS
27
+ tolliver/notification_receiver:
28
+ receiver: Příjemce
29
+ state: Stav
30
+ state_values:
31
+ created: Vytvořeno
32
+ sent: Odesláno
33
+ received: Doručeno
34
+ accepted: Akceptováno
35
+ error: Chyba
36
+ state_colors:
37
+ created: yellow
38
+ sent: green
39
+ received: green
40
+ accepted: green
41
+ error: red
42
+ created_at: Vytvořeno
43
+ sent_at: Odesláno
44
+ received_at: Doručeno
45
+ tolliver/notification_template:
46
+ ref: Klíč
47
+ subject: Předmět
48
+ message: Zpráva
49
+ disabled: Nevytvářet notifikace
50
+ disabled_values:
51
+ bool_yes: Nevytvářet
52
+ bool_no: Vytvářet
53
+ disabled_colors:
54
+ bool_yes: red
55
+ bool_no: green
56
+ dry: Neodesílat notifikace
57
+ dry_values:
58
+ bool_yes: Neodesílat
59
+ bool_no: Odesílat
60
+ dry_colors:
61
+ bool_yes: red
62
+ bool_no: green
63
+ notices:
64
+ models:
65
+ tolliver/notification:
66
+ update: Zpráva byla úspěšně uložena.
67
+ create: Zpráva byla úspěšně vytvořena.
68
+ enqueue_for_delivery: Zpráva byla úspěšně zařazena k odeslání.
69
+ destroy: Zpráva byla úspěšně smazána.
70
+ tolliver/notification_template:
71
+ update: Šablona zprávy byla úspěšně uložena.
72
+ errors:
73
+ models:
74
+ tolliver/notification:
75
+ not_found: Zpráva nebyla nalezena.
76
+ tolliver/notification_delivery:
77
+ not_found: Doručovací metoda nebyla nalezena.
78
+ tolliver/notification_receiver:
79
+ not_found: Příjemce nebyl nalezen.
80
+ tolliver/notification_template:
81
+ not_found: Šablona zprávy nebyla nalezena.
82
+ mailers:
83
+ tolliver:
84
+ notification:
85
+ notify:
86
+ subject: "%{url}: Nová systémová zpráva"
@@ -0,0 +1,86 @@
1
+ en:
2
+ activerecord:
3
+ attributes:
4
+ tolliver/notification:
5
+ created_at: Created
6
+ subject: Subject
7
+ message: Message
8
+ url: URL
9
+ attachment: Attachment
10
+ kind: Message type
11
+ kind_values:
12
+ notice: Information
13
+ alert: Error
14
+ warning: Worning
15
+ sender: Sender
16
+ sent_at: Sent
17
+ done: Done
18
+ deliveries: Methods of delivery
19
+ tolliver/notification_delivery:
20
+ sent_at: Sent
21
+ done: Done
22
+ receivers: Receivers
23
+ kind: Delivery type
24
+ kind_values:
25
+ email: E-mail
26
+ sms: SMS
27
+ tolliver/notification_receiver:
28
+ receiver: Receiver
29
+ state: Status
30
+ state_values:
31
+ created: Created
32
+ sent: Sent
33
+ received: Received
34
+ accepted: Accepted
35
+ error: Error
36
+ state_colors:
37
+ created: yellow
38
+ sent: green
39
+ received: green
40
+ accepted: green
41
+ error: red
42
+ created_at: Created
43
+ sent_at: Sent
44
+ received_at: Received
45
+ tolliver/notification_template:
46
+ ref: Reference
47
+ subject: Subject
48
+ message: Message
49
+ disabled: Disable notifications
50
+ disabled_values:
51
+ bool_yes: Disable
52
+ bool_no: Enable
53
+ disabled_colors:
54
+ bool_yes: red
55
+ bool_no: green
56
+ dry: Don't send notifications
57
+ dry_values:
58
+ bool_yes: Don't send
59
+ bool_no: Send
60
+ dry_colors:
61
+ bool_yes: red
62
+ bool_no: green
63
+ notices:
64
+ models:
65
+ tolliver/notification:
66
+ update: Message was successfully saved.
67
+ create: Message was successfully created.
68
+ enqueue_for_delivery: Message was successfully enqueued for delivery.
69
+ destroy: Message was successfully deleted.
70
+ tolliver/notification_template:
71
+ update: Template was successfully saved.
72
+ errors:
73
+ models:
74
+ tolliver/notification:
75
+ not_found: Message was not found.
76
+ tolliver/notification_delivery:
77
+ not_found: Delivery method was not found.
78
+ tolliver/notification_receiver:
79
+ not_found: Receier was not found.
80
+ tolliver/notification_template:
81
+ not_found: Template was not found.
82
+ mailers:
83
+ tolliver:
84
+ notification:
85
+ notify:
86
+ subject: "%{url}: New system notification"
@@ -0,0 +1,13 @@
1
+ # *****************************************************************************
2
+ # * Copyright (c) 2019 Matěj Outlý
3
+ # *****************************************************************************
4
+ # *
5
+ # * Routes
6
+ # *
7
+ # * Author: Matěj Outlý
8
+ # * Date : 26. 11. 2015
9
+ # *
10
+ # *****************************************************************************
11
+
12
+ Tolliver::Engine.routes.draw do
13
+ end
@@ -0,0 +1,28 @@
1
+ class CreateNotifications < ActiveRecord::Migration
2
+ def change
3
+ create_table :notifications do |t|
4
+
5
+ # Timestamps
6
+ t.timestamps null: true
7
+
8
+ # Association to template
9
+ t.integer :notification_template_id, index: true
10
+
11
+ # Kind
12
+ t.string :kind
13
+
14
+ # Message
15
+ t.string :subject
16
+ t.text :message
17
+
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
+ end
27
+ end
28
+ end
@@ -0,0 +1,21 @@
1
+ class CreateNotificationReceivers < ActiveRecord::Migration
2
+ def change
3
+ create_table :notification_receivers do |t|
4
+
5
+ # Timestamps
6
+ t.timestamps null: true
7
+ t.datetime :sent_at
8
+ t.datetime :received_at
9
+
10
+ # Relations
11
+ t.integer :notification_delivery_id, index: true
12
+ t.integer :receiver_id, index: true
13
+ t.string :receiver_type, index: true
14
+
15
+ # State
16
+ t.string :state
17
+ t.string :error_message
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ class CreateNotificationTemplates < ActiveRecord::Migration
2
+ def change
3
+ create_table :notification_templates do |t|
4
+
5
+ # Timestamps
6
+ t.timestamps null: true
7
+
8
+ # Identification
9
+ t.string :ref
10
+
11
+ # Message
12
+ t.string :subject
13
+ t.text :message
14
+
15
+ # Handlers
16
+ t.boolean :disabled
17
+ t.boolean :dry
18
+
19
+ end
20
+ end
21
+ end