hey-you 1.2.2 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -2
- data/lib/hey_you/builder.rb +3 -3
- data/lib/hey_you/builder/email.rb +21 -4
- data/lib/hey_you/channels/email.rb +3 -3
- data/lib/hey_you/config.rb +10 -2
- data/lib/hey_you/config/conigurable.rb +3 -1
- data/lib/hey_you/config/data_source.rb +1 -1
- data/lib/hey_you/sender.rb +9 -6
- 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: a02aef783a1b2fa450d1c420595f9c7df0a06eefa7a877c0e3e97fe072449f20
|
4
|
+
data.tar.gz: b4ff049fe645dab2263b0ffb2c947c537a3fcdde985b6a228e2daa455f4c38da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1b41481fdc55fe9463a5e017dae21ec53cf490c04925bfd43d350f717acdb4a9a20eeb2908666f28ab8e3db02daef420a0edf6922c25779168bdbc58ba8a864
|
7
|
+
data.tar.gz: 650584118b560468f1c428e9e203eadd11571b3c5576b64dcc5e3322bfbcc237ab571ace0af62c079fc988278879aac332b812e2e6e82ceea680868670b6aab2
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,18 @@
|
|
1
1
|
# Changelog for hey-you gem
|
2
2
|
|
3
|
-
|
3
|
+
# 1.4.0
|
4
|
+
- Improvement: configs validations for custom classes
|
5
|
+
- Improvement: allow custom classes with '_' in name
|
6
|
+
|
7
|
+
## 1.3.0 - 1.3.4
|
8
|
+
- Feature: `body_part` in email builder.
|
9
|
+
- Fixes
|
10
|
+
|
11
|
+
### 1.2.3
|
12
|
+
- Improvement: fix ruby 2.7 warnings
|
13
|
+
- Fix: fix `NoMethodError` in `sender.rb` when channel must be ignored by `if`
|
14
|
+
|
15
|
+
### 1.2.2
|
4
16
|
- Improvement: `if` condition for receiver (if condition `false` - sending will be skipped).
|
5
17
|
- Improvement: `force` option - send message independent on `if` condition.
|
6
18
|
|
@@ -10,4 +22,4 @@
|
|
10
22
|
|
11
23
|
### 1.2.0
|
12
24
|
- Feature: data source extensions (check readme for more information).
|
13
|
-
__Attention__: You should rewrite your configuration for use yaml data source!
|
25
|
+
__Attention__: You should rewrite your configuration for use yaml data source!
|
data/lib/hey_you/builder.rb
CHANGED
@@ -37,8 +37,8 @@ module HeyYou
|
|
37
37
|
return
|
38
38
|
end
|
39
39
|
|
40
|
-
|
41
|
-
|
40
|
+
klass_name = ch.to_s.downcase.split('_').map(&:capitalize).join
|
41
|
+
ch_builder = HeyYou::Builder.const_get(klass_name).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)
|
@@ -74,4 +74,4 @@ module HeyYou
|
|
74
74
|
class DataNotFound < StandardError; end
|
75
75
|
class RequiredChannelNotFound < StandardError; end
|
76
76
|
end
|
77
|
-
end
|
77
|
+
end
|
@@ -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
|
data/lib/hey_you/config.rb
CHANGED
@@ -62,6 +62,13 @@ module HeyYou
|
|
62
62
|
@registered_receivers << receiver_class
|
63
63
|
end
|
64
64
|
|
65
|
+
def validate_config
|
66
|
+
registered_channels.each do |ch|
|
67
|
+
ch_config = send(ch)
|
68
|
+
ch_config.validate_config if ch_config.respond_to?(:validate_config)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
65
72
|
# Registrate new custom channel.
|
66
73
|
# For successful registration, in application must be exists:
|
67
74
|
# 1. HeyYou::Channels::<YOUR_CHANNEL_NAME> < HeyYou::Channels::Base
|
@@ -94,7 +101,8 @@ module HeyYou
|
|
94
101
|
# For example, if ch == 'push' will define method #push for class instance.
|
95
102
|
# New method will return instance of channel config instance
|
96
103
|
def define_ch_config_method(ch)
|
97
|
-
|
104
|
+
klass_name = ch.to_s.split('_').map(&:capitalize).join
|
105
|
+
method_proc = -> { self.class.const_get(klass_name).config }
|
98
106
|
self.class.send(:define_method, ch, method_proc)
|
99
107
|
end
|
100
108
|
|
@@ -102,4 +110,4 @@ module HeyYou
|
|
102
110
|
data_source.load_data
|
103
111
|
end
|
104
112
|
end
|
105
|
-
end
|
113
|
+
end
|
@@ -13,6 +13,7 @@ module HeyYou
|
|
13
13
|
def configure(&block)
|
14
14
|
@configured ? raise(AlreadyConfiguredError, 'You already configure HeyYou') : instance_eval(&block)
|
15
15
|
@configured = true
|
16
|
+
instance.validate_config if instance.respond_to?(:validate_config)
|
16
17
|
end
|
17
18
|
|
18
19
|
def config
|
@@ -20,6 +21,7 @@ module HeyYou
|
|
20
21
|
end
|
21
22
|
|
22
23
|
class AlreadyConfiguredError < StandardError; end
|
24
|
+
class RequiredConfigsNotPassed < StandardError; end
|
23
25
|
end
|
24
26
|
end
|
25
|
-
end
|
27
|
+
end
|
@@ -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/sender.rb
CHANGED
@@ -38,18 +38,18 @@ module HeyYou
|
|
38
38
|
# Fetch receiver's info for sending: phone_number, email, etc
|
39
39
|
subject: receiver.public_send("#{ch}_ch_receive_info"),
|
40
40
|
# Fetch receiver's options like :mailer_class
|
41
|
-
options: receiver.public_send("#{ch}_ch_receive_options") || {}
|
41
|
+
options: receiver.public_send("#{ch}_ch_receive_options").merge(options) || {}
|
42
42
|
}
|
43
43
|
end
|
44
44
|
|
45
|
-
send_to_receive_info(notification_key, to_hash, options)
|
45
|
+
send_to_receive_info(notification_key, to_hash, **options)
|
46
46
|
end
|
47
47
|
|
48
48
|
def send_to_receive_info(notification_key, receive_info, **options)
|
49
|
-
builder = Builder.new(notification_key, options)
|
49
|
+
builder = Builder.new(notification_key, **options)
|
50
50
|
response = {}
|
51
51
|
config.registered_channels.each do |ch|
|
52
|
-
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)
|
53
53
|
config.log(
|
54
54
|
"Send #{ch}-message to `#{receive_info[ch][:subject]}` with data: #{builder.public_send(ch).data}" \
|
55
55
|
" and options: #{receive_info[ch][:options]}"
|
@@ -68,7 +68,10 @@ module HeyYou
|
|
68
68
|
private
|
69
69
|
|
70
70
|
def channel_allowed?(ch, to, builder, **options)
|
71
|
-
|
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
|
72
75
|
return false unless condition
|
73
76
|
channel_allowed_by_only?(ch, options[:only]) && !builder.send(ch).nil?
|
74
77
|
end
|
@@ -86,4 +89,4 @@ module HeyYou
|
|
86
89
|
|
87
90
|
class NotRegisteredReceiver < StandardError; end
|
88
91
|
end
|
89
|
-
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.4.0
|
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-12-26 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.
|