textris 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 22e7162b57526b114af677ddabf1d417f97c31b7
4
- data.tar.gz: 15f9e84235920d7413b252ed751e80023a5b15b7
3
+ metadata.gz: c892d39927e7381aa8d34757802e9102d3341681
4
+ data.tar.gz: 63b2c323d52306386dd787c4304c98f458023715
5
5
  SHA512:
6
- metadata.gz: 93312a94c10bab68d1faff3fc82d8fb882a5ffc0bd462e93e075cf28e2087176e10c48f2ee6dabe27cd6bd6b78ec89505037fe2aa103597052543782ce0cfc16
7
- data.tar.gz: 1ef7417175290cbec6812c6c9c718d15f88c0fd98c1bafe25d7f0607a591d582f5c5403539bcb8f4058f443326a533ae002b9b66f9c8a1ad5f9bd915aafd15e6
6
+ metadata.gz: 2a8b73f20130a57a8b226eff56d89cc39b1b875265edc2bcc1fea1b5cc519bfb72f009bb709436e6490de1e29715955f2faae1f33a3e341b81e4ba99b4d4db55
7
+ data.tar.gz: 1ade51f79ebf729434c12c9a470500da2c99e0c4b87af1c01f102c2f41a05bde92f5cc2fc6e36866c9201e57fae632e308edbfcda86190467d2f3c076e3f77df
data/README.md CHANGED
@@ -12,13 +12,15 @@ Unlike similar gems, **textris** has some unique features:
12
12
 
