textris 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +22 -7
- data/lib/textris.rb +1 -0
- data/lib/textris/delivery.rb +5 -1
- data/lib/textris/delivery/twilio.rb +22 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f1998dcf38ee77fccc6357527ad6129fe3ce6e7
|
4
|
+
data.tar.gz: 84953db540e4d1ceff87f3d44157d98df7727f55
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a2d83ecaaf191b1e3a0e8cca147f76d2ee0bbd5e175ae9c249f6986f8934d4fd58bae41499a0771dfacf25a9b36558b2fa06f74f9197cde7446060fd13dfe51
|
7
|
+
data.tar.gz: d47fceee3c971d97f4025d97dc306c3bb3631f031349ff465360b579ca9beaa9f161a32592a58c5a49c4ab7b9870191d8adfa727aa8f394b3a4d10252eb0f0fb
|
data/README.md
CHANGED
@@ -5,14 +5,13 @@ Simple gem for implementing texter classes which allow sending SMS messages in s
|
|
5
5
|
Unlike similar gems, **Textris** has some unique features:
|
6
6
|
|
7
7
|
- e-mail proxy allowing to inspect messages using [Mailinator](https://mailinator.com/) or similar service
|
8
|
-
- phone number E164 validation and normalization with the [
|
8
|
+
- phone number E164 validation and normalization with the [phony](https://github.com/floere/phony) gem
|
9
9
|
- multiple, per-environment configurable and chainable delivery methods
|
10
|
+
- built-in support for the Twilio API thanks to the [twilio-ruby](https://github.com/twilio/twilio-ruby) gem
|
10
11
|
- extensible with any number of custom delivery methods (also chainable)
|
11
12
|
- support for testing using self-explanatory `Textris::Base.deliveries`
|
12
13
|
- simple, extensible code written from the ground up instead of copying *ActionMailer*
|
13
14
|
|
14
|
-
Currently, this gem comes with `test` and `mail` delivery methods, so there's no method for any real SMS gateway yet. Still, you can easily implement your own - see the [Custom delivery methods](#custom-delivery-methods) chapter below.
|
15
|
-
|
16
15
|
## Installation
|
17
16
|
|
18
17
|
Add to `Gemfile`:
|
@@ -57,9 +56,22 @@ class User < ActiveRecord::Base
|
|
57
56
|
end
|
58
57
|
```
|
59
58
|
|
59
|
+
### Twilio
|
60
|
+
|
61
|
+
In order to use Twilio with textris, you must pre-configure the *twilio-ruby* settings. Create the `config/initializers/twilio.rb`:
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
Twilio.configure do |config|
|
65
|
+
config.account_sid = 'some_sid'
|
66
|
+
config.auth_token = 'some_auth_token'
|
67
|
+
end
|
68
|
+
```
|
69
|
+
|
70
|
+
> Unless otherwise [configured](#configuration), Twilio will be the default delivery method in `development` and `production` environment, while the `test` method will be used in (surprise, surprise) `test` environment by default.
|
71
|
+
|
60
72
|
### Custom delivery methods
|
61
73
|
|
62
|
-
Place desired delivery method in `app/deliveries/<name>_delivery.rb` (e.g. `app/deliveries/my_provider_delivery.rb`):
|
74
|
+
Currently, textris comes with `twilio`, `test` and `mail` delivery methods built-in, but you can easily implement your own. Place desired delivery method class in `app/deliveries/<name>_delivery.rb` (e.g. `app/deliveries/my_provider_delivery.rb`):
|
63
75
|
|
64
76
|
```ruby
|
65
77
|
class MyProviderDelivery < Textris::Delivery::Base
|
@@ -75,10 +87,10 @@ class MyProviderDelivery < Textris::Delivery::Base
|
|
75
87
|
end
|
76
88
|
```
|
77
89
|
|
78
|
-
> **NOTE**: You can also place your custom deliveries in `app/texters` if you don't want to clutter the *app* directory too much.
|
79
|
-
|
80
90
|
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.
|
81
91
|
|
92
|
+
> **NOTE**: You can also place your custom deliveries in `app/texters` if you don't want to clutter the *app* directory too much.
|
93
|
+
|
82
94
|
After implementing your own deliveries, you can activate them by setting app configuration:
|
83
95
|
|
84
96
|
```ruby
|
@@ -86,7 +98,7 @@ After implementing your own deliveries, you can activate them by setting app con
|
|
86
98
|
config.textris_delivery_method = :my_provider
|
87
99
|
|
88
100
|
# Chain your new delivery with others, including stock ones
|
89
|
-
config.textris_delivery_method = [:my_provider, :mail]
|
101
|
+
config.textris_delivery_method = [:my_provider, :twilio, :mail]
|
90
102
|
```
|
91
103
|
|
92
104
|
## Testing
|
@@ -120,6 +132,9 @@ You can change default settings by placing them in any of environment files, lik
|
|
120
132
|
Choose the delivery method:
|
121
133
|
|
122
134
|
```ruby
|
135
|
+
# Send messages via the Twilio REST API using the twilio-ruby gem
|
136
|
+
config.textris_delivery_method = :twilio
|
137
|
+
|
123
138
|
# Don't send anything, access your messages via Textris::Base.deliveries
|
124
139
|
config.textris_delivery_method = :test
|
125
140
|
|
data/lib/textris.rb
CHANGED
data/lib/textris/delivery.rb
CHANGED
@@ -6,7 +6,11 @@ module Textris
|
|
6
6
|
methods = Rails.application.config.try(:textris_delivery_method)
|
7
7
|
methods = [*methods].compact
|
8
8
|
if methods.blank?
|
9
|
-
|
9
|
+
if Rails.env.test?
|
10
|
+
methods = [:test]
|
11
|
+
else
|
12
|
+
methods = [:twilio]
|
13
|
+
end
|
10
14
|
end
|
11
15
|
|
12
16
|
methods.map do |method|
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'twilio-ruby'
|
2
|
+
|
3
|
+
module Textris
|
4
|
+
module Delivery
|
5
|
+
class Twilio < Textris::Delivery::Base
|
6
|
+
class << self
|
7
|
+
private
|
8
|
+
|
9
|
+
def send_message(to, message)
|
10
|
+
client.messages.create(
|
11
|
+
:from => message.from_phone,
|
12
|
+
:to => to,
|
13
|
+
:body => message.content)
|
14
|
+
end
|
15
|
+
|
16
|
+
def client
|
17
|
+
@client ||= Twilio::REST::Client.new
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: textris
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Karol Słuszniak
|
@@ -54,6 +54,7 @@ files:
|
|
54
54
|
- lib/textris/delivery/base.rb
|
55
55
|
- lib/textris/delivery/mail.rb
|
56
56
|
- lib/textris/delivery/test.rb
|
57
|
+
- lib/textris/delivery/twilio.rb
|
57
58
|
- lib/textris/message.rb
|
58
59
|
homepage: http://github.com/visualitypl/textris
|
59
60
|
licenses:
|