hey-you 1.2.1 → 1.3.4
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/CHANGELOG.md +15 -1
- data/README.md +16 -3
- data/lib/hey_you/builder.rb +1 -1
- data/lib/hey_you/builder/_base.rb +1 -3
- data/lib/hey_you/builder/email.rb +21 -4
- data/lib/hey_you/channels/email.rb +3 -3
- data/lib/hey_you/config/data_source.rb +1 -1
- data/lib/hey_you/receiver.rb +2 -0
- data/lib/hey_you/sender.rb +16 -8
- data/lib/hey_you/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: af4fe24304e8d627f618c3cc5b6e93695a2be2f4d2207034f59feb0a7ad0d906
|
|
4
|
+
data.tar.gz: b60aa9ec6a472bc008d57e472406cb00e49b2f3d5827a5a3119a494fc83cfcbb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d1cf816831a4962b2f795621585156447cb837256773f4663da7009e6d404be2488e017ab2d96944b205764416f5bd4ee3b6c4bf28c399fbe6463abdcbbe65df
|
|
7
|
+
data.tar.gz: 165f7490a9a3eb749b2c966adf412a95027995bbcdb257c86b91c02484982ad56e48a99189157abcccf07cb88081bda0af3aa8673429c599ad336d14441a1709
|
data/CHANGELOG.md
CHANGED
|
@@ -1,8 +1,22 @@
|
|
|
1
1
|
# Changelog for hey-you gem
|
|
2
|
+
## 1.3.1/1.3.2/1.3.3/1.3.4
|
|
3
|
+
Fixing bugs
|
|
4
|
+
|
|
5
|
+
## 1.3.0
|
|
6
|
+
- Feature: `body_part` in email builder.
|
|
7
|
+
|
|
8
|
+
### 1.2.3
|
|
9
|
+
- Improvement: fix ruby 2.7 warnings
|
|
10
|
+
- Fix: fix `NoMethodError` in `sender.rb` when channel must be ignored by `if`
|
|
11
|
+
|
|
12
|
+
### 1.2.2
|
|
13
|
+
- Improvement: `if` condition for receiver (if condition `false` - sending will be skipped).
|
|
14
|
+
- Improvement: `force` option - send message independent on `if` condition.
|
|
15
|
+
|
|
2
16
|
|
|
3
17
|
### 1.2.1
|
|
4
18
|
- Improvement: Builder will not make channel builder if it skipped by only option
|
|
5
19
|
|
|
6
20
|
### 1.2.0
|
|
7
21
|
- Feature: data source extensions (check readme for more information).
|
|
8
|
-
__Attention__: You should rewrite your configuration for use yaml data source!
|
|
22
|
+
__Attention__: You should rewrite your configuration for use yaml data source!
|
data/README.md
CHANGED
|
@@ -163,8 +163,8 @@ fetching values required to send notification. For push channel
|
|
|
163
163
|
expected that proc will return receiver's fcm registration id. For
|
|
164
164
|
email expected that proc will return receiver's email address.
|
|
165
165
|
|
|
166
|
-
You can pass options for receiver channels. You must pass proc with receive_data to `:subject` key and options
|
|
167
|
-
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:
|
|
168
168
|
|
|
169
169
|
```ruby
|
|
170
170
|
class User < Model
|
|
@@ -172,7 +172,11 @@ class User < Model
|
|
|
172
172
|
|
|
173
173
|
receive(
|
|
174
174
|
push: -> { push_token.value },
|
|
175
|
-
email: {
|
|
175
|
+
email: {
|
|
176
|
+
subject: -> { email },
|
|
177
|
+
if: -> { email_notifications? },
|
|
178
|
+
options: { mailer_class: UserMailer, mailer_method: :notify! }
|
|
179
|
+
}
|
|
176
180
|
)
|
|
177
181
|
end
|
|
178
182
|
```
|
|
@@ -189,6 +193,15 @@ Last command will fetch notifications credentials for user instance
|
|
|
189
193
|
and will try to send SMS, Push and Email for it. What argument we pass
|
|
190
194
|
for method? This is string key for builder. Read next to understand it.
|
|
191
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
|
+
|
|
192
205
|
### Build your notification
|
|
193
206
|
HeyYou Notification Builder - good system for store your notifications in one place.
|
|
194
207
|
By default you need create yml file with follow format:
|
data/lib/hey_you/builder.rb
CHANGED
|
@@ -38,7 +38,7 @@ module HeyYou
|
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
ch_builder =
|
|
41
|
-
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)
|
|
42
42
|
instance_variable_set("@#{ch}".to_sym, ch_builder)
|
|
43
43
|
|
|
44
44
|
define_ch_method(ch)
|
|
@@ -23,10 +23,8 @@ module HeyYou
|
|
|
23
23
|
raise InterpolationError, "Failed build notification string `#{notification_string}`: #{err.message}"
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
def ch_data
|
|
27
|
-
data.fetch(current_builder_name)
|
|
28
|
-
end
|
|
29
26
|
|
|
27
|
+
alias ch_data data
|
|
30
28
|
alias channel_data ch_data
|
|
31
29
|
|
|
32
30
|
def ch_options
|
|
@@ -3,19 +3,36 @@ require_relative '_base'
|
|
|
3
3
|
module HeyYou
|
|
4
4
|
class Builder
|
|
5
5
|
class Email < Base
|
|
6
|
-
attr_reader :subject, :body, :layout, :mailer_class, :mailer_method, :delivery_method
|
|
6
|
+
attr_reader :subject, :body, :layout, :mailer_class, :mailer_method, :delivery_method, :body_parts
|
|
7
7
|
|
|
8
8
|
def build
|
|
9
9
|
@mailer_class = ch_data.fetch('mailer_class', nil)
|
|
10
10
|
@mailer_method = ch_data.fetch('mailer_method', nil)
|
|
11
11
|
@delivery_method = ch_data.fetch('delivery_method', nil)
|
|
12
|
-
@body = interpolate(ch_data
|
|
12
|
+
@body = interpolate(ch_data['body'], options) if ch_data['body']
|
|
13
|
+
@body_parts = interpolate_each(ch_data.fetch('body_parts', nil)&.deep_dup, options)
|
|
13
14
|
@subject = interpolate(ch_data.fetch('subject'), options)
|
|
14
15
|
end
|
|
15
16
|
|
|
16
17
|
def to_hash
|
|
17
|
-
{ body: body, subject: subject }
|
|
18
|
+
{ body: body, subject: subject, body_parts: body_parts }
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
def interpolate_each(notification_hash, options)
|
|
24
|
+
return notification_hash unless notification_hash.is_a?(Hash)
|
|
25
|
+
|
|
26
|
+
notification_hash.each do |k, v|
|
|
27
|
+
next interpolate_each(v, options) if v.is_a?(Hash)
|
|
28
|
+
|
|
29
|
+
begin
|
|
30
|
+
notification_hash[k] = v % options
|
|
31
|
+
rescue KeyError => err
|
|
32
|
+
raise InterpolationError, "Failed build notification string `#{v}`: #{err.message}"
|
|
33
|
+
end
|
|
34
|
+
end
|
|
18
35
|
end
|
|
19
36
|
end
|
|
20
37
|
end
|
|
21
|
-
end
|
|
38
|
+
end
|
|
@@ -7,13 +7,13 @@ 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
|
|
@@ -22,7 +22,7 @@ module HeyYou
|
|
|
22
22
|
raise InvalidDataSourceError, 'You must pass `config.data_source.source_class` in configuration.'
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
source_class.new(options).load_collections
|
|
25
|
+
source_class.new(**options).load_collections
|
|
26
26
|
rescue ArgumentError => err
|
|
27
27
|
problem_fields =
|
|
28
28
|
err.message.gsub(/missing keyword(.?):\s/, '').split(', ').map { |f| "`#{f}`" }.join(', ')
|
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,24 +30,28 @@ 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"),
|
|
35
40
|
# Fetch receiver's options like :mailer_class
|
|
36
|
-
options: receiver.public_send("#{ch}_ch_receive_options") || {}
|
|
41
|
+
options: receiver.public_send("#{ch}_ch_receive_options").merge(options) || {}
|
|
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
|
|
@@ -81,4 +89,4 @@ module HeyYou
|
|
|
81
89
|
|
|
82
90
|
class NotRegisteredReceiver < StandardError; end
|
|
83
91
|
end
|
|
84
|
-
end
|
|
92
|
+
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.3.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sergey Nesterov
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2020-
|
|
11
|
+
date: 2020-10-30 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: fcm
|
|
@@ -166,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
166
166
|
- !ruby/object:Gem::Version
|
|
167
167
|
version: '0'
|
|
168
168
|
requirements: []
|
|
169
|
-
rubygems_version: 3.
|
|
169
|
+
rubygems_version: 3.1.2
|
|
170
170
|
signing_key:
|
|
171
171
|
specification_version: 4
|
|
172
172
|
summary: Send multichannel notification with one command.
|