textris 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -17
- data/lib/textris.rb +12 -1
- data/lib/textris/base.rb +1 -0
- data/lib/textris/delay/sidekiq.rb +3 -43
- data/lib/textris/delay/sidekiq/missing.rb +15 -0
- data/lib/textris/delay/sidekiq/proxy.rb +25 -0
- data/lib/textris/delay/sidekiq/worker.rb +17 -0
- data/lib/textris/version.rb +1 -1
- metadata +5 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e13df5317b09424b8db2890130f2e29d468bbaca
|
4
|
+
data.tar.gz: 77ea8801bc86ed0ee3378084445e73eeaa2e3e50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 914d3089beba2457bf2df38e1cf310cf1de2b986b7874704b8cc9658baa0cdfea5584e368e58b4d85711a074312bde4a9a978b8b25bdbd520fadd01787ec7a3c
|
7
|
+
data.tar.gz: d8e5554a3ed82a078c4d77fd949700b34c4278327397d67c63300655e6bef8992fd054808414cf5698709f9ffe4c786963438163d1cf29a2b20491376fa39fd3
|
data/README.md
CHANGED
@@ -14,7 +14,7 @@ Unlike similar gems, **textris** has some unique features:
|
|
14
14
|
- built-in support for the Twilio API thanks to the [twilio-ruby](https://github.com/twilio/twilio-ruby) gem
|
15
15
|
- multiple, per-environment configurable and chainable delivery methods
|
16
16
|
- extensible with any number of custom delivery methods (also chainable)
|
17
|
-
- background and scheduled
|
17
|
+
- background and scheduled texting thanks to integration with the [sidekiq](https://github.com/mperham/sidekiq) gem
|
18
18
|
- support for testing using self-explanatory `Textris::Base.deliveries`
|
19
19
|
- simple, extensible, fully tested code written from the ground up instead of copying *ActionMailer*
|
20
20
|
|
@@ -62,21 +62,9 @@ class User < ActiveRecord::Base
|
|
62
62
|
end
|
63
63
|
```
|
64
64
|
|
65
|
-
### Background and scheduled
|
65
|
+
### Background and scheduled
|
66
66
|
|
67
|
-
Thanks to Sidekiq integration, you can send text messages in the background to speed things up, retry in case of failures or just to do it at
|
68
|
-
|
69
|
-
```ruby
|
70
|
-
class UserTexter < Textris::Base
|
71
|
-
include Textris::Delay::Sidekiq
|
72
|
-
|
73
|
-
def welcome(user)
|
74
|
-
# ...
|
75
|
-
end
|
76
|
-
end
|
77
|
-
```
|
78
|
-
|
79
|
-
Then use one of three delay methods.
|
67
|
+
Thanks to Sidekiq integration, you can send text messages in the background to speed things up, retry in case of failures or just to do it at specific time. To do so, use one of three delay methods:
|
80
68
|
|
81
69
|
```ruby
|
82
70
|
UserTexter.delay.welcome(user)
|
@@ -86,6 +74,17 @@ UserTexter.delay_until(1.day.from_now).welcome(user)
|
|
86
74
|
|
87
75
|
> You should not call `deliver` after the action invocation when using delay. It will be called by the *Textris::Delay::Sidekiq::Worker* worker.
|
88
76
|
|
77
|
+
Keep in mind that **textris** does not install *sidekiq* for you. If you don't have it yet, [install Redis](http://redis.io/topics/quickstart) on your machine and add the *sidekiq* gem to `Gemfile`:
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
gem 'sidekiq'
|
81
|
+
```
|
82
|
+
|
83
|
+
Then run:
|
84
|
+
|
85
|
+
bundle install
|
86
|
+
bundle exec sidekiq
|
87
|
+
|
89
88
|
## Testing
|
90
89
|
|
91
90
|
Access all messages that were sent with the `:test` delivery:
|
@@ -147,7 +146,7 @@ end
|
|
147
146
|
|
148
147
|
#### Custom delivery methods
|
149
148
|
|
150
|
-
Currently, **textris** comes with `twilio`, `
|
149
|
+
Currently, **textris** comes with `twilio`, `mail` and `test` delivery methods built-in, but you can easily implement your own. Place desired delivery class in `app/deliveries/<name>_delivery.rb` (e.g. `app/deliveries/my_provider_delivery.rb`):
|
151
150
|
|
152
151
|
```ruby
|
153
152
|
class MyProviderDelivery < Textris::Delivery::Base
|
@@ -165,7 +164,7 @@ end
|
|
165
164
|
|
166
165
|
Only one of methods above must be implemented for the delivery class to work. In case of multiple phone numbers and no implementation of *send_message_to_all*, the *send_message* method will be invoked multiple times.
|
167
166
|
|
168
|
-
> You can place your custom deliveries in `app/texters` instead of `app/deliveries` if you don't want to clutter the *app* directory too much.
|
167
|
+
> You can place your custom deliveries in `app/texters` or `app/models` instead of `app/deliveries` if you don't want to clutter the *app* directory too much.
|
169
168
|
|
170
169
|
After implementing your own deliveries, you can activate them by setting app configuration:
|
171
170
|
|
data/lib/textris.rb
CHANGED
@@ -2,6 +2,18 @@ require 'action_controller'
|
|
2
2
|
require 'action_mailer'
|
3
3
|
require 'phony'
|
4
4
|
|
5
|
+
begin
|
6
|
+
require 'sidekiq'
|
7
|
+
rescue LoadError
|
8
|
+
require 'textris/delay/sidekiq/missing'
|
9
|
+
|
10
|
+
Textris::Delay::Sidekiq.include(Textris::Delay::Sidekiq::Missing)
|
11
|
+
else
|
12
|
+
require 'textris/delay/sidekiq'
|
13
|
+
require 'textris/delay/sidekiq/proxy'
|
14
|
+
require 'textris/delay/sidekiq/worker'
|
15
|
+
end
|
16
|
+
|
5
17
|
require 'textris/base'
|
6
18
|
require 'textris/message'
|
7
19
|
require 'textris/delivery'
|
@@ -9,4 +21,3 @@ require 'textris/delivery/base'
|
|
9
21
|
require 'textris/delivery/test'
|
10
22
|
require 'textris/delivery/mail'
|
11
23
|
require 'textris/delivery/twilio'
|
12
|
-
require 'textris/delay/sidekiq'
|
data/lib/textris/base.rb
CHANGED
@@ -1,48 +1,6 @@
|
|
1
|
-
require 'sidekiq'
|
2
|
-
|
3
1
|
module Textris
|
4
2
|
module Delay
|
5
3
|
module Sidekiq
|
6
|
-
class Worker
|
7
|
-
include ::Sidekiq::Worker
|
8
|
-
|
9
|
-
def perform(texter, action, params)
|
10
|
-
texter = texter.safe_constantize
|
11
|
-
|
12
|
-
if texter.present?
|
13
|
-
texter.new(action, *params).call_action.deliver
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
class Proxy
|
19
|
-
def initialize(texter, options = {})
|
20
|
-
@texter = texter
|
21
|
-
@perform_in = options[:perform_in]
|
22
|
-
@perform_at = options[:perform_at]
|
23
|
-
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
def method_missing(method_name, *args)
|
28
|
-
args = [@texter, method_name, args]
|
29
|
-
|
30
|
-
if @perform_in
|
31
|
-
::Textris::Delay::Sidekiq::Worker.perform_in(@perform_in, *args)
|
32
|
-
elsif @perform_at
|
33
|
-
::Textris::Delay::Sidekiq::Worker.perform_at(@perform_at, *args)
|
34
|
-
else
|
35
|
-
::Textris::Delay::Sidekiq::Worker.perform_async(*args)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
class << self
|
41
|
-
def included(base)
|
42
|
-
base.extend(self)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
4
|
def delay
|
47
5
|
::Textris::Delay::Sidekiq::Proxy.new(self)
|
48
6
|
end
|
@@ -64,4 +22,6 @@ module Textris
|
|
64
22
|
end
|
65
23
|
end
|
66
24
|
end
|
67
|
-
end
|
25
|
+
end
|
26
|
+
|
27
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Textris
|
2
|
+
module Delay
|
3
|
+
module Sidekiq
|
4
|
+
module Missing
|
5
|
+
def sidekiq_missing(*args)
|
6
|
+
raise(LoadError, "Sidekiq is required to delay sending messages")
|
7
|
+
end
|
8
|
+
|
9
|
+
alias_method :delay, :sidekiq_missing
|
10
|
+
alias_method :delay_for, :sidekiq_missing
|
11
|
+
alias_method :delay_until, :sidekiq_missing
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Textris
|
2
|
+
module Delay
|
3
|
+
module Sidekiq
|
4
|
+
class Proxy
|
5
|
+
def initialize(texter, options = {})
|
6
|
+
@texter = texter
|
7
|
+
@perform_in = options[:perform_in]
|
8
|
+
@perform_at = options[:perform_at]
|
9
|
+
end
|
10
|
+
|
11
|
+
def method_missing(method_name, *args)
|
12
|
+
args = [@texter, method_name, args]
|
13
|
+
|
14
|
+
if @perform_in
|
15
|
+
::Textris::Delay::Sidekiq::Worker.perform_in(@perform_in, *args)
|
16
|
+
elsif @perform_at
|
17
|
+
::Textris::Delay::Sidekiq::Worker.perform_at(@perform_at, *args)
|
18
|
+
else
|
19
|
+
::Textris::Delay::Sidekiq::Worker.perform_async(*args)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Textris
|
2
|
+
module Delay
|
3
|
+
module Sidekiq
|
4
|
+
class Worker
|
5
|
+
include ::Sidekiq::Worker
|
6
|
+
|
7
|
+
def perform(texter, action, params)
|
8
|
+
texter = texter.safe_constantize
|
9
|
+
|
10
|
+
if texter.present?
|
11
|
+
texter.new(action, *params).call_action.deliver
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/textris/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: textris
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Karol Słuszniak
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -164,20 +164,6 @@ dependencies:
|
|
164
164
|
- - "~>"
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '2.8'
|
167
|
-
- !ruby/object:Gem::Dependency
|
168
|
-
name: sidekiq
|
169
|
-
requirement: !ruby/object:Gem::Requirement
|
170
|
-
requirements:
|
171
|
-
- - "~>"
|
172
|
-
- !ruby/object:Gem::Version
|
173
|
-
version: '3.2'
|
174
|
-
type: :runtime
|
175
|
-
prerelease: false
|
176
|
-
version_requirements: !ruby/object:Gem::Requirement
|
177
|
-
requirements:
|
178
|
-
- - "~>"
|
179
|
-
- !ruby/object:Gem::Version
|
180
|
-
version: '3.2'
|
181
167
|
description: Implement texter classes for sending SMS messages in similar way to how
|
182
168
|
e-mails are sent with ActionMailer-based mailers. Take advantage of e-mail proxying
|
183
169
|
and enhanced phone number parsing, among others.
|
@@ -191,6 +177,9 @@ files:
|
|
191
177
|
- lib/textris.rb
|
192
178
|
- lib/textris/base.rb
|
193
179
|
- lib/textris/delay/sidekiq.rb
|
180
|
+
- lib/textris/delay/sidekiq/missing.rb
|
181
|
+
- lib/textris/delay/sidekiq/proxy.rb
|
182
|
+
- lib/textris/delay/sidekiq/worker.rb
|
194
183
|
- lib/textris/delivery.rb
|
195
184
|
- lib/textris/delivery/base.rb
|
196
185
|
- lib/textris/delivery/mail.rb
|