hey-you 1.0.0 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -4
- data/CHANGELOG.md +17 -0
- data/README.md +69 -12
- data/hey_you.gemspec +1 -1
- data/lib/hey_you/builder.rb +11 -2
- data/lib/hey_you/builder/_base.rb +6 -3
- data/lib/hey_you/builder/email.rb +4 -0
- data/lib/hey_you/builder/push.rb +4 -0
- data/lib/hey_you/channels/email.rb +4 -4
- data/lib/hey_you/config.rb +8 -24
- data/lib/hey_you/config/data_source.rb +38 -0
- data/lib/hey_you/data_source/_base.rb +9 -0
- data/lib/hey_you/data_source/hash.rb +17 -0
- data/lib/hey_you/data_source/yaml.rb +37 -0
- data/lib/hey_you/receiver.rb +2 -0
- data/lib/hey_you/sender.rb +14 -6
- data/lib/hey_you/version.rb +1 -1
- metadata +10 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e45a6c6dcd683af58756e5bc3702ac92e0cd7e0f4fefb469f356002334f33fce
|
4
|
+
data.tar.gz: b8144f42b5cac765f8610ab05e046524e2ac9a4c5e47f08a7e6f4e7a409c309f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a96ab10f4b7dd0c0a07d6e16be547f2c97d2f51f7bf5be91386541fddde61f7739154d3867695ce7e814d6974b1377e4fa64e98239c4ab296ffff20dfe2602c8
|
7
|
+
data.tar.gz: e1cdb47a072bd632ea89ee6e072bc49afac86abaf570666ce92b2392b10787268552d1b599bdcb059da3488b7cc19c898b72dc3859730ab48514785291e44adf
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# Changelog for hey-you gem
|
2
|
+
|
3
|
+
### 1.2.3
|
4
|
+
- Improvement: fix ruby 2.7 warnings
|
5
|
+
- Fix: fix `NoMethodError` in `sender.rb` when channel must be ignored by `if`
|
6
|
+
|
7
|
+
### 1.2.2
|
8
|
+
- Improvement: `if` condition for receiver (if condition `false` - sending will be skipped).
|
9
|
+
- Improvement: `force` option - send message independent on `if` condition.
|
10
|
+
|
11
|
+
|
12
|
+
### 1.2.1
|
13
|
+
- Improvement: Builder will not make channel builder if it skipped by only option
|
14
|
+
|
15
|
+
### 1.2.0
|
16
|
+
- Feature: data source extensions (check readme for more information).
|
17
|
+
__Attention__: You should rewrite your configuration for use yaml data source!
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# HeyYou
|
1
|
+
# HeyYou
|
2
2
|
[![Build Status](https://travis-ci.com/QNester/hey-you.svg?branch=master)](https://travis-ci.com/QNester/hey-you#)
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/hey-you.svg)](https://badge.fury.io/rb/hey-you)
|
4
4
|
|
@@ -20,7 +20,7 @@ him easy.
|
|
20
20
|
|
21
21
|
|
22
22
|
## Requirements
|
23
|
-
* Ruby 2.
|
23
|
+
* Ruby 2.5.0 min (rspec works with ruby 2.5.0, 2.6.0, 2.7.0)
|
24
24
|
* FCM - Gem send push notification using [fcm gem](https://github.com/spacialdb/fcm).
|
25
25
|
You need *fcm server key* to successful configure push notifications.
|
26
26
|
|
@@ -44,15 +44,20 @@ Or install it yourself as:
|
|
44
44
|
First, you must configure HeyYou. Example:
|
45
45
|
```ruby
|
46
46
|
HeyYou::Config.configure do
|
47
|
-
config.
|
47
|
+
config.data_source.options = { collection_files: ['config/notifications.yml'] }
|
48
48
|
config.email.from = 'noreply@example-mail.com'
|
49
49
|
config.push.fcm_token = 'fcm_server_key'
|
50
50
|
end
|
51
51
|
```
|
52
52
|
#### Required settings
|
53
53
|
Options for gem base work.
|
54
|
-
#####
|
55
|
-
* __config.
|
54
|
+
##### Data Source
|
55
|
+
* __config.data_source.source_class__ - Class implemented instance method `load_collections` returning hash (by default `HeyYou::DataSource::Yaml`)
|
56
|
+
* __config.data_source.options__ - Arguments for source_class. This options will be passed to init `source_class`
|
57
|
+
OR
|
58
|
+
* __config.data_source.source_instance__ - Instance of source class implemented `load_collections`
|
59
|
+
|
60
|
+
Read more about data source in [data source](#data-source-1).d
|
56
61
|
##### Push
|
57
62
|
* __config.push.fcm_token__ - Required setting for push channel. You can not send
|
58
63
|
push messages if setting was not set. You should set it to equal your fcm server key.
|
@@ -62,8 +67,6 @@ push messages if setting was not set. You should set it to equal your fcm server
|
|
62
67
|
#### Optional settings
|
63
68
|
Additional options for configure your notifications.
|
64
69
|
#### Base
|
65
|
-
* __config.env_collection_file__ - File contained all your notifications texts for
|
66
|
-
environment. You can set it like `notifications.#{ENV['APP_ENV]}.yml`
|
67
70
|
* __config.splitter__ - Chars for split notification keys for
|
68
71
|
builder. Default: `.`
|
69
72
|
* __config.registered_channels__ - Avialable channels for your
|
@@ -77,9 +80,10 @@ notifications for build should be nested in `I18n.locale` key. Default: `false`.
|
|
77
80
|
# config/initializers/hey-you.rb
|
78
81
|
HeyYou::Config.configure do
|
79
82
|
...
|
80
|
-
|
83
|
+
i18n_files = Rails.application.config.i18n.available_locales.map do |locale|
|
81
84
|
"config/notifications/#{locale}.yml"
|
82
85
|
end
|
86
|
+
config.data_source.options = { collection_files: i18n_files }
|
83
87
|
...
|
84
88
|
end
|
85
89
|
```
|
@@ -159,8 +163,8 @@ fetching values required to send notification. For push channel
|
|
159
163
|
expected that proc will return receiver's fcm registration id. For
|
160
164
|
email expected that proc will return receiver's email address.
|
161
165
|
|
162
|
-
You can pass options for receiver channels. You must pass proc with receive_data to `:subject` key and options
|
163
|
-
pass to `:options` key:
|
166
|
+
You can pass options and sending condition for receiver channels. You must pass proc with receive_data to `:subject` key and options
|
167
|
+
pass to `:options` key. `if` key should be passed for sending condition:
|
164
168
|
|
165
169
|
```ruby
|
166
170
|
class User < Model
|
@@ -168,7 +172,11 @@ class User < Model
|
|
168
172
|
|
169
173
|
receive(
|
170
174
|
push: -> { push_token.value },
|
171
|
-
email: {
|
175
|
+
email: {
|
176
|
+
subject: -> { email },
|
177
|
+
if: -> { email_notifications? },
|
178
|
+
options: { mailer_class: UserMailer, mailer_method: :notify! }
|
179
|
+
}
|
172
180
|
)
|
173
181
|
end
|
174
182
|
```
|
@@ -185,9 +193,18 @@ Last command will fetch notifications credentials for user instance
|
|
185
193
|
and will try to send SMS, Push and Email for it. What argument we pass
|
186
194
|
for method? This is string key for builder. Read next to understand it.
|
187
195
|
|
196
|
+
Sometimes you need send notification independent on user's notification settings. For this case you can use
|
197
|
+
`force` option in `#send_notification`:
|
198
|
+
```ruby
|
199
|
+
user = User.find(1)
|
200
|
+
user.settings.update!(email_notifications: false)
|
201
|
+
user.send_notification('for_users.hello') #=> will not send notification
|
202
|
+
user.send_notification('for_users.hello', force: true) #=> will send notification
|
203
|
+
```
|
204
|
+
|
188
205
|
### Build your notification
|
189
206
|
HeyYou Notification Builder - good system for store your notifications in one place.
|
190
|
-
|
207
|
+
By default you need create yml file with follow format:
|
191
208
|
```yaml
|
192
209
|
# config/notifications/collection.yml
|
193
210
|
any_key:
|
@@ -214,6 +231,46 @@ notification will send for all available channels for receiver:
|
|
214
231
|
1) Send push via fcm
|
215
232
|
2) Send email
|
216
233
|
|
234
|
+
#### Data Source
|
235
|
+
Often we need store our notification text in another data source, not int yml files. HeyYou has flexible
|
236
|
+
system for data source. All what you need - make your own provider source and pass it to config. For example:
|
237
|
+
|
238
|
+
```ruby
|
239
|
+
class NotificationText < ApplicationRecord
|
240
|
+
def self.load_collections
|
241
|
+
# load colelctions from database to hash
|
242
|
+
# THIS METHOD MUST returns hash!
|
243
|
+
end
|
244
|
+
end
|
245
|
+
```
|
246
|
+
|
247
|
+
```ruby
|
248
|
+
HeyYou::Config.configure do
|
249
|
+
# NotificationText is a rails model
|
250
|
+
config.data_source.source_instance = NotificationText
|
251
|
+
end
|
252
|
+
```
|
253
|
+
|
254
|
+
HeyYou will pull texts from database to memory with initialize your application after this configuration. Builder
|
255
|
+
will build your texts successfully.
|
256
|
+
|
257
|
+
HeyYou by default contains only two data sources:
|
258
|
+
1. `HeyYou::DataSource::Yaml` - for store notifications collections in data. For example:
|
259
|
+
```ruby
|
260
|
+
HeyYou::Config.configure do
|
261
|
+
config.data_source.source_class = HeyYou::DataSource::Yaml
|
262
|
+
config.data_source.options = { collection_files: ['config/notifications.yml'] }
|
263
|
+
end
|
264
|
+
```
|
265
|
+
2. `HeyYou::DataSource::Hash` - store notification everywhere you want and pass to HeyYou only hash
|
266
|
+
```ruby
|
267
|
+
config.data_source.source_class = HeyYou::DataSource::Yaml
|
268
|
+
config.data_source.options = { data: { welcome: { email: { ... }, push: { ... } } } }
|
269
|
+
```
|
270
|
+
|
271
|
+
__Pay attention__: for difference source we should pass difference options.
|
272
|
+
|
273
|
+
|
217
274
|
### Send notification
|
218
275
|
Receiver not only one way to send notification. You can send it using `HeyYou::Sender`.
|
219
276
|
Just use method `#send` for HeyYou::Sender and pass notification key and `to` options
|
data/hey_you.gemspec
CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.add_runtime_dependency "mail", '~> 2.7'
|
27
27
|
spec.add_runtime_dependency "i18n", '~> 1.0'
|
28
28
|
|
29
|
-
spec.add_development_dependency "rake", '~>
|
29
|
+
spec.add_development_dependency "rake", '~> 13.0'
|
30
30
|
spec.add_development_dependency "rspec", '~> 3.7'
|
31
31
|
spec.add_development_dependency "webmock", '~> 3.4'
|
32
32
|
spec.add_development_dependency "ffaker", '~> 2.9'
|
data/lib/hey_you/builder.rb
CHANGED
@@ -13,11 +13,14 @@ module HeyYou
|
|
13
13
|
# Define methods for each registered channel. After initialize you can use
|
14
14
|
# `instance.<ch_name>`. It will be return instance of HeyYou::Builder::<YOUR_CHANNEL_NAME>
|
15
15
|
#
|
16
|
+
# Skip builder for excluded channels (not included in `only` option)
|
17
|
+
#
|
18
|
+
# @param [String] key - notification key for fetching notification data from collection
|
16
19
|
def initialize(key, **options)
|
17
20
|
@data = fetch_from_collection_by_key(key, options[:locale])
|
18
21
|
@options = options
|
19
22
|
config.registered_channels.each do |ch|
|
20
|
-
init_channel_builder(ch, key)
|
23
|
+
init_channel_builder(ch, key) if channel_allowed_by_only?(ch, options[:only])
|
21
24
|
end
|
22
25
|
end
|
23
26
|
|
@@ -35,7 +38,7 @@ module HeyYou
|
|
35
38
|
end
|
36
39
|
|
37
40
|
ch_builder =
|
38
|
-
HeyYou::Builder.const_get("#{ch.downcase.capitalize}").new(data, key, options)
|
41
|
+
HeyYou::Builder.const_get("#{ch.downcase.capitalize}").new(data[ch.to_s], key, **options)
|
39
42
|
instance_variable_set("@#{ch}".to_sym, ch_builder)
|
40
43
|
|
41
44
|
define_ch_method(ch)
|
@@ -61,6 +64,12 @@ module HeyYou
|
|
61
64
|
raise DataNotFound, "collection data not found for `#{keys.join(config.splitter)}`"
|
62
65
|
end
|
63
66
|
|
67
|
+
def channel_allowed_by_only?(ch, only)
|
68
|
+
return true unless only
|
69
|
+
return only.map(&:to_sym).include?(ch.to_sym) if only.is_a?(Array)
|
70
|
+
only.to_sym == ch.to_sym
|
71
|
+
end
|
72
|
+
|
64
73
|
class UnknownLocale < StandardError; end
|
65
74
|
class DataNotFound < StandardError; end
|
66
75
|
class RequiredChannelNotFound < StandardError; end
|
@@ -10,6 +10,11 @@ module HeyYou
|
|
10
10
|
build
|
11
11
|
end
|
12
12
|
|
13
|
+
def to_hash
|
14
|
+
raise NotImplementedError, 'Builder not implemented #to_hash method'
|
15
|
+
end
|
16
|
+
alias_method :to_h, :to_hash
|
17
|
+
|
13
18
|
private
|
14
19
|
|
15
20
|
def interpolate(notification_string, options)
|
@@ -18,10 +23,8 @@ module HeyYou
|
|
18
23
|
raise InterpolationError, "Failed build notification string `#{notification_string}`: #{err.message}"
|
19
24
|
end
|
20
25
|
|
21
|
-
def ch_data
|
22
|
-
data.fetch(current_builder_name)
|
23
|
-
end
|
24
26
|
|
27
|
+
alias ch_data data
|
25
28
|
alias channel_data ch_data
|
26
29
|
|
27
30
|
def ch_options
|
data/lib/hey_you/builder/push.rb
CHANGED
@@ -7,19 +7,19 @@ module HeyYou
|
|
7
7
|
class << self
|
8
8
|
def send!(builder, to:, **options)
|
9
9
|
method = config.email.use_default_mailing ? :send_via_mail : :send_via_custom_class
|
10
|
-
public_send(method, builder, to, options)
|
10
|
+
public_send(method, builder, to, **options)
|
11
11
|
end
|
12
12
|
|
13
13
|
# Send email via custom class instance.
|
14
14
|
def send_via_custom_class(builder, to, **options)
|
15
|
-
mailer = mailer_class_from_builder(builder, options)
|
16
|
-
mailer_method = mailer_method_from_builder(mailer, builder, options)
|
15
|
+
mailer = mailer_class_from_builder(builder, **options)
|
16
|
+
mailer_method = mailer_method_from_builder(mailer, builder, **options)
|
17
17
|
delivery_method = options[:delivery_method] ||
|
18
18
|
builder.email.delivery_method ||
|
19
19
|
config.email.default_delivery_method
|
20
20
|
|
21
21
|
log("Build mail via #{mailer}##{mailer_method}. Delivery with #{delivery_method}")
|
22
|
-
mailer_msg = mailer.public_send(mailer_method, data: builder.email, to: to)
|
22
|
+
mailer_msg = mailer.public_send(mailer_method, data: builder.email.to_hash, to: to)
|
23
23
|
return mailer_msg.public_send(delivery_method) if mailer_msg.respond_to?(delivery_method)
|
24
24
|
raise(
|
25
25
|
DeliveryMethodNotDefined,
|
data/lib/hey_you/config.rb
CHANGED
@@ -2,6 +2,7 @@ require 'yaml'
|
|
2
2
|
require 'hey_you/config/conigurable'
|
3
3
|
require 'hey_you/config/push'
|
4
4
|
require 'hey_you/config/email'
|
5
|
+
require 'hey_you/config/data_source'
|
5
6
|
|
6
7
|
#
|
7
8
|
# @config REQUIRED collection_file [String] - File path for general notifications file
|
@@ -34,9 +35,8 @@ module HeyYou
|
|
34
35
|
|
35
36
|
attr_reader :collection, :env_collection, :configured, :registered_receivers
|
36
37
|
attr_accessor(
|
37
|
-
:
|
38
|
-
:
|
39
|
-
:require_all_channels
|
38
|
+
:splitter, :registered_channels, :localization, :logger, :log_tag,
|
39
|
+
:require_all_channels, :data_source
|
40
40
|
)
|
41
41
|
|
42
42
|
def initialize
|
@@ -49,13 +49,6 @@ module HeyYou
|
|
49
49
|
define_ch_config_methods
|
50
50
|
end
|
51
51
|
|
52
|
-
def collection_file
|
53
|
-
@collection_files || raise(
|
54
|
-
CollectionFileNotDefined,
|
55
|
-
'You must define HeyYou::Config.collection_files'
|
56
|
-
)
|
57
|
-
end
|
58
|
-
|
59
52
|
def collection
|
60
53
|
@collection ||= load_collection
|
61
54
|
end
|
@@ -84,6 +77,10 @@ module HeyYou
|
|
84
77
|
logger&.info("[#{log_tag}] #{msg} ")
|
85
78
|
end
|
86
79
|
|
80
|
+
def data_source
|
81
|
+
DataSource.instance
|
82
|
+
end
|
83
|
+
|
87
84
|
private
|
88
85
|
|
89
86
|
def define_ch_config_methods
|
@@ -101,21 +98,8 @@ module HeyYou
|
|
101
98
|
self.class.send(:define_method, ch, method_proc)
|
102
99
|
end
|
103
100
|
|
104
|
-
# Load yaml from collection_file and merge it with yaml from env_collection_file
|
105
101
|
def load_collection
|
106
|
-
|
107
|
-
notification_collection = {}
|
108
|
-
collection_files.each do |file|
|
109
|
-
notification_collection.merge!(YAML.load_file(file))
|
110
|
-
end
|
111
|
-
notification_collection.merge!(env_collection)
|
112
|
-
end
|
113
|
-
|
114
|
-
def load_env_collection
|
115
|
-
if env_collection_file
|
116
|
-
return YAML.load_file(env_collection_file) rescue { }
|
117
|
-
end
|
118
|
-
{}
|
102
|
+
data_source.load_data
|
119
103
|
end
|
120
104
|
end
|
121
105
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'hey_you/config/conigurable'
|
2
|
+
require 'hey_you/data_source/yaml'
|
3
|
+
require 'hey_you/data_source/hash'
|
4
|
+
|
5
|
+
module HeyYou
|
6
|
+
class Config
|
7
|
+
class DataSource
|
8
|
+
extend Configurable
|
9
|
+
|
10
|
+
attr_accessor :source_class, :options, :source_instance
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@type = DEFAULTS[:type]
|
14
|
+
@options = DEFAULTS[:options]
|
15
|
+
@source_class = HeyYou::DataSource::Yaml
|
16
|
+
end
|
17
|
+
|
18
|
+
def load_data
|
19
|
+
return source_instance.load_collections if source_instance
|
20
|
+
|
21
|
+
if source_class.nil?
|
22
|
+
raise InvalidDataSourceError, 'You must pass `config.data_source.source_class` in configuration.'
|
23
|
+
end
|
24
|
+
|
25
|
+
source_class.new(**options).load_collections
|
26
|
+
rescue ArgumentError => err
|
27
|
+
problem_fields =
|
28
|
+
err.message.gsub(/missing keyword(.?):\s/, '').split(', ').map { |f| "`#{f}`" }.join(', ')
|
29
|
+
field_word = problem_fields.split(', ').size > 1 ? 'fields' : 'field'
|
30
|
+
msg = "You must pass #{field_word} #{problem_fields} for `config.data_source.options` in configuration"
|
31
|
+
|
32
|
+
raise InvalidOptionsError, msg
|
33
|
+
end
|
34
|
+
|
35
|
+
class InvalidOptionsError < StandardError; end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'hey_you/data_source/_base'
|
2
|
+
|
3
|
+
module HeyYou
|
4
|
+
module DataSource
|
5
|
+
class Yaml < Base
|
6
|
+
attr_reader :collection_files, :env_collection_file
|
7
|
+
|
8
|
+
def initialize(collection_files:, env_collection_file: nil)
|
9
|
+
@collection_files = collection_files
|
10
|
+
@collection_files = [collection_files] if collection_files.is_a?(String)
|
11
|
+
@env_collection_file = env_collection_file
|
12
|
+
end
|
13
|
+
|
14
|
+
# Load yaml from collection_file and merge it with yaml from env_collection_file
|
15
|
+
def load_collections
|
16
|
+
notification_collection = {}
|
17
|
+
collection_files.each do |file|
|
18
|
+
notification_collection.merge!(YAML.load_file(file))
|
19
|
+
end
|
20
|
+
notification_collection.merge!(env_collection)
|
21
|
+
end
|
22
|
+
|
23
|
+
def env_collection
|
24
|
+
@env_collection ||= load_env_collection
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def load_env_collection
|
30
|
+
if env_collection_file
|
31
|
+
return YAML.load_file(env_collection_file) rescue { }
|
32
|
+
end
|
33
|
+
{}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/hey_you/receiver.rb
CHANGED
@@ -74,9 +74,11 @@ module HeyYou
|
|
74
74
|
if receiver_data[ch].is_a?(Hash)
|
75
75
|
me = self
|
76
76
|
self.send(:define_method, "#{ch}_ch_receive_info", receiver_data[ch].fetch(:subject))
|
77
|
+
self.send(:define_method, "#{ch}_ch_receive_condition", receiver_data[ch].fetch(:if, -> { true }))
|
77
78
|
self.send(:define_method, "#{ch}_ch_receive_options", -> { me.receiver_data[ch].fetch(:options, {}) })
|
78
79
|
else
|
79
80
|
self.send(:define_method, "#{ch}_ch_receive_info", receiver_data[ch])
|
81
|
+
self.send(:define_method, "#{ch}_ch_receive_condition", -> { true })
|
80
82
|
self.send(:define_method, "#{ch}_ch_receive_options", -> { {} })
|
81
83
|
end
|
82
84
|
end
|
data/lib/hey_you/sender.rb
CHANGED
@@ -15,6 +15,7 @@ module HeyYou
|
|
15
15
|
# @input notification_key [String] - key for notification builder
|
16
16
|
# @input options [Hash]
|
17
17
|
# @option only [String/Array[String]] - whitelist for using channels
|
18
|
+
# @option force [Boolean] - ignore `if` for receiver
|
18
19
|
#
|
19
20
|
def send_to(receiver, notification_key, **options)
|
20
21
|
unless receiver_valid?(receiver)
|
@@ -29,6 +30,10 @@ module HeyYou
|
|
29
30
|
def send!(notification_key, receiver, **options)
|
30
31
|
to_hash = {}
|
31
32
|
receiver.class.receiver_channels.each do |ch|
|
33
|
+
if !options[:force] && !receiver.public_send("#{ch}_ch_receive_condition")
|
34
|
+
next
|
35
|
+
end
|
36
|
+
|
32
37
|
to_hash[ch] = {
|
33
38
|
# Fetch receiver's info for sending: phone_number, email, etc
|
34
39
|
subject: receiver.public_send("#{ch}_ch_receive_info"),
|
@@ -37,16 +42,16 @@ module HeyYou
|
|
37
42
|
}
|
38
43
|
end
|
39
44
|
|
40
|
-
send_to_receive_info(notification_key, to_hash, options)
|
45
|
+
send_to_receive_info(notification_key, to_hash, **options)
|
41
46
|
end
|
42
47
|
|
43
48
|
def send_to_receive_info(notification_key, receive_info, **options)
|
44
|
-
builder = Builder.new(notification_key, options)
|
49
|
+
builder = Builder.new(notification_key, **options)
|
45
50
|
response = {}
|
46
51
|
config.registered_channels.each do |ch|
|
47
|
-
if channel_allowed?(ch, receive_info, builder, options) && builder.respond_to?(ch) && builder.public_send(ch)
|
52
|
+
if channel_allowed?(ch, receive_info, builder, **options) && builder.respond_to?(ch) && builder.public_send(ch)
|
48
53
|
config.log(
|
49
|
-
"Send #{ch}-message to
|
54
|
+
"Send #{ch}-message to `#{receive_info[ch][:subject]}` with data: #{builder.public_send(ch).data}" \
|
50
55
|
" and options: #{receive_info[ch][:options]}"
|
51
56
|
)
|
52
57
|
receive_options = receive_info[ch].fetch(:options, {}) || {}
|
@@ -54,7 +59,7 @@ module HeyYou
|
|
54
59
|
builder, to: receive_info[ch][:subject], **receive_options
|
55
60
|
)
|
56
61
|
else
|
57
|
-
config.log("Channel #{ch} not allowed.")
|
62
|
+
config.log("Channel #{ch} not allowed or sending condition doesn't return truthy result.")
|
58
63
|
end
|
59
64
|
end
|
60
65
|
response
|
@@ -63,7 +68,10 @@ module HeyYou
|
|
63
68
|
private
|
64
69
|
|
65
70
|
def channel_allowed?(ch, to, builder, **options)
|
66
|
-
|
71
|
+
data_in_subject = to[ch.to_sym]&.fetch(:subject, nil) || to[ch.to_s]&.fetch(:subject, nil)
|
72
|
+
data_in_core = to[ch.to_sym] || to[ch.to_s]
|
73
|
+
|
74
|
+
condition = to[ch].is_a?(Hash) ? data_in_subject : data_in_core
|
67
75
|
return false unless condition
|
68
76
|
channel_allowed_by_only?(ch, options[:only]) && !builder.send(ch).nil?
|
69
77
|
end
|
data/lib/hey_you/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hey-you
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Nesterov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fcm
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '13.0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '13.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -121,6 +121,7 @@ files:
|
|
121
121
|
- ".rspec"
|
122
122
|
- ".rubocop.yml"
|
123
123
|
- ".travis.yml"
|
124
|
+
- CHANGELOG.md
|
124
125
|
- Gemfile
|
125
126
|
- README.md
|
126
127
|
- Rakefile
|
@@ -137,8 +138,12 @@ files:
|
|
137
138
|
- lib/hey_you/channels/push.rb
|
138
139
|
- lib/hey_you/config.rb
|
139
140
|
- lib/hey_you/config/conigurable.rb
|
141
|
+
- lib/hey_you/config/data_source.rb
|
140
142
|
- lib/hey_you/config/email.rb
|
141
143
|
- lib/hey_you/config/push.rb
|
144
|
+
- lib/hey_you/data_source/_base.rb
|
145
|
+
- lib/hey_you/data_source/hash.rb
|
146
|
+
- lib/hey_you/data_source/yaml.rb
|
142
147
|
- lib/hey_you/helper.rb
|
143
148
|
- lib/hey_you/receiver.rb
|
144
149
|
- lib/hey_you/sender.rb
|
@@ -161,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
161
166
|
- !ruby/object:Gem::Version
|
162
167
|
version: '0'
|
163
168
|
requirements: []
|
164
|
-
rubygems_version: 3.
|
169
|
+
rubygems_version: 3.1.2
|
165
170
|
signing_key:
|
166
171
|
specification_version: 4
|
167
172
|
summary: Send multichannel notification with one command.
|