hertz-twilio 1.0.3
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 +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +97 -0
- data/Rakefile +6 -0
- data/app/jobs/hertz/courier/twilio/notification_delivery_job.rb +33 -0
- data/lib/generators/hertz/courier/twilio/install_generator.rb +15 -0
- data/lib/generators/hertz/courier/twilio/templates/initializer.rb +12 -0
- data/lib/hertz/courier/twilio.rb +26 -0
- data/lib/hertz/courier/twilio/engine.rb +11 -0
- data/lib/hertz/courier/twilio/version.rb +9 -0
- metadata +241 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: '0948a5633393fc8cee816b06c33e8fe69922f9fcec29acba789a27928db36a8f'
|
4
|
+
data.tar.gz: '0876362cf706cf713acfb03ea9e0392761e47298c3714c3e09cb2741a60ad6de'
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0717d2965a2be52a45770ec1600a5ed2b6a1c7348cafe16b5b9bf2b3197f9eb46339b441dc32a78a61ac47f23e7216bb7fb6cf2b0e3e8290957a5fb410d43313
|
7
|
+
data.tar.gz: 054b9b206c936a9d72b296195a9b6b74011b7215ed47d1bbdcdf2408436a4ac93c30328232ea1e5ea3281ddb0695d962ee7284666a0efdbb495030fb5386b1c9
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2016 Alessandro Desantis
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
# Hertz::Courier::Twilio
|
2
|
+
|
3
|
+
[](https://travis-ci.org/aldesantis/hertz-twilio)
|
4
|
+
[](https://gemnasium.com/github.com/aldesantis/hertz-twilio)
|
5
|
+
[](https://coveralls.io/github/aldesantis/hertz-twilio?branch=master)
|
6
|
+
[](https://codeclimate.com/github/aldesantis/hertz-twilio/maintainability)
|
7
|
+
|
8
|
+
This is a [Hertz](https://github.com/alessandro1997/hertz) courier for sending notifications to your users via SMS by
|
9
|
+
leveraging the [Twilio](https://www.twilio.com) API.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'hertz-twilio'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
```console
|
22
|
+
$ bundle
|
23
|
+
```
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
```console
|
28
|
+
$ gem install hertz-twilio
|
29
|
+
```
|
30
|
+
|
31
|
+
Then, run the installer generator:
|
32
|
+
|
33
|
+
```console
|
34
|
+
$ rails g hertz:courier:twilio:install
|
35
|
+
```
|
36
|
+
|
37
|
+
The courier will use ActiveJob to asynchronously deliver the text messages, so make sure that you're executing
|
38
|
+
background jobs with some adapter (`inline` will work, even though it's not recommended). Jobs are pushed to the
|
39
|
+
`default` queue.
|
40
|
+
|
41
|
+
Finally, you will have to expose a `#hertz_phone_number` method in your receiver class:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
class User
|
45
|
+
include Hertz::Notifiable
|
46
|
+
|
47
|
+
def hertz_phone_number
|
48
|
+
phone_number
|
49
|
+
end
|
50
|
+
end
|
51
|
+
```
|
52
|
+
|
53
|
+
If `#hertz_phone_number` returns an empty value (i.e. `false`, `nil` or an empty string) at the time the job is
|
54
|
+
executed, the notification will not be delivered. This allows you to programmatically enable/disable SMS notifications
|
55
|
+
for a user:
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
class User
|
59
|
+
include Hertz::Notifiable
|
60
|
+
|
61
|
+
def hertz_phone_number
|
62
|
+
phone_number if phone_number_verified?
|
63
|
+
end
|
64
|
+
end
|
65
|
+
```
|
66
|
+
|
67
|
+
## Usage
|
68
|
+
|
69
|
+
All you need to do in order to start delivering notifications by SMS is add `twilio` to the notification's `#deliver_by`
|
70
|
+
statement and provide an SMS body:
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
class CommentNotification < Hertz::Notification
|
74
|
+
deliver_by :twilio
|
75
|
+
|
76
|
+
def sms_body
|
77
|
+
'You received a new comment!'
|
78
|
+
end
|
79
|
+
end
|
80
|
+
```
|
81
|
+
|
82
|
+
All `CommentNotification`s will now be delivered by SMS! :)
|
83
|
+
|
84
|
+
**NOTE:** This courier uses the [deliveries API](https://github.com/aldesantis/hertz#tracking-delivery-status)
|
85
|
+
to prevent double deliveries.
|
86
|
+
|
87
|
+
## Contributing
|
88
|
+
|
89
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/aldesantis/hertz-twilio.
|
90
|
+
|
91
|
+
## License
|
92
|
+
|
93
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
94
|
+
|
95
|
+
# To do
|
96
|
+
|
97
|
+
- [ ] Allow changing the job's queue
|
data/Rakefile
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Hertz
|
4
|
+
module Courier
|
5
|
+
module Twilio
|
6
|
+
class NotificationDeliveryJob < ActiveJob::Base
|
7
|
+
queue_as :default
|
8
|
+
|
9
|
+
def perform(notification)
|
10
|
+
return unless notification.receiver.hertz_phone_number.present?
|
11
|
+
return if notification.delivered_with?(:twilio)
|
12
|
+
|
13
|
+
twilio_client.messages.create(
|
14
|
+
to: notification.receiver.hertz_phone_number,
|
15
|
+
from: Hertz::Courier::Twilio.phone_number,
|
16
|
+
body: notification.sms_body
|
17
|
+
)
|
18
|
+
|
19
|
+
notification.mark_delivered_with(:twilio)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def twilio_client
|
25
|
+
@twilio_client ||= ::Twilio::REST::Client.new(
|
26
|
+
Hertz::Courier::Twilio.account_sid,
|
27
|
+
Hertz::Courier::Twilio.auth_token
|
28
|
+
)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Hertz
|
4
|
+
module Courier
|
5
|
+
module Twilio
|
6
|
+
class InstallGenerator < Rails::Generators::Base
|
7
|
+
source_root File.expand_path('../templates', __FILE__)
|
8
|
+
|
9
|
+
def copy_initializer_file
|
10
|
+
copy_file 'initializer.rb', 'config/initializers/hertz_twilio.rb'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
Hertz::Courier::Twilio.configure do |config|
|
4
|
+
# Your Twilio phone number.
|
5
|
+
config.phone_number = '+390123456789'
|
6
|
+
|
7
|
+
# Your Twilio account's SID.
|
8
|
+
config.account_sid = 'YourTwilioAccountSid'
|
9
|
+
|
10
|
+
# Your Twilio authentication token
|
11
|
+
config.auth_token = 'YourTwilioAuthToken'
|
12
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'twilio-ruby'
|
4
|
+
require 'hertz'
|
5
|
+
|
6
|
+
require 'hertz/courier/twilio/engine'
|
7
|
+
require 'hertz/courier/twilio/version'
|
8
|
+
|
9
|
+
module Hertz
|
10
|
+
module Courier
|
11
|
+
module Twilio
|
12
|
+
mattr_accessor :phone_number, :account_sid, :auth_token
|
13
|
+
|
14
|
+
class << self
|
15
|
+
def configure
|
16
|
+
yield(self)
|
17
|
+
end
|
18
|
+
|
19
|
+
def deliver_notification(notification)
|
20
|
+
Hertz::Courier::Twilio::NotificationDeliveryJob
|
21
|
+
.perform_later(notification)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,241 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hertz-twilio
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alessandro Desantis
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-02-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: hertz
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 4.0.0
|
34
|
+
- - "<"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '6'
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 4.0.0
|
44
|
+
- - "<"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '6'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: twilio-ruby
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '5.6'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '5.6'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: coveralls
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: database_cleaner
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: factory_bot_rails
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: faker
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: fuubar
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: pg
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - "~>"
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0.21'
|
138
|
+
type: :development
|
139
|
+
prerelease: false
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - "~>"
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0.21'
|
145
|
+
- !ruby/object:Gem::Dependency
|
146
|
+
name: rspec-activejob
|
147
|
+
requirement: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
type: :development
|
153
|
+
prerelease: false
|
154
|
+
version_requirements: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - ">="
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0'
|
159
|
+
- !ruby/object:Gem::Dependency
|
160
|
+
name: rspec-rails
|
161
|
+
requirement: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - ">="
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
166
|
+
type: :development
|
167
|
+
prerelease: false
|
168
|
+
version_requirements: !ruby/object:Gem::Requirement
|
169
|
+
requirements:
|
170
|
+
- - ">="
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
version: '0'
|
173
|
+
- !ruby/object:Gem::Dependency
|
174
|
+
name: rubocop
|
175
|
+
requirement: !ruby/object:Gem::Requirement
|
176
|
+
requirements:
|
177
|
+
- - ">="
|
178
|
+
- !ruby/object:Gem::Version
|
179
|
+
version: '0'
|
180
|
+
type: :development
|
181
|
+
prerelease: false
|
182
|
+
version_requirements: !ruby/object:Gem::Requirement
|
183
|
+
requirements:
|
184
|
+
- - ">="
|
185
|
+
- !ruby/object:Gem::Version
|
186
|
+
version: '0'
|
187
|
+
- !ruby/object:Gem::Dependency
|
188
|
+
name: rubocop-rspec
|
189
|
+
requirement: !ruby/object:Gem::Requirement
|
190
|
+
requirements:
|
191
|
+
- - ">="
|
192
|
+
- !ruby/object:Gem::Version
|
193
|
+
version: '0'
|
194
|
+
type: :development
|
195
|
+
prerelease: false
|
196
|
+
version_requirements: !ruby/object:Gem::Requirement
|
197
|
+
requirements:
|
198
|
+
- - ">="
|
199
|
+
- !ruby/object:Gem::Version
|
200
|
+
version: '0'
|
201
|
+
description:
|
202
|
+
email:
|
203
|
+
- desa.alessandro@gmail.com
|
204
|
+
executables: []
|
205
|
+
extensions: []
|
206
|
+
extra_rdoc_files: []
|
207
|
+
files:
|
208
|
+
- MIT-LICENSE
|
209
|
+
- README.md
|
210
|
+
- Rakefile
|
211
|
+
- app/jobs/hertz/courier/twilio/notification_delivery_job.rb
|
212
|
+
- lib/generators/hertz/courier/twilio/install_generator.rb
|
213
|
+
- lib/generators/hertz/courier/twilio/templates/initializer.rb
|
214
|
+
- lib/hertz/courier/twilio.rb
|
215
|
+
- lib/hertz/courier/twilio/engine.rb
|
216
|
+
- lib/hertz/courier/twilio/version.rb
|
217
|
+
homepage: https://github.com/alessandro1997/hertz-twilio
|
218
|
+
licenses:
|
219
|
+
- MIT
|
220
|
+
metadata: {}
|
221
|
+
post_install_message:
|
222
|
+
rdoc_options: []
|
223
|
+
require_paths:
|
224
|
+
- lib
|
225
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
226
|
+
requirements:
|
227
|
+
- - ">="
|
228
|
+
- !ruby/object:Gem::Version
|
229
|
+
version: '0'
|
230
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
231
|
+
requirements:
|
232
|
+
- - ">="
|
233
|
+
- !ruby/object:Gem::Version
|
234
|
+
version: '0'
|
235
|
+
requirements: []
|
236
|
+
rubyforge_project:
|
237
|
+
rubygems_version: 2.7.5
|
238
|
+
signing_key:
|
239
|
+
specification_version: 4
|
240
|
+
summary: A Twilio courier for Hertz.
|
241
|
+
test_files: []
|