hey-you 1.2.1 → 1.2.2
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 +5 -0
- 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/receiver.rb +2 -0
- data/lib/hey_you/sender.rb +7 -2
- 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: 755f8775f2918592a3faf297f7dbed8f5b7253d137ac47ffedae9a9106a5d44f
|
|
4
|
+
data.tar.gz: 17c927968d8fe27c6a5e8b2ace86af1bb30683f3cc968099aca19401c94cbcd7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 592e4f17b2e26f26f04477150118a91d2cf68696bc17f3021617e554a14bddb19fd3fec5e2c8d2dc37342d045e6ca2c2c679969de645aa9269edf6cc139ea596
|
|
7
|
+
data.tar.gz: 83aa1a371cffa0efce33fb69e410abbe6d0eda85e019ab117f1e1ccb93cfee8d7ce92fb4b23d83a4b19d08615ccc0616c378ebd030801bc10b0773edb71e1596
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Changelog for hey-you gem
|
|
2
2
|
|
|
3
|
+
## 1.2.2
|
|
4
|
+
- Improvement: `if` condition for receiver (if condition `false` - sending will be skipped).
|
|
5
|
+
- Improvement: `force` option - send message independent on `if` condition.
|
|
6
|
+
|
|
7
|
+
|
|
3
8
|
### 1.2.1
|
|
4
9
|
- Improvement: Builder will not make channel builder if it skipped by only option
|
|
5
10
|
|
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
|
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"),
|
|
@@ -46,7 +51,7 @@ module HeyYou
|
|
|
46
51
|
config.registered_channels.each do |ch|
|
|
47
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
|
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.2.
|
|
4
|
+
version: 1.2.2
|
|
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-07-
|
|
11
|
+
date: 2020-07-02 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.0.
|
|
169
|
+
rubygems_version: 3.0.3
|
|
170
170
|
signing_key:
|
|
171
171
|
specification_version: 4
|
|
172
172
|
summary: Send multichannel notification with one command.
|