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.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +56 -0
- data/app/mailers/tolliver/notification_mailer.rb +16 -0
- data/app/models/tolliver/notification.rb +17 -0
- data/app/models/tolliver/notification_delivery.rb +19 -0
- data/app/models/tolliver/notification_receiver.rb +19 -0
- data/app/models/tolliver/notification_template.rb +17 -0
- data/app/views/notification_mailer/notify.html.erb +1 -0
- data/app/views/notification_mailer/notify.text.erb +1 -0
- data/config/locales/cs.yml +86 -0
- data/config/locales/en.yml +86 -0
- data/config/routes.rb +13 -0
- data/db/migrate/20160121093817_create_notifications.rb +28 -0
- data/db/migrate/20160121094838_create_notification_receivers.rb +21 -0
- data/db/migrate/20160509144238_create_notification_templates.rb +21 -0
- data/db/migrate/20170630190600_create_notification_deliveries.rb +20 -0
- data/lib/tolliver.rb +167 -0
- data/lib/tolliver/engine.rb +17 -0
- data/lib/tolliver/mailers/notification_mailer.rb +44 -0
- data/lib/tolliver/models/notification.rb +121 -0
- data/lib/tolliver/models/notification_delivery.rb +112 -0
- data/lib/tolliver/models/notification_delivery/batch.rb +77 -0
- data/lib/tolliver/models/notification_delivery/instantly.rb +55 -0
- data/lib/tolliver/models/notification_receiver.rb +76 -0
- data/lib/tolliver/models/notification_receiver/email.rb +46 -0
- data/lib/tolliver/models/notification_receiver/sms.rb +45 -0
- data/lib/tolliver/models/notification_template.rb +54 -0
- data/lib/tolliver/services/delivery.rb +30 -0
- data/lib/tolliver/services/notification.rb +234 -0
- data/lib/tolliver/services/sms/plivo.rb +49 -0
- data/lib/tolliver/utils/enum.rb +133 -0
- metadata +89 -0
@@ -0,0 +1,49 @@
|
|
1
|
+
# *****************************************************************************
|
2
|
+
# * Copyright (c) 2019 Matěj Outlý
|
3
|
+
# *****************************************************************************
|
4
|
+
# *
|
5
|
+
# * Plivo SMS provider
|
6
|
+
# *
|
7
|
+
# * Author: Matěj Outlý
|
8
|
+
# * Date : 1. 12. 2017
|
9
|
+
# *
|
10
|
+
# *****************************************************************************
|
11
|
+
|
12
|
+
require "plivo"
|
13
|
+
|
14
|
+
module Tolliver
|
15
|
+
module Services
|
16
|
+
module Sms
|
17
|
+
class Plivo
|
18
|
+
|
19
|
+
def initialize(params = {})
|
20
|
+
if params[:auth_id].blank? || params[:auth_token].blank?
|
21
|
+
raise "Please provide Auth ID and Auth Token in provider params."
|
22
|
+
end
|
23
|
+
@auth_id = params[:auth_id]
|
24
|
+
@auth_token = params[:auth_token]
|
25
|
+
@api = ::Plivo::RestAPI.new(@auth_id, @auth_token)
|
26
|
+
end
|
27
|
+
|
28
|
+
def deliver(receiver, message)
|
29
|
+
|
30
|
+
# Check message length.
|
31
|
+
if message.bytesize > 200
|
32
|
+
raise "Message too long."
|
33
|
+
end
|
34
|
+
|
35
|
+
# Request API
|
36
|
+
response = @api.send_message({
|
37
|
+
"src" => Tolliver.sms_sender, # TODO: This should be improved to take sender from number pool and remember number / message mapping
|
38
|
+
"dst" => receiver.to_s,
|
39
|
+
"text" => message.to_s,
|
40
|
+
"method" => "POST"
|
41
|
+
})
|
42
|
+
|
43
|
+
return true
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
# *****************************************************************************
|
2
|
+
# * Copyright (c) 2019 Matěj Outlý
|
3
|
+
# *****************************************************************************
|
4
|
+
# *
|
5
|
+
# * Enum definition
|
6
|
+
# *
|
7
|
+
# * Author: Matěj Outlý
|
8
|
+
# * Date : 7. 1. 2015
|
9
|
+
# *
|
10
|
+
# *****************************************************************************
|
11
|
+
|
12
|
+
require "active_record"
|
13
|
+
|
14
|
+
module Tolliver
|
15
|
+
module Utils
|
16
|
+
module Enum
|
17
|
+
extend ActiveSupport::Concern
|
18
|
+
|
19
|
+
module ClassMethods
|
20
|
+
|
21
|
+
# Add new enum column
|
22
|
+
def enum_column(new_column, spec, options = {})
|
23
|
+
|
24
|
+
# Prepare internal structure
|
25
|
+
if @enums.nil?
|
26
|
+
@enums = {}
|
27
|
+
end
|
28
|
+
@enums[new_column] = {}
|
29
|
+
|
30
|
+
# Fill out internal structure
|
31
|
+
spec.each do |item|
|
32
|
+
|
33
|
+
# Value check
|
34
|
+
if item.is_a?(OpenStruct)
|
35
|
+
item = item.to_h
|
36
|
+
elsif item.is_a? Hash
|
37
|
+
# OK
|
38
|
+
else
|
39
|
+
item = {value: item}
|
40
|
+
end
|
41
|
+
unless item[:value]
|
42
|
+
raise "Enum definition cannot be empty."
|
43
|
+
end
|
44
|
+
|
45
|
+
# Identify special type
|
46
|
+
item[:special_type] = :integer if item[:value].is_a?(Integer)
|
47
|
+
|
48
|
+
# Retype to string
|
49
|
+
item[:value] = item[:value].to_s
|
50
|
+
|
51
|
+
# Label
|
52
|
+
unless item[:label]
|
53
|
+
item[:label] = I18n.t("activerecord.attributes.#{model_name.i18n_key}.#{new_column.to_s}_values.#{item[:special_type] ? item[:special_type].to_s + "_" : ""}#{item[:value]}")
|
54
|
+
end
|
55
|
+
|
56
|
+
# Other attributes
|
57
|
+
if options[:attributes]
|
58
|
+
options[:attributes].each do |attribute|
|
59
|
+
singular_attribute_name = attribute.to_s.singularize
|
60
|
+
plural_attribute_name = attribute.to_s.pluralize
|
61
|
+
if item[singular_attribute_name.to_sym].nil?
|
62
|
+
item[singular_attribute_name.to_sym] = I18n.t("activerecord.attributes.#{model_name.i18n_key}.#{new_column.to_s}_#{plural_attribute_name}.#{item[:special_type] ? item[:special_type].to_s + "_" : ""}#{item[:value]}")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# Store
|
68
|
+
@enums[new_column][item[:value].to_s] = OpenStruct.new(item)
|
69
|
+
end
|
70
|
+
|
71
|
+
# Obj method
|
72
|
+
define_method((new_column.to_s + "_obj").to_sym) do
|
73
|
+
column = new_column
|
74
|
+
|
75
|
+
# Get map Value => Object
|
76
|
+
enums = self.class.enums[column]
|
77
|
+
|
78
|
+
# Get possible special type
|
79
|
+
special_type = enums.values.first.special_type if enums.first && enums.values.first.special_type
|
80
|
+
|
81
|
+
# Get value and modify it according to special type
|
82
|
+
value = self.send(column)
|
83
|
+
value = value.to_i if special_type == :integer
|
84
|
+
|
85
|
+
return self.class.enums[column][value.to_s]
|
86
|
+
end
|
87
|
+
|
88
|
+
# All method
|
89
|
+
define_singleton_method(("available_" + new_column.to_s.pluralize).to_sym) do
|
90
|
+
column = new_column
|
91
|
+
return @enums[column].values
|
92
|
+
end
|
93
|
+
|
94
|
+
# All values method
|
95
|
+
define_singleton_method(("available_" + new_column.to_s + "_values").to_sym) do
|
96
|
+
column = new_column
|
97
|
+
return @enums[column].values.map { |o| o.value.to_sym }
|
98
|
+
end
|
99
|
+
|
100
|
+
# Label method
|
101
|
+
define_singleton_method((new_column.to_s + "_label").to_sym) do |value|
|
102
|
+
column = new_column
|
103
|
+
return @enums[column].values.select { |o| o.value.to_s == value.to_s }.map { |o| o.label }.first
|
104
|
+
end
|
105
|
+
|
106
|
+
# Default value
|
107
|
+
if options[:default]
|
108
|
+
before_validation do
|
109
|
+
column = new_column
|
110
|
+
default = options[:default]
|
111
|
+
if self.send(column).nil?
|
112
|
+
self.send(column.to_s + "=", default.to_s)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
# Get all defined enums
|
120
|
+
def enums
|
121
|
+
@enums
|
122
|
+
end
|
123
|
+
|
124
|
+
# Check if given column is enum defined on this model
|
125
|
+
def has_enum?(column)
|
126
|
+
!@enums.nil? && !@enums[column].nil?
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tolliver
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matěj Outlý
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-04-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.2'
|
27
|
+
description: Tolliver is an engine for event notification and distribution among users
|
28
|
+
via e-mail, SMS or other 3rd party systems.
|
29
|
+
email:
|
30
|
+
- matej.outly@gmail.com
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- LICENSE
|
36
|
+
- README.md
|
37
|
+
- app/mailers/tolliver/notification_mailer.rb
|
38
|
+
- app/models/tolliver/notification.rb
|
39
|
+
- app/models/tolliver/notification_delivery.rb
|
40
|
+
- app/models/tolliver/notification_receiver.rb
|
41
|
+
- app/models/tolliver/notification_template.rb
|
42
|
+
- app/views/notification_mailer/notify.html.erb
|
43
|
+
- app/views/notification_mailer/notify.text.erb
|
44
|
+
- config/locales/cs.yml
|
45
|
+
- config/locales/en.yml
|
46
|
+
- config/routes.rb
|
47
|
+
- db/migrate/20160121093817_create_notifications.rb
|
48
|
+
- db/migrate/20160121094838_create_notification_receivers.rb
|
49
|
+
- db/migrate/20160509144238_create_notification_templates.rb
|
50
|
+
- db/migrate/20170630190600_create_notification_deliveries.rb
|
51
|
+
- lib/tolliver.rb
|
52
|
+
- lib/tolliver/engine.rb
|
53
|
+
- lib/tolliver/mailers/notification_mailer.rb
|
54
|
+
- lib/tolliver/models/notification.rb
|
55
|
+
- lib/tolliver/models/notification_delivery.rb
|
56
|
+
- lib/tolliver/models/notification_delivery/batch.rb
|
57
|
+
- lib/tolliver/models/notification_delivery/instantly.rb
|
58
|
+
- lib/tolliver/models/notification_receiver.rb
|
59
|
+
- lib/tolliver/models/notification_receiver/email.rb
|
60
|
+
- lib/tolliver/models/notification_receiver/sms.rb
|
61
|
+
- lib/tolliver/models/notification_template.rb
|
62
|
+
- lib/tolliver/services/delivery.rb
|
63
|
+
- lib/tolliver/services/notification.rb
|
64
|
+
- lib/tolliver/services/sms/plivo.rb
|
65
|
+
- lib/tolliver/utils/enum.rb
|
66
|
+
homepage: https://github.com/matej-outly/tolliver
|
67
|
+
licenses:
|
68
|
+
- MIT
|
69
|
+
metadata: {}
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubygems_version: 3.0.6
|
86
|
+
signing_key:
|
87
|
+
specification_version: 4
|
88
|
+
summary: Event notification and distribution
|
89
|
+
test_files: []
|