tolliver 1.0.0 → 2.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 (39) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +21 -11
  3. data/app/models/tolliver/notification.rb +0 -1
  4. data/app/models/tolliver/notification_attachment.rb +16 -0
  5. data/app/models/tolliver/notification_delivery.rb +1 -3
  6. data/app/models/tolliver/notification_receiver.rb +0 -2
  7. data/app/models/tolliver/notification_template.rb +0 -1
  8. data/app/views/{notification_mailer → tolliver/notification_mailer}/notify.html.erb +0 -0
  9. data/app/views/tolliver/notification_mailer/notify.text.erb +1 -0
  10. data/config/locales/en.yml +1 -1
  11. data/db/migrate/20160121093817_create_notifications.rb +1 -12
  12. data/db/migrate/20160121094838_create_notification_receivers.rb +6 -4
  13. data/db/migrate/20160509144238_create_notification_templates.rb +4 -4
  14. data/db/migrate/20170630190600_create_notification_deliveries.rb +10 -3
  15. data/db/migrate/20201027150000_create_notification_attachments.rb +17 -0
  16. data/lib/tolliver.rb +44 -47
  17. data/lib/tolliver/errors/bad_request.rb +17 -0
  18. data/lib/tolliver/errors/not_found.rb +17 -0
  19. data/lib/tolliver/errors/standard_error.rb +17 -0
  20. data/lib/tolliver/mailers/notification_mailer.rb +10 -13
  21. data/lib/tolliver/models/notification.rb +11 -64
  22. data/lib/tolliver/models/notification_attachment.rb +35 -0
  23. data/lib/tolliver/models/notification_delivery.rb +32 -40
  24. data/lib/tolliver/models/notification_receiver.rb +3 -25
  25. data/lib/tolliver/models/notification_template.rb +6 -10
  26. data/lib/tolliver/services/delivery.rb +52 -8
  27. data/lib/tolliver/services/methods/email.rb +42 -0
  28. data/lib/tolliver/services/methods/sms.rb +51 -0
  29. data/lib/tolliver/services/methods/sms/plivo.rb +51 -0
  30. data/lib/tolliver/services/notification.rb +109 -178
  31. data/lib/tolliver/services/policies/batch.rb +90 -0
  32. data/lib/tolliver/services/policies/instantly.rb +50 -0
  33. metadata +20 -14
  34. data/app/views/notification_mailer/notify.text.erb +0 -1
  35. data/lib/tolliver/models/notification_delivery/batch.rb +0 -77
  36. data/lib/tolliver/models/notification_delivery/instantly.rb +0 -55
  37. data/lib/tolliver/models/notification_receiver/email.rb +0 -46
  38. data/lib/tolliver/models/notification_receiver/sms.rb +0 -45
  39. data/lib/tolliver/services/sms/plivo.rb +0 -49
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6b51e98fd8b3ff0cdfbb2a9e4c3461367d91e84603b8f0dbc173520c34d2625e
4
- data.tar.gz: 2cfc09c23fc2e2911c3c6c0bb6f3095a6a929c513fc837e23e9043614dc6682d
3
+ metadata.gz: 560d3dcb05343bbf964e6a418c95bc4960d7cd9ba6e8e01698455a93077a99ed
4
+ data.tar.gz: 8365863b679d97581dbd9d2288dd4043f4040a283e4f649ce1b86ba4aa882454
5
5
  SHA512:
6
- metadata.gz: bb9d2b1a57c832ee8b6d24859ada4760bc5b8405c799df7dc28ca252b7bb8dd5cc8a3fdb92df530cc2d12e16072bd49afc1f041eddb7f27c409fe25da3d9ef6a
7
- data.tar.gz: e55ef50ab51b8cc260f3e26c542719109ef2a1518dc775b6c2541b0a0d474dd1263894d973ac40784f70e028a9e35751c5502519b56aa62f779b2088fb8bb462
6
+ metadata.gz: 353704eedb8fd167d864ac1d19fd738eb81fd644bfe3072ee78d4b08087a0d04f699acbd3c75d2487505f399a95856cf5bfdd80ed49f10fbf42eb6d17eb60bd6
7
+ data.tar.gz: 719f0dc978ab83ecbb6eba6c0a1814d52318b3b3f18c5d415249ba475478767aaf75cea4b210666dc0f7eefa40c00657e86d6585f47076525aa094dd23011b5d
data/README.md CHANGED
@@ -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 "tolliver"
15
+ gem 'tolliver'
16
16
  ```
17
17
 
18
18
  Add database migrations to you application (you can modify DB structure accordingly before migrating):
@@ -26,31 +26,41 @@ You can configure module through `config/initializers/tolliver.rb` file:
26
26
 
27
27
  ```ruby
