hey-you 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rspec +3 -0
- data/.rubocop.yml +0 -0
- data/.travis.yml +10 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +67 -0
- data/README.md +373 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/hey_you.gemspec +33 -0
- data/lib/hey-you.rb +8 -0
- data/lib/hey_you/builder/_base.rb +40 -0
- data/lib/hey_you/builder/email.rb +17 -0
- data/lib/hey_you/builder/push.rb +15 -0
- data/lib/hey_you/builder.rb +51 -0
- data/lib/hey_you/channels/_base.rb +42 -0
- data/lib/hey_you/channels/email.rb +87 -0
- data/lib/hey_you/channels/push.rb +38 -0
- data/lib/hey_you/config/conigurable.rb +24 -0
- data/lib/hey_you/config/email.rb +31 -0
- data/lib/hey_you/config/push.rb +29 -0
- data/lib/hey_you/config.rb +111 -0
- data/lib/hey_you/receiver.rb +89 -0
- data/lib/hey_you/sender.rb +81 -0
- data/lib/hey_you/version.rb +3 -0
- metadata +170 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e3e825c0d1b7cdb82618796909f87f4244ef66c2
|
4
|
+
data.tar.gz: 9c564df97362eb0ff7999feebe9764ffb1450049
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 94d4347cc837e84e3185dafb4f046b7be65e826e44bfc0af444cafcfcf413c79b85b2ebb4d7f89861db8f93a98fd00b569f977f7c389f42869d93094a1c1cfec
|
7
|
+
data.tar.gz: 38a3a8952ecc0c962f1820f46eb3a395c2cbc5b8bf21f11405edd151b6e85d75582d8b0c1b324d121a2155fbce934e0f1ebbcc88b51ed0ade836f42f9e483abe
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
File without changes
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at qnesterr@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
hey-you (0.1.6)
|
5
|
+
fcm (~> 0.0.2)
|
6
|
+
i18n (~> 1.0)
|
7
|
+
mail (~> 2.7)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
addressable (2.5.2)
|
13
|
+
public_suffix (>= 2.0.2, < 4.0)
|
14
|
+
byebug (10.0.2)
|
15
|
+
concurrent-ruby (1.0.5)
|
16
|
+
crack (0.4.3)
|
17
|
+
safe_yaml (~> 1.0.0)
|
18
|
+
diff-lcs (1.3)
|
19
|
+
fcm (0.0.2)
|
20
|
+
httparty
|
21
|
+
json
|
22
|
+
ffaker (2.9.0)
|
23
|
+
hashdiff (0.3.7)
|
24
|
+
httparty (0.16.2)
|
25
|
+
multi_xml (>= 0.5.2)
|
26
|
+
i18n (1.0.1)
|
27
|
+
concurrent-ruby (~> 1.0)
|
28
|
+
json (2.1.0)
|
29
|
+
mail (2.7.0)
|
30
|
+
mini_mime (>= 0.1.1)
|
31
|
+
mini_mime (1.0.0)
|
32
|
+
multi_xml (0.6.0)
|
33
|
+
public_suffix (3.0.2)
|
34
|
+
rake (10.5.0)
|
35
|
+
rspec (3.7.0)
|
36
|
+
rspec-core (~> 3.7.0)
|
37
|
+
rspec-expectations (~> 3.7.0)
|
38
|
+
rspec-mocks (~> 3.7.0)
|
39
|
+
rspec-core (3.7.1)
|
40
|
+
rspec-support (~> 3.7.0)
|
41
|
+
rspec-expectations (3.7.0)
|
42
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
43
|
+
rspec-support (~> 3.7.0)
|
44
|
+
rspec-mocks (3.7.0)
|
45
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
46
|
+
rspec-support (~> 3.7.0)
|
47
|
+
rspec-support (3.7.1)
|
48
|
+
safe_yaml (1.0.4)
|
49
|
+
webmock (3.4.1)
|
50
|
+
addressable (>= 2.3.6)
|
51
|
+
crack (>= 0.3.2)
|
52
|
+
hashdiff
|
53
|
+
|
54
|
+
PLATFORMS
|
55
|
+
ruby
|
56
|
+
|
57
|
+
DEPENDENCIES
|
58
|
+
bundler
|
59
|
+
byebug
|
60
|
+
ffaker (~> 2.9)
|
61
|
+
hey-you!
|
62
|
+
rake (~> 10.5)
|
63
|
+
rspec (~> 3.7)
|
64
|
+
webmock (~> 3.4)
|
65
|
+
|
66
|
+
BUNDLED WITH
|
67
|
+
1.16.1
|
data/README.md
ADDED
@@ -0,0 +1,373 @@
|
|
1
|
+
# HeyYou [Alpha]
|
2
|
+
[![Build Status](https://travis-ci.com/QNester/hey-you.svg?branch=master)](https://travis-ci.com/QNester/hey-you#)
|
3
|
+
|
4
|
+
Send multichannel notifications with one command.
|
5
|
+
Сonvenient storage of notifications texts. Create your
|
6
|
+
own channels. Registrate receiver and send notifications for
|
7
|
+
him easy.
|
8
|
+
|
9
|
+
* [Requirements](#requirements)
|
10
|
+
* [Installation](#installation)
|
11
|
+
* [How to use](#how-to-use)
|
12
|
+
* [Configure](#configure)
|
13
|
+
* [Registrate receiver](#registrate-receiver)
|
14
|
+
* [Build your notification](#build-your-notification)
|
15
|
+
* [Send notification](#send-notification)
|
16
|
+
* [Sender options](#sender-options)
|
17
|
+
* [Create your own channels](#create-your-own-channels)
|
18
|
+
|
19
|
+
|
20
|
+
## Requirements
|
21
|
+
* Ruby 2.3.0 min (rspec works with ruby 2.3.3, 2.4.2, 2.5.3)
|
22
|
+
* FCM - Gem send push notification using [fcm gem](https://github.com/spacialdb/fcm).
|
23
|
+
You need *fcm server key* to successful configure push notifications.
|
24
|
+
|
25
|
+
## Installation
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
gem 'hey-you'
|
29
|
+
```
|
30
|
+
|
31
|
+
And then execute:
|
32
|
+
|
33
|
+
$ bundle
|
34
|
+
|
35
|
+
Or install it yourself as:
|
36
|
+
|
37
|
+
$ gem install hey-you
|
38
|
+
|
39
|
+
## How to use
|
40
|
+
|
41
|
+
### Configure
|
42
|
+
First, you must configure HeyYou. Example:
|
43
|
+
```ruby
|
44
|
+
HeyYou::Config.configure do
|
45
|
+
config.collection_files = ['config/notifications.yml']
|
46
|
+
config.email.from = 'noreply@example-mail.com'
|
47
|
+
config.push.fcm_token = 'fcm_server_key'
|
48
|
+
end
|
49
|
+
```
|
50
|
+
#### Required settings
|
51
|
+
Options for gem base work.
|
52
|
+
##### Base
|
53
|
+
* __config.collection_files__ - File or files contained all your notifications texts.
|
54
|
+
##### Push
|
55
|
+
* __config.push.fcm_token__ - Required setting for push channel. You can not send
|
56
|
+
push messages if setting was not set. You should set it to equal your fcm server key.
|
57
|
+
##### Email
|
58
|
+
* __config.email.from__ - Email address for send email notifications.
|
59
|
+
|
60
|
+
#### Optional settings
|
61
|
+
Additional options for configure your notifications.
|
62
|
+
#### Base
|
63
|
+
* __config.env_collection_file__ - File contained all your notifications texts for
|
64
|
+
environment. You can set it like `notifications.#{ENV['APP_ENV]}.yml`
|
65
|
+
* __config.splitter__ - Chars for split notification keys for
|
66
|
+
builder. Default: `.`
|
67
|
+
* __config.registered_channels__ - Avialable channels for your
|
68
|
+
applications. Default: `[:push, :email]`
|
69
|
+
* __config.localization__ - Boolean. If true, hey-you begin support I18n locales for notifications collection. Your
|
70
|
+
notifications for build should be nested in `I18n.locale` key. For example:
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
# config/initializers/hey-you.rb
|
74
|
+
HeyYou::Config.configure do
|
75
|
+
...
|
76
|
+
config.collection_files = I18n.available_locales.map { |locale| "config/notifications/#{locale}.yml" }
|
77
|
+
...
|
78
|
+
end
|
79
|
+
```
|
80
|
+
|
81
|
+
```yaml
|
82
|
+
# config/notifications/en.yml
|
83
|
+
en:
|
84
|
+
any_key:
|
85
|
+
any_nested_key:
|
86
|
+
push:
|
87
|
+
title: Test hey you
|
88
|
+
body: Hey you, %{name}
|
89
|
+
email:
|
90
|
+
subject: Test hello
|
91
|
+
body: Hey you, %{name}
|
92
|
+
```
|
93
|
+
|
94
|
+
```yaml
|
95
|
+
# config/notifications/ru.yml
|
96
|
+
ru:
|
97
|
+
any_key:
|
98
|
+
any_nested_key:
|
99
|
+
push:
|
100
|
+
title: Эй, ты!
|
101
|
+
body: Эй, ты, %{name}
|
102
|
+
email:
|
103
|
+
subject: Привет
|
104
|
+
body: Эй, ты, %{name}
|
105
|
+
```
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
# From your code:
|
109
|
+
I18n.locale = :ru
|
110
|
+
user.send_notification('any_key.any_nested_key', name: 'QNester') #=> send notification with body `Эй, ты, QNester`
|
111
|
+
I18n.locale = :en
|
112
|
+
user.send_notification('any_key.any_nested_key', name: 'QNester') #=> send notification with body `Hey you, QNester`
|
113
|
+
user.send_notification('any_key.any_nested_key', name: 'QNester', locale: :ru) #=> send notification with body `Эй, ты, QNester`
|
114
|
+
|
115
|
+
```
|
116
|
+
|
117
|
+
##### Push
|
118
|
+
* __config.push.priority__ - priority level for your pushes.
|
119
|
+
Default: high
|
120
|
+
* __config.push.ttl__ - default time_to_live option for fcm.
|
121
|
+
Default 60
|
122
|
+
* __config.push.fcm_timeout__ - default timeout for fcm.
|
123
|
+
Default 30
|
124
|
+
##### Email
|
125
|
+
* __config.email.layout__ - default layout for email letters.
|
126
|
+
* __config.email.default_mailing__ - use default mail sending or use custom mailer classes
|
127
|
+
* __config.email.default_mailer_class__ - default mailer class for email notifications
|
128
|
+
* __config.email.default_mailer_method__ - default mailer_method for mailer_class
|
129
|
+
* __config.email.default_delivery_method__ - expects, that mailer_method will build message and delivery_method will send it.
|
130
|
+
If you use ActionMailer you can set this option like `delivery_now` or `delivery_later`.
|
131
|
+
|
132
|
+
By default all letters will send as simple text.
|
133
|
+
|
134
|
+
### Registrate receiver
|
135
|
+
You can registrate your application classes like receivers.
|
136
|
+
You can easy send notification for receiver with method
|
137
|
+
`#send_notification`. For example:
|
138
|
+
```ruby
|
139
|
+
class User < Model
|
140
|
+
extend HeyYou::Receiver
|
141
|
+
|
142
|
+
receive(
|
143
|
+
push: -> { push_token.value },
|
144
|
+
email: -> { email }
|
145
|
+
)
|
146
|
+
end
|
147
|
+
```
|
148
|
+
|
149
|
+
Class method `#receive` will registrate your class User
|
150
|
+
as receiver. In arguments we must pass Hash instance where
|
151
|
+
keys - channels names as symbols, and values - procs for
|
152
|
+
fetching values required to send notification. For push channel
|
153
|
+
expected that proc will return receiver's fcm registration id. For
|
154
|
+
email expected that proc will return receiver's email address.
|
155
|
+
|
156
|
+
You can pass options for receiver channels. You must pass proc with receive_data to `:subject` key and options
|
157
|
+
pass to `:options` key:
|
158
|
+
|
159
|
+
```ruby
|
160
|
+
class User < Model
|
161
|
+
extend HeyYou::Receiver
|
162
|
+
|
163
|
+
receive(
|
164
|
+
push: -> { push_token.value },
|
165
|
+
email: { subject: -> { email }, options: { mailer_class: UserMailer, mailer_method: :notify! } }
|
166
|
+
)
|
167
|
+
end
|
168
|
+
```
|
169
|
+
|
170
|
+
If you pass correct procs in `#receive` you can send notification
|
171
|
+
for your user like:
|
172
|
+
|
173
|
+
```ruby
|
174
|
+
user = User.find(1)
|
175
|
+
user.send_notification('for_users.hello')
|
176
|
+
```
|
177
|
+
|
178
|
+
Last command will fetch notifications credentials for user instance
|
179
|
+
and will try to send SMS, Push and Email for it. What argument we pass
|
180
|
+
for method? This is string key for builder. Read next to understand it.
|
181
|
+
|
182
|
+
### Build your notification
|
183
|
+
HeyYou Notification Builder - good system for store your notifications in one place.
|
184
|
+
You need create yml file with follow format:
|
185
|
+
```yaml
|
186
|
+
# config/notifications/collection.yml
|
187
|
+
any_key:
|
188
|
+
any_nested_key:
|
189
|
+
push:
|
190
|
+
title: Test hey you
|
191
|
+
body: Hey you, %{name}
|
192
|
+
email:
|
193
|
+
subject: Test hello
|
194
|
+
body: Hey you, %{name}
|
195
|
+
```
|
196
|
+
|
197
|
+
You should pass file path to `config.collection_file` to load your notification texts.
|
198
|
+
Now you can send notification:
|
199
|
+
|
200
|
+
```ruby
|
201
|
+
...
|
202
|
+
user.send_notification('any_key.any_nested_key', name: 'HeyYou')
|
203
|
+
```
|
204
|
+
This command with fetch notifications templates from your collection file
|
205
|
+
for each channel and will try interpolate it. If you will not pass required
|
206
|
+
interpolation keys then error will be raised. After successful interpolation
|
207
|
+
notification will send for all available channels for receiver:
|
208
|
+
1) Send push via fcm
|
209
|
+
2) Send email
|
210
|
+
|
211
|
+
### Send notification
|
212
|
+
Receiver not only one way to send notification. You can send it using `HeyYou::Sender`.
|
213
|
+
Just use method `#send` for HeyYou::Sender and pass notification key and `to` options
|
214
|
+
like:
|
215
|
+
|
216
|
+
```ruby
|
217
|
+
HeyYou::Sender.send!(
|
218
|
+
'any_key.any_nested_key',
|
219
|
+
to: {
|
220
|
+
push: 'fcm_registration_token',
|
221
|
+
email: 'example_mail@example.com'
|
222
|
+
},
|
223
|
+
name: 'HeyYou'
|
224
|
+
)
|
225
|
+
|
226
|
+
```
|
227
|
+
This command will process texts and send push and email to `to` credentials.
|
228
|
+
|
229
|
+
### Sender options
|
230
|
+
#### Only option
|
231
|
+
You can user some options for sender. You can send notification exclude
|
232
|
+
not required channels with option `:only` like:
|
233
|
+
|
234
|
+
```ruby
|
235
|
+
user.send_notification('any_key.any_nested_key', name: 'HeyYou', only: [:push])
|
236
|
+
```
|
237
|
+
|
238
|
+
It will send notification only with push channel. Email will be skipped.
|
239
|
+
|
240
|
+
#### Channels options
|
241
|
+
Channels options should pass to send method with associated channel names like:
|
242
|
+
```ruby
|
243
|
+
user.send_notification(
|
244
|
+
'any_key.any_nested_key',
|
245
|
+
name: 'HeyYou',
|
246
|
+
email: { layout: 'layout' }
|
247
|
+
)
|
248
|
+
```
|
249
|
+
|
250
|
+
In this example we pass option for email channel. We decide
|
251
|
+
specific layout for 'any_key.any_nested_key' notification.
|
252
|
+
|
253
|
+
### Create your own channels
|
254
|
+
To create your custom channel you should create two classes:
|
255
|
+
1. HeyYou::Builders::<YOUR_CHANNEL_NAME>
|
256
|
+
2. HeyYou::Channels::<YOUR_CHANNEL_NAME>
|
257
|
+
|
258
|
+
You must extend your builder class from `HeyYou::Builder::Base` and realize
|
259
|
+
class method `#build`. In this method you should fetch notification data for
|
260
|
+
Your channel. For example:
|
261
|
+
|
262
|
+
```ruby
|
263
|
+
class HeyYou::Builder::CustomNotifier < HeyYou::Builder::Base
|
264
|
+
class << self
|
265
|
+
attr_reader :header, :body, :icon
|
266
|
+
|
267
|
+
def build
|
268
|
+
@header = interpolate(ch_data['header'], options)
|
269
|
+
@body = interpolate(ch_data['body'], options)
|
270
|
+
@icon = options[:icon] || interpolate(ch_data['icon'], options)
|
271
|
+
end
|
272
|
+
end
|
273
|
+
end
|
274
|
+
```
|
275
|
+
|
276
|
+
Your notifications collection YAML file will contain next:
|
277
|
+
|
278
|
+
```yaml
|
279
|
+
any_key:
|
280
|
+
any_nested_key:
|
281
|
+
push:
|
282
|
+
# ...
|
283
|
+
custom_notifier:
|
284
|
+
header: Hello
|
285
|
+
body: Hello, %{name}
|
286
|
+
icon: 'icons.klass'
|
287
|
+
```
|
288
|
+
|
289
|
+
To check your builder you can call
|
290
|
+
```ruby
|
291
|
+
notifier_data = HeyYou::Builder.new('any_key.any_nested_key', name: 'HeyYou').custom_notifier
|
292
|
+
notifier_data # => Instance of HeyYou::Builder::CustomNotifier
|
293
|
+
notifier_data.header # => Hello
|
294
|
+
notifier_data.body # => Hello, HeyYou
|
295
|
+
notifier_data.icon # => 'icons.klass'
|
296
|
+
```
|
297
|
+
|
298
|
+
You must extend your channel class from `HeyYou::Channels::Base` and
|
299
|
+
realize class method `#send!`. This method pass two arguments: builder instance and to option.
|
300
|
+
Finally, you channel should look like:
|
301
|
+
|
302
|
+
```ruby
|
303
|
+
class HeyYou::Channels::CustomNotifier < HeyYou::Channels::Base
|
304
|
+
class << self
|
305
|
+
def send!(builder, to:)
|
306
|
+
custom_notifier_client.send_message(
|
307
|
+
text: builder.custom_notifier.text,
|
308
|
+
token: to
|
309
|
+
)
|
310
|
+
end
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
```
|
315
|
+
|
316
|
+
If your channel require some configurations you should create class
|
317
|
+
`HeyYou::Config::<YOUR_CHANNEL_NAME>`, extend it with Configurable module and add
|
318
|
+
accessors for it. Example:
|
319
|
+
|
320
|
+
```ruby
|
321
|
+
class HeyYou::Config::CustomNotifier
|
322
|
+
extend HeyYou::Config::Configurable
|
323
|
+
|
324
|
+
attr_accessor :secret_key
|
325
|
+
|
326
|
+
def client
|
327
|
+
YourProviderClass::Client.new(secret_key)
|
328
|
+
end
|
329
|
+
end
|
330
|
+
```
|
331
|
+
|
332
|
+
If your attr is required you can add checking it
|
333
|
+
in your channel:
|
334
|
+
|
335
|
+
```ruby
|
336
|
+
class HeyYou::Channels::CustomNotifier < HeyYou::Channels::Base
|
337
|
+
class << self
|
338
|
+
def send!(builder, to:)
|
339
|
+
return false unless credentials_present?
|
340
|
+
|
341
|
+
HeyYou::Config.instance.custom_notifier.client.send_message(
|
342
|
+
text: builder.custom_notifier.text,
|
343
|
+
token: to
|
344
|
+
)
|
345
|
+
end
|
346
|
+
|
347
|
+
def required_credentials
|
348
|
+
[:secret_key]
|
349
|
+
end
|
350
|
+
end
|
351
|
+
end
|
352
|
+
|
353
|
+
```
|
354
|
+
|
355
|
+
`#credentials_present?` method check exists required_credentials
|
356
|
+
in your channel config.
|
357
|
+
|
358
|
+
Now, when you will send notification, it will be send with your channel too.
|
359
|
+
|
360
|
+
|
361
|
+
## Development
|
362
|
+
|
363
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
364
|
+
|
365
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
366
|
+
|
367
|
+
## Contributing
|
368
|
+
|
369
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/hey_you. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
370
|
+
|
371
|
+
## Code of Conduct
|
372
|
+
|
373
|
+
Everyone interacting in the HeyYou project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/hey_you/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "hey-you"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/hey_you.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "hey_you/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "hey-you"
|
8
|
+
spec.version = HeyYou::VERSION
|
9
|
+
spec.authors = ["Sergey Nesterov"]
|
10
|
+
spec.email = ["qnesterr@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = 'Send multichannel notification with one command.'
|
13
|
+
spec.description = 'Send multichannel notifications with one command. ' \
|
14
|
+
'Сonvenient storage of notifications texts. Create your own channels.' \
|
15
|
+
'Registrate receiver send notifications easy.'
|
16
|
+
spec.homepage = "https://github.com/QNester/hey-you"
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
19
|
+
f.match(%r{^(test|spec|features)/})
|
20
|
+
end
|
21
|
+
spec.bindir = "exe"
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.add_runtime_dependency "fcm", '~> 0.0.2'
|
26
|
+
spec.add_runtime_dependency "mail", '~> 2.7'
|
27
|
+
spec.add_runtime_dependency "i18n", '~> 1.0'
|
28
|
+
|
29
|
+
spec.add_development_dependency "rake", '~> 10.5'
|
30
|
+
spec.add_development_dependency "rspec", '~> 3.7'
|
31
|
+
spec.add_development_dependency "webmock", '~> 3.4'
|
32
|
+
spec.add_development_dependency "ffaker", '~> 2.9'
|
33
|
+
end
|
data/lib/hey-you.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
module HeyYou
|
2
|
+
class Builder
|
3
|
+
class Base
|
4
|
+
attr_reader :data, :key, :options
|
5
|
+
|
6
|
+
def initialize(data, key, **options)
|
7
|
+
@data = data
|
8
|
+
@key = key
|
9
|
+
@options = options
|
10
|
+
build
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def interpolate(notification_string, options)
|
16
|
+
notification_string % options
|
17
|
+
rescue KeyError => err
|
18
|
+
raise InterpolationError, "Failed build notification string `#{notification_string}`: #{err.message}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def ch_data
|
22
|
+
data.fetch(current_builder_name)
|
23
|
+
end
|
24
|
+
|
25
|
+
alias channel_data ch_data
|
26
|
+
|
27
|
+
def ch_options
|
28
|
+
options.fetch(current_builder_name, {})
|
29
|
+
end
|
30
|
+
|
31
|
+
alias channel_options ch_options
|
32
|
+
|
33
|
+
def current_builder_name
|
34
|
+
self.class.name.split('::').last.downcase
|
35
|
+
end
|
36
|
+
|
37
|
+
class InterpolationError < StandardError; end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|