hertz-twilio 1.0.3 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -13
- data/Rakefile +5 -3
- data/app/jobs/hertz/twilio/notification_delivery_job.rb +31 -0
- data/lib/generators/hertz/twilio/install_generator.rb +13 -0
- data/lib/generators/hertz/{courier/twilio → twilio}/templates/initializer.rb +5 -1
- data/lib/hertz/twilio/engine.rb +9 -0
- data/lib/hertz/twilio/version.rb +7 -0
- data/lib/hertz/twilio.rb +23 -0
- metadata +11 -11
- data/app/jobs/hertz/courier/twilio/notification_delivery_job.rb +0 -33
- data/lib/generators/hertz/courier/twilio/install_generator.rb +0 -15
- data/lib/hertz/courier/twilio/engine.rb +0 -11
- data/lib/hertz/courier/twilio/version.rb +0 -9
- data/lib/hertz/courier/twilio.rb +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a440feb7decf0ab34fa2bdfd97788e3361d05102e4b2d4448d73cc6733aa516
|
4
|
+
data.tar.gz: 45afcdc2bcbf6e20bfe8f5d261f5ed6fe58c08e6f36761e5e3a7d17f7a989e18
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73faa0c4783d912105a483102abc1adf94c86545bfaec80572e25e2f0a40fb5adda4f3299f658afce00be5e9f21301bc08067767880e834e8ca4377a910a0fe5
|
7
|
+
data.tar.gz: 0bea9290bd484a5861d56bf4bb5130805a4a04424785cfb645e9ec7ab76e69267cb799b5234a294f7181af15cd575c27726068370ddba4250473883fd467cdfb
|
data/README.md
CHANGED
@@ -1,12 +1,11 @@
|
|
1
|
-
# Hertz::
|
1
|
+
# Hertz::Twilio
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/aldesantis/hertz-twilio.svg?branch=master)](https://travis-ci.org/aldesantis/hertz-twilio)
|
4
|
-
[![Dependency Status](https://gemnasium.com/badges/github.com/aldesantis/hertz-twilio.svg)](https://gemnasium.com/github.com/aldesantis/hertz-twilio)
|
5
4
|
[![Coverage Status](https://coveralls.io/repos/github/aldesantis/hertz-twilio/badge.svg?branch=master)](https://coveralls.io/github/aldesantis/hertz-twilio?branch=master)
|
6
|
-
[![Maintainability](https://api.codeclimate.com/v1/badges/
|
5
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/204eed3c916b560ef788/maintainability)](https://codeclimate.com/github/aldesantis/hertz-twilio/maintainability)
|
7
6
|
|
8
|
-
This is a [Hertz](https://github.com/
|
9
|
-
leveraging the [Twilio](https://www.twilio.com) API.
|
7
|
+
This is a [Hertz](https://github.com/aldesantis/hertz) courier for sending notifications to your
|
8
|
+
users via SMS by leveraging the [Twilio](https://www.twilio.com) API.
|
10
9
|
|
11
10
|
## Installation
|
12
11
|
|
@@ -34,9 +33,9 @@ Then, run the installer generator:
|
|
34
33
|
$ rails g hertz:courier:twilio:install
|
35
34
|
```
|
36
35
|
|
37
|
-
The courier will use ActiveJob to asynchronously deliver the text messages, so make sure that you're
|
38
|
-
background jobs with some adapter (`inline` will work, even though it's not recommended).
|
39
|
-
`default` queue.
|
36
|
+
The courier will use ActiveJob to asynchronously deliver the text messages, so make sure that you're
|
37
|
+
executing background jobs with some adapter (`inline` will work, even though it's not recommended).
|
38
|
+
Jobs are pushed to the `default` queue.
|
40
39
|
|
41
40
|
Finally, you will have to expose a `#hertz_phone_number` method in your receiver class:
|
42
41
|
|
@@ -50,9 +49,9 @@ class User
|
|
50
49
|
end
|
51
50
|
```
|
52
51
|
|
53
|
-
If `#hertz_phone_number` returns an empty value (i.e. `false`, `nil` or an empty string) at the time
|
54
|
-
executed, the notification will not be delivered. This allows you to programmatically
|
55
|
-
for a user:
|
52
|
+
If `#hertz_phone_number` returns an empty value (i.e. `false`, `nil` or an empty string) at the time
|
53
|
+
the job is executed, the notification will not be delivered. This allows you to programmatically
|
54
|
+
enable/disable SMS notifications for a user:
|
56
55
|
|
57
56
|
```ruby
|
58
57
|
class User
|
@@ -66,8 +65,8 @@ end
|
|
66
65
|
|
67
66
|
## Usage
|
68
67
|
|
69
|
-
All you need to do in order to start delivering notifications by SMS is add `twilio` to the
|
70
|
-
statement and provide an SMS body:
|
68
|
+
All you need to do in order to start delivering notifications by SMS is add `twilio` to the
|
69
|
+
notification's `#deliver_by` statement and provide an SMS body:
|
71
70
|
|
72
71
|
```ruby
|
73
72
|
class CommentNotification < Hertz::Notification
|
data/Rakefile
CHANGED
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Hertz
|
4
|
+
module Twilio
|
5
|
+
class NotificationDeliveryJob < ActiveJob::Base
|
6
|
+
queue_as :default
|
7
|
+
|
8
|
+
def perform(notification)
|
9
|
+
return unless notification.receiver.hertz_phone_number.present?
|
10
|
+
return if notification.delivered_with?(:twilio)
|
11
|
+
|
12
|
+
twilio_client.messages.create(
|
13
|
+
to: notification.receiver.hertz_phone_number,
|
14
|
+
from: Hertz::Twilio.sender_id || Hertz::Twilio.phone_number,
|
15
|
+
body: notification.sms_body
|
16
|
+
)
|
17
|
+
|
18
|
+
notification.mark_delivered_with(:twilio)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def twilio_client
|
24
|
+
@twilio_client ||= ::Twilio::REST::Client.new(
|
25
|
+
Hertz::Twilio.account_sid,
|
26
|
+
Hertz::Twilio.auth_token
|
27
|
+
)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Hertz
|
4
|
+
module Twilio
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
source_root File.expand_path('templates', __dir__)
|
7
|
+
|
8
|
+
def copy_initializer_file
|
9
|
+
copy_file 'initializer.rb', 'config/initializers/hertz_twilio.rb'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
Hertz::
|
3
|
+
Hertz::Twilio.configure do |config|
|
4
4
|
# Your Twilio phone number.
|
5
5
|
config.phone_number = '+390123456789'
|
6
6
|
|
@@ -9,4 +9,8 @@ Hertz::Courier::Twilio.configure do |config|
|
|
9
9
|
|
10
10
|
# Your Twilio authentication token
|
11
11
|
config.auth_token = 'YourTwilioAuthToken'
|
12
|
+
|
13
|
+
# Optional: An alphanumeric sender ID that will appear instead of your phone number. Not setting
|
14
|
+
# this will just use `config.phone_number`.
|
15
|
+
config.sender_id = nil
|
12
16
|
end
|
data/lib/hertz/twilio.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'twilio-ruby'
|
4
|
+
require 'hertz'
|
5
|
+
|
6
|
+
require 'hertz/twilio/engine'
|
7
|
+
require 'hertz/twilio/version'
|
8
|
+
|
9
|
+
module Hertz
|
10
|
+
module Twilio
|
11
|
+
mattr_accessor :phone_number, :account_sid, :auth_token, :sender_id
|
12
|
+
|
13
|
+
class << self
|
14
|
+
def configure
|
15
|
+
yield(self)
|
16
|
+
end
|
17
|
+
|
18
|
+
def deliver_notification(notification)
|
19
|
+
Hertz::Twilio::NotificationDeliveryJob.perform_later(notification)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hertz-twilio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alessandro Desantis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hertz
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rails
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -208,12 +208,12 @@ files:
|
|
208
208
|
- MIT-LICENSE
|
209
209
|
- README.md
|
210
210
|
- Rakefile
|
211
|
-
- app/jobs/hertz/
|
212
|
-
- lib/generators/hertz/
|
213
|
-
- lib/generators/hertz/
|
214
|
-
- lib/hertz/
|
215
|
-
- lib/hertz/
|
216
|
-
- lib/hertz/
|
211
|
+
- app/jobs/hertz/twilio/notification_delivery_job.rb
|
212
|
+
- lib/generators/hertz/twilio/install_generator.rb
|
213
|
+
- lib/generators/hertz/twilio/templates/initializer.rb
|
214
|
+
- lib/hertz/twilio.rb
|
215
|
+
- lib/hertz/twilio/engine.rb
|
216
|
+
- lib/hertz/twilio/version.rb
|
217
217
|
homepage: https://github.com/alessandro1997/hertz-twilio
|
218
218
|
licenses:
|
219
219
|
- MIT
|
@@ -234,7 +234,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
234
234
|
version: '0'
|
235
235
|
requirements: []
|
236
236
|
rubyforge_project:
|
237
|
-
rubygems_version: 2.7.
|
237
|
+
rubygems_version: 2.7.7
|
238
238
|
signing_key:
|
239
239
|
specification_version: 4
|
240
240
|
summary: A Twilio courier for Hertz.
|
@@ -1,33 +0,0 @@
|
|
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
|
@@ -1,15 +0,0 @@
|
|
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
|
data/lib/hertz/courier/twilio.rb
DELETED
@@ -1,26 +0,0 @@
|
|
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
|