28
28
  Tolliver.setup do |config|
29
- config.mailer_sender = "no-reply@domain.com"
30
- config.delivery_kinds = [
29
+ config.mailer_sender = 'no-reply@domain.com'
30
+ config.delivery_methods = [
31
31
  :email
32
32
  ]
33
- config.template_refs = [
34
- :user_new_password,
35
- ]
36
33
  end
37
34
  ```
38
35
 
39
36
  Available options:
40
37
 
41
38
  - notification_model
39
+ - notification_attachment_model
42
40
  - notification_delivery_model
43
41
  - notification_receiver_model
44
42
  - notification_template_model
45
- - people_selector_model
46
- - mailer_sender
47
- - delivery_kinds
48
- - template_refs
43
+ - email_sender
44
+ - email_sender_name
45
+ - sms_sender
46
+ - sms_provider
47
+ - sms_provider_params
48
+ - delivery_methods
49
49
 
50
50
  ## Usage
51
51
 
52
52
  To enter new notification into the system, just call `notify` method:
53
53
 
54
54
  ```ruby
55
- Tolliver.notify([:sample_notification_ref, param_1, param_2], [receiver_1, receiver_2], options)
55
+ Tolliver.notify(
56
+ template: :template_ref,
57
+ params: [
58
+ {key: :key_1, value: :value_1},
59
+ {key: :key_2, value: :value_2}
60
+ ],
61
+ receivers: [
62
+ {ref: :receiver_1, contact: "receiver_1@domain.tld"},
63
+ {ref: :receiver_2, contact: "receiver_2@domain.tld"},
64
+ ]
65
+ )
56
66
  ```
@@ -11,7 +11,6 @@
11
11
 
12
12
  module Tolliver
13
13
  class Notification < ActiveRecord::Base
14
- include Tolliver::Utils::Enum
15
14
  include Tolliver::Models::Notification
16
15
  end
17
16
  end
@@ -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 receiver
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
@@ -11,7 +11,6 @@
11
11
 
12
12
  module Tolliver
13
13
  class NotificationTemplate < ActiveRecord::Base
14
- include Tolliver::Utils::Enum
15
14
  include Tolliver::Models::NotificationTemplate
16
15
  end
17
16
  end
@@ -0,0 +1 @@
1
+ <%= ActionController::Base.helpers.strip_tags(@notification.message.to_s) %>
@@ -11,7 +11,7 @@ en:
11
11
  kind_values:
12
12
  notice: Information
13
13
  alert: Error
14
- warning: Worning
14
+ warning: Warning
15
15
  sender: Sender
16
16
  sent_at: Sent
17
17
  done: Done
@@ -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
- t.integer :receiver_id, index: true
13
- t.string :receiver_type, index: true
12
+
13
+ # Receiver
14
+ t.string :receiver_ref, index: true
15
+ t.string :receiver_contact
14
16
 
15
17
  # State
16
- t.string :state
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 :disabled
17
- t.boolean :dry
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 kind (email, SMS, mailboxer, ...)
13
- t.string :kind
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
@@ -14,17 +14,18 @@ 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
23
  require "tolliver/services/notification"
27
24
  require "tolliver/services/delivery"
25
+ require "tolliver/services/policies/batch"
26
+ require "tolliver/services/policies/instantly"
27
+ require "tolliver/services/methods/email"
28
+ require "tolliver/services/methods/sms"
28
29
 
29
30
  # Mailers
30
31
  require "tolliver/mailers/notification_mailer"
@@ -32,6 +33,11 @@ require "tolliver/mailers/notification_mailer"
32
33
  # Utils
33
34
  require "tolliver/utils/enum"
34
35
 
36
+ # Errors
37
+ require "tolliver/errors/standard_error"
38
+ require "tolliver/errors/bad_request"
39
+ require "tolliver/errors/not_found"
40
+
35
41
  module Tolliver
36
42
 
37
43
  # This will keep Rails Engine from generating all table prefixes with the engines name
@@ -42,8 +48,21 @@ module Tolliver
42
48
  # Services
43
49
  # *************************************************************************
44
50
 
45
- include Tolliver::Services::Notification
46
- include Tolliver::Services::Delivery
51
+ def self.notify(options)
52
+ Tolliver::Services::Notification.instance.notify(options)
53
+ end
54
+
55
+ def self.deliver(notification)
56
+ Tolliver::Services::Delivery.instance.deliver(notification)
57
+ end
58
+
59
+ def self.enqueue_for_delivery(notification)
60
+ Tolliver::Services::Delivery.instance.enqueue_for_delivery(notification)
61
+ end
62
+
63
+ def self.reset_delivery(notification)
64
+ Tolliver::Services::Delivery.instance.reset_delivery(notification)
65
+ end
47
66
 
48
67
  # *************************************************************************
49
68
  # Configuration
@@ -54,18 +73,6 @@ module Tolliver
54
73
  yield self
55
74
  end
56
75
 
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
76
  # *************************************************************************
70
77
  # Config options
71
78
  # *************************************************************************
@@ -79,6 +86,15 @@ module Tolliver
79
86
 
80
87
  @@notification_model = "Tolliver::Notification"
81
88
 
89
+ # Notification attachment model
90
+ mattr_accessor :notification_attachment_model
91
+
92
+ def self.notification_attachment_model
93
+ return @@notification_attachment_model.constantize
94
+ end
95
+
96
+ @@notification_attachment_model = "Tolliver::NotificationAttachment"
97
+
82
98
  # Notification delivery model
83
99
  mattr_accessor :notification_delivery_model
84
100
 
@@ -106,33 +122,14 @@ module Tolliver
106
122
 
107
123
  @@notification_template_model = "Tolliver::NotificationTemplate"
108
124
 
109
- # People selector model
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
125
+ # Delivery methods
129
126
  #
130
- # Available kinds:
127
+ # Available methods:
131
128
  # - email
132
129
  # - sms
133
130
  # - whatever
134
- mattr_accessor :delivery_kinds
135
- @@delivery_kinds = [
131
+ mattr_accessor :delivery_methods
132
+ @@delivery_methods = [
136
133
  :email
137
134
  ]
138
135
 
@@ -144,13 +141,13 @@ module Tolliver
144
141
  mattr_accessor :load_balance
145
142
  @@load_balance = nil
146
143
 
147
- # Mailer sender
148
- mattr_accessor :mailer_sender
149
- #@@mailer_sender = "test@domain.com" to be set in module initializer if needed
144
+ # E-mail sender
145
+ mattr_accessor :email_sender
146
+ #@@email_sender = "test@domain.com" to be set in module initializer if needed
150
147
 
151
- # Mailer sender name
152
- mattr_accessor :mailer_sender_name
153
- #@@mailer_sender_name = "Test sender" to be set in module initializer if needed
148
+ # E-mail sender name
149
+ mattr_accessor :email_sender_name
150
+ #@@email_sender_name = "Test sender" to be set in module initializer if needed
154
151
 
155
152
  # Used SMS provider
156
153
  mattr_accessor :sms_provider
@@ -0,0 +1,17 @@
1
+ # *****************************************************************************
2
+ # * Copyright (c) 2019 Matěj Outlý
3
+ # *****************************************************************************
4
+ # *
5
+ # * Bar request error
6
+ # *
7
+ # * Author: Matěj Outlý
8
+ # * Date : 19. 4. 2017
9
+ # *
10
+ # *****************************************************************************
11
+
12
+ module Tolliver
13
+ module Errors
14
+ class BadRequest < StandardError
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ # *****************************************************************************
2
+ # * Copyright (c) 2019 Matěj Outlý
3
+ # *****************************************************************************
4
+ # *
5
+ # * Not found error
6
+ # *
7
+ # * Author: Matěj Outlý
8
+ # * Date : 19. 4. 2017
9
+ # *
10
+ # *****************************************************************************
11
+
12
+ module Tolliver
13
+ module Errors
14
+ class NotFound < StandardError
15
+ end
16
+ end
17
+ end