13
13
  - e-mail proxy allowing to inspect messages using [Mailinator](https://mailinator.com/) or similar service
14
14
  - phone number E164 validation and normalization with the [phony](https://github.com/floere/phony) gem
15
- - built-in support for the Twilio API thanks to integration with the [twilio-ruby](https://github.com/twilio/twilio-ruby) gem
15
+ - built-in support for the Twilio and Nexmo APIs with [twilio-ruby](https://github.com/twilio/twilio-ruby) and [nexmo](https://github.com/timcraft/nexmo) gems
16
16
  - multiple, per-environment configurable and chainable delivery methods
17
17
  - extensible with any number of custom delivery methods (also chainable)
18
18
  - background and scheduled texting thanks to integration with the [sidekiq](https://github.com/mperham/sidekiq) gem
19
19
  - support for testing using self-explanatory `Textris::Base.deliveries`
20
20
  - simple, extensible, fully tested code written from the ground up instead of copying *ActionMailer*
21
21
 
22
+ See the [blog entry](http://www.visuality.pl/posts/txt-messaging-with-textris-gem) for the whole story and a practical usage example.
23
+
22
24
  ## Installation
23
25
 
24
26
  Add to `Gemfile`:
@@ -124,6 +126,9 @@ Below you'll find sample settings for any of supported delivery methods along wi
124
126
  # Send messages via the Twilio REST API
125
127
  config.textris_delivery_method = :twilio
126
128
 
129
+ # Send messages via the Nexmo API
130
+ config.textris_delivery_method = :nexmo
131
+
127
132
  # Don't send anything, log messages into Rails logger
128
133
  config.textris_delivery_method = :log
129
134
 
@@ -133,8 +138,8 @@ config.textris_delivery_method = :test
133
138
  # Send e-mails instead of SMSes in order to inspect their content
134
139
  config.textris_delivery_method = :mail
135
140
 
136
- # Chain multiple delivery methods (e.g. to have e-mail backups of your messages)
137
- config.textris_delivery_method = [:mail, :test]
141
+ # Chain multiple delivery methods (e.g. to have e-mail and log backups of messages)
142
+ config.textris_delivery_method = [:twilio, :mail, :log]
138
143
  ```
139
144
 
140
145
  > Unless otherwise configured, default delivery methods will be: *log* in `development` environment, *test* in `test` environment and *mail* in `production` environment. All these come with reasonable defaults and will work with no further configuration.
@@ -156,6 +161,17 @@ Twilio.configure do |config|
156
161
  end
157
162
  ```
158
163
 
164
+ #### Nexmo
165
+
166
+ In order to use Nexmo with **textris**, you need to include the `nexmo` gem in your `Gemfile`:
167
+
168
+ ```ruby
169
+ gem 'nexmo'
170
+ ```
171
+
172
+ The Nexmo gem uses the environment variables `NEXMO_API_KEY` and `NEXMO_API_SECRET` to authenticate with the API.
173
+ Therefore the safest way to provide authentication credentials is to set these variables in your application environment.
174
+
159
175
  #### Log
160
176
 
161
177
  **textris** logger has similar logging behavior to ActionMailer. It will log single line to *info* log with production in mind and then a couple details to *debug* log. You can change the log level for the whole output:
@@ -166,7 +182,7 @@ config.textris_log_level = :info
166
182
 
167
183
  #### Custom delivery methods
168
184
 
169
- 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`):
185
+ Currently, **textris** comes with several 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`):
170
186
 
171
187
  ```ruby
172
188
  class MyProviderDelivery < Textris::Delivery::Base
@@ -253,3 +269,5 @@ Implementing new delivery methods in Pull Requests is strongly encouraged. Start
253
269
  2. If delivery depends on any gems, don't add them as runtime dependencies. You can (and should in order to write complete specs) add them as development dependencies.
254
270
  3. Delivery code must load without exceptions even when dependent libraries are missing. Specs should test such case (you can use `remove_const` to undefine loaded consts).
255
271
  4. New deliveries are expected to have 100% test coverage. Run `COVERAGE=1 bundle exec rake spec` to generate *simplecov* coverage into the **coverage/index.html** file.
272
+
273
+ The commit in which [the log delivery was added](https://github.com/visualitypl/textris/commit/7c3231ca5eeb94cca01a3beced19a1a909299faf) is an example of delivery method addition that meets all guidelines listed above.
@@ -28,3 +28,4 @@ require 'textris/delivery/test'
28
28
  require 'textris/delivery/mail'
29
29
  require 'textris/delivery/log'
30
30
  require 'textris/delivery/twilio'
31
+ require 'textris/delivery/nexmo'
@@ -0,0 +1,18 @@
1
+ module Textris
2
+ module Delivery
3
+ class Nexmo < Textris::Delivery::Base
4
+ def deliver(phone)
5
+ client.send_message(
6
+ from: message.from_phone,
7
+ to: phone,
8
+ text: message.content
9
+ )
10
+ end
11
+
12
+ private
13
+ def client
14
+ @client ||= ::Nexmo::Client.new
15
+ end
16
+ end
17
+ end
18
+ end
@@ -41,12 +41,14 @@ module Textris
41
41
  end
42
42
 
43
43
  def from
44
- if @from_name.present? && @from_phone.present?
45
- "#{@from_name} <#{Phony.format(@from_phone)}>"
44
+ if @from_phone.present?
45
+ if @from_name.present?
46
+ "#{@from_name} <#{Phony.format(@from_phone)}>"
47
+ else
48
+ Phony.format(@from_phone)
49
+ end
46
50
  elsif @from_name.present?
47
51
  @from_name
48
- elsif @from_phone.present?
49
- Phony.format(@from_phone)
50
52
  end
51
53
  end
52
54
 
@@ -1,3 +1,3 @@
1
1
  module Textris
2
- VERSION = '0.3.1'
2
+ VERSION = '0.3.2'
3
3
  end
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.3.1
4
+ version: 0.3.2
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-19 00:00:00.000000000 Z
11
+ date: 2015-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: '3.12'
125
+ - !ruby/object:Gem::Dependency
126
+ name: nexmo
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '2.0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '2.0'
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: actionmailer
127
141
  requirement: !ruby/object:Gem::Requirement
@@ -185,6 +199,7 @@ files:
185
199
  - lib/textris/delivery/base.rb
186
200
  - lib/textris/delivery/log.rb
187
201
  - lib/textris/delivery/mail.rb
202
+ - lib/textris/delivery/nexmo.rb
188
203
  - lib/textris/delivery/test.rb
189
204
  - lib/textris/delivery/twilio.rb
190
205
  - lib/textris/message.rb