hertz-courier-twilio 1.0.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 686cfdb462120ccab5c110158373764e03e6168c
4
+ data.tar.gz: 453aecc745aba06d542e2349325e409f84d6f0b8
5
+ SHA512:
6
+ metadata.gz: 8f428a12a91a9d1d05a62e74dcec0ca9024211c447d9a97409710341d96e7860f54934ae37b8dcd61e460551a14bd2be27cfbac5e4708acb63c72bf6250ed198
7
+ data.tar.gz: d1d17d00836ba37ecc6f5c1abb979a32dbebdfb96b6fe93e58373f9ad1930c7c91f7dd460e9c7d077fd45d74fff82fc4397d5cadbf70c0a661ca41c6bab23837
@@ -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.
@@ -0,0 +1,97 @@
1
+ # Hertz::Courier::Twilio
2
+
3
+ [![Dependency Status](https://gemnasium.com/badges/github.com/alessandro1997/hertz-courier-twilio.svg)](https://gemnasium.com/github.com/alessandro1997/hertz-courier-twilio)
4
+ [![Code Climate](https://codeclimate.com/github/alessandro1997/hertz-courier-twilio/badges/gpa.svg)](https://codeclimate.com/github/alessandro1997/hertz-courier-twilio)
5
+
6
+ This is a [Hertz](https://github.com/alessandro1997/hertz) courier for sending
7
+ notifications to your users via SMS by leveraging the
8
+ [Twilio](https://www.twilio.com) API.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'hertz-courier-twilio'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ ```console
21
+ $ bundle
22
+ ```
23
+
24
+ Or install it yourself as:
25
+
26
+ ```console
27
+ $ gem install hertz-courier-twilio
28
+ ```
29
+
30
+ Then, run the installer generator:
31
+
32
+ ```console
33
+ $ rails g hertz:courier:twilio:install
34
+ ```
35
+
36
+ The courier will use ActiveJob to asynchronously deliver the text messages, so
37
+ make sure that you're executing background jobs with some adapter (`inline` will
38
+ work, even though it's not recommended). Jobs are pushed to the `default` queue.
39
+
40
+ Finally, you will have to expose a `#hertz_phone_number` method in your receiver
41
+ 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
54
+ string) at the time the job is executed, the notification will not be delivered.
55
+ This allows you to programmatically enable/disable SMS notifications 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
70
+ `twilio` to the notification's `deliver_by` 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
+ ## Contributing
85
+
86
+ Bug reports and pull requests are welcome on GitHub at
87
+ https://github.com/alessandro1997/hertz-courier-twilio.
88
+
89
+ ## License
90
+
91
+ The gem is available as open source under the terms of the
92
+ [MIT License](http://opensource.org/licenses/MIT).
93
+
94
+ # To do
95
+
96
+ - [ ] Allow changing the job's queue
97
+ - [ ] Store notification delivery in the DB to avoid resending
@@ -0,0 +1,30 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Hertz'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+ load 'rails/tasks/statistics.rake'
20
+
21
+ Bundler::GemHelper.install_tasks
22
+
23
+ Rake::TestTask.new(:spec) do |t|
24
+ t.libs << 'lib'
25
+ t.libs << 'spec'
26
+ t.pattern = 'spec/**/*_spec.rb'
27
+ t.verbose = false
28
+ end
29
+
30
+ task default: :spec
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+ module Hertz
3
+ module Courier
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
+
11
+ twilio_client.messages.create(
12
+ to: notification.receiver.hertz_phone_number,
13
+ from: Hertz::Courier::Twilio.phone_number,
14
+ body: notification.sms_body
15
+ )
16
+ end
17
+
18
+ private
19
+
20
+ def twilio_client
21
+ @twilio_client ||= ::Twilio::REST::Client.new(
22
+ Hertz::Courier::Twilio.account_sid,
23
+ Hertz::Courier::Twilio.auth_token
24
+ )
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+ module Hertz
3
+ module Courier
4
+ module Twilio
5
+ class InstallGenerator < Rails::Generators::Base
6
+ source_root File.expand_path('../templates', __FILE__)
7
+
8
+ def copy_initializer_file
9
+ copy_file 'initializer.rb', 'config/initializers/hertz_twilio.rb'
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+ Hertz::Courier::Twilio.configure do |config|
3
+ # Your Twilio phone number.
4
+ config.phone_number = '+390123456789'
5
+
6
+ # Your Twilio account's SID.
7
+ config.account_sid = 'YourTwilioAccountSid'
8
+
9
+ # Your Twilio authentication token
10
+ config.auth_token = 'YourTwilioAuthToken'
11
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+ require 'twilio-ruby'
3
+ require 'hertz'
4
+
5
+ require 'hertz/courier/twilio/engine'
6
+ require 'hertz/courier/twilio/version'
7
+
8
+ module Hertz
9
+ module Courier
10
+ module Twilio
11
+ mattr_accessor :phone_number, :account_sid, :auth_token
12
+
13
+ class << self
14
+ def configure
15
+ yield(self)
16
+ end
17
+
18
+ def deliver_notification(notification)
19
+ Hertz::Courier::Twilio::NotificationDeliveryJob
20
+ .perform_later(notification)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+ module Hertz
3
+ module Courier
4
+ module Twilio
5
+ class Engine < ::Rails::Engine
6
+ isolate_namespace Hertz::Courier::Twilio
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+ module Hertz
3
+ module Courier
4
+ module Twilio
5
+ VERSION = '1.0.0'
6
+ end
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,221 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hertz-courier-twilio
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Alessandro Desantis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-05-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 4.2.6
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 4.2.6
27
+ - !ruby/object:Gem::Dependency
28
+ name: hertz
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: twilio-ruby
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 4.11.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 4.11.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop-rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec-rails
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec-activejob
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: fuubar
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: faker
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: database_cleaner
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: factory_girl_rails
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: pg
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ description:
182
+ email:
183
+ - desa.alessandro@gmail.com
184
+ executables: []
185
+ extensions: []
186
+ extra_rdoc_files: []
187
+ files:
188
+ - MIT-LICENSE
189
+ - README.md
190
+ - Rakefile
191
+ - app/jobs/hertz/courier/twilio/notification_delivery_job.rb
192
+ - lib/generators/hertz/courier/twilio/install_generator.rb
193
+ - lib/generators/hertz/courier/twilio/templates/initializer.rb
194
+ - lib/hertz/courier/twilio.rb
195
+ - lib/hertz/courier/twilio/engine.rb
196
+ - lib/hertz/courier/twilio/version.rb
197
+ homepage: https://github.com/alessandro1997/hertz-courier-twilio
198
+ licenses:
199
+ - MIT
200
+ metadata: {}
201
+ post_install_message:
202
+ rdoc_options: []
203
+ require_paths:
204
+ - lib
205
+ required_ruby_version: !ruby/object:Gem::Requirement
206
+ requirements:
207
+ - - ">="
208
+ - !ruby/object:Gem::Version
209
+ version: '0'
210
+ required_rubygems_version: !ruby/object:Gem::Requirement
211
+ requirements:
212
+ - - ">="
213
+ - !ruby/object:Gem::Version
214
+ version: '0'
215
+ requirements: []
216
+ rubyforge_project:
217
+ rubygems_version: 2.5.1
218
+ signing_key:
219
+ specification_version: 4
220
+ summary: A Twilio courier for Hertz.
221
+ test_files: []