textris 0.1.7 → 0.1.8

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0715eb5a0c4ce47948654b5353c7d67b4f6ea3da
4
- data.tar.gz: 00e2a1a8c37cd5e3f6b478a41173d5293dfa3098
3
+ metadata.gz: 809b477aaf1b029a62e607a176a28fd472d39278
4
+ data.tar.gz: f016ff50375a87cb76639ada746e94a1fe5b147e
5
5
  SHA512:
6
- metadata.gz: a91454d5a3975a73149d944549a965b1f492f23de8671259f162d823ddd953fc82839c650e220058a8d2d8fd36fa3a3440b6d2e5c509db1b325d57170b34f2b8
7
- data.tar.gz: 58ccf8ef1e8ccb8d7b0f49f16e801285346dd65db865b9e890e710d80ac5d53179ab3ad124f98528c56136949f09d5168c2d2a6324d855752c890e93b5771014
6
+ metadata.gz: 35fdb014b8dd1c9fd44900d6faf8c0e02919975df0d597e1cfe5268f3cfad74d23c54e1c4a90f46c9261155dece5b9c80a7b49eb76378df264f786615f423428
7
+ data.tar.gz: a7e10be07676138514db7c118e68f12c55bab309ab7ce40f989f7a8640b8055d464de2d29507ff44606763c116b887392de06094b16921a669b8fcfe15848cf9
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # textris
2
2
 
3
+ [![Build Status](https://travis-ci.org/visualitypl/textris.svg)](https://travis-ci.org/visualitypl/textris)
3
4
  [![Code Climate](https://codeclimate.com/github/visualitypl/textris/badges/gpa.svg)](https://codeclimate.com/github/visualitypl/textris)
4
5
 
5
6
  Simple gem for implementing texter classes which allow sending SMS messages in similar way to how e-mails are implemented and sent with ActionMailer-based mailers.
@@ -8,11 +9,11 @@ Unlike similar gems, **textris** has some unique features:
8
9
 
9
10
  - e-mail proxy allowing to inspect messages using [Mailinator](https://mailinator.com/) or similar service
10
11
  - phone number E164 validation and normalization with the [phony](https://github.com/floere/phony) gem
11
- - multiple, per-environment configurable and chainable delivery methods
12
12
  - built-in support for the Twilio API thanks to the [twilio-ruby](https://github.com/twilio/twilio-ruby) gem
13
+ - multiple, per-environment configurable and chainable delivery methods
13
14
  - extensible with any number of custom delivery methods (also chainable)
14
15
  - support for testing using self-explanatory `Textris::Base.deliveries`
15
- - simple, extensible code written from the ground up instead of copying *ActionMailer*
16
+ - simple, extensible and fully tested code written from the ground up instead of copying guts of *ActionMailer*
16
17
 
17
18
  ## Installation
18
19
 
@@ -58,51 +59,6 @@ class User < ActiveRecord::Base
58
59
  end
59
60
  ```
60
61
 
61
- ### Twilio
62
-
63
- In order to use Twilio with **textris**, you must pre-configure the *twilio-ruby* settings. Create the `config/initializers/twilio.rb`:
64
-
65
- ```ruby
66
- Twilio.configure do |config|
67
- config.account_sid = 'some_sid'
68
- config.auth_token = 'some_auth_token'
69
- end
70
- ```
71
-
72
- > 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.
73
-
74
- ### Custom delivery methods
75
-
76
- Currently, **textris** comes with `twilio`, `test` and `mail` 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`):
77
-
78
- ```ruby
79
- class MyProviderDelivery < Textris::Delivery::Base
80
- # Implement sending message to single phone number
81
- def self.send_message(phone, message)
82
- some_send_method(:phone => phone, :text => message.content)
83
- end
84
-
85
- # ...or implement sending message to multiple phone numbers at once
86
- def self.send_message_to_all(message)
87
- other_send_method(:phone_array => message.to, :text => message.content)
88
- end
89
- end
90
- ```
91
-
92
- 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.
93
-
94
- > 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.
95
-
96
- After implementing your own deliveries, you can activate them by setting app configuration:
97
-
98
- ```ruby
99
- # Use your new delivery
100
- config.textris_delivery_method = :my_provider
101
-
102
- # Chain your new delivery with others, including stock ones
103
- config.textris_delivery_method = [:my_provider, :twilio, :mail]
104
- ```
105
-
106
62
  ## Testing
107
63
 
108
64
  Access all messages that were sent with the `:test` delivery:
@@ -133,8 +89,10 @@ You can change default settings by placing them in any of environment files, lik
133
89
 
134
90
  ### Choosing and chaining delivery methods
135
91
 
92
+ Below you'll find sample settings for any of supported delivery methods along with short description of each:
93
+
136
94
  ```ruby
137
- # Send messages via the Twilio REST API using the twilio-ruby gem
95
+ # Send messages via the Twilio REST API
138
96
  config.textris_delivery_method = :twilio
139
97
 
140
98
  # Don't send anything, access your messages via Textris::Base.deliveries
@@ -147,6 +105,51 @@ config.textris_delivery_method = :mail
147
105
  config.textris_delivery_method = [:mail, :test]
148
106
  ```
149
107
 
108
+ > Unless otherwise configured, *Twilio* will be the default delivery method in `development` and `production` environments, while the *test* method will be used in `test` environment by default.
109
+
110
+ #### Twilio
111
+
112
+ In order to use Twilio with **textris**, you must pre-configure the *twilio-ruby* settings. Create the `config/initializers/twilio.rb`:
113
+
114
+ ```ruby
115
+ Twilio.configure do |config|
116
+ config.account_sid = 'some_sid'
117
+ config.auth_token = 'some_auth_token'
118
+ end
119
+ ```
120
+
121
+ #### Custom delivery methods
122
+
123
+ Currently, **textris** comes with `twilio`, `test` and `mail` 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`):
124
+
125
+ ```ruby
126
+ class MyProviderDelivery < Textris::Delivery::Base
127
+ # Implement sending message to single phone number
128
+ def self.send_message(phone, message)
129
+ some_send_method(:phone => phone, :text => message.content)
130
+ end
131
+
132
+ # ...or implement sending message to multiple phone numbers at once
133
+ def self.send_message_to_all(message)
134
+ other_send_method(:phone_array => message.to, :text => message.content)
135
+ end
136
+ end
137
+ ```
138
+
139
+ 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.
140
+
141
+ > 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.
142
+
143
+ After implementing your own deliveries, you can activate them by setting app configuration:
144
+
145
+ ```ruby
146
+ # Use your new delivery
147
+ config.textris_delivery_method = :my_provider
148
+
149
+ # Chain your new delivery with others, including stock ones
150
+ config.textris_delivery_method = [:my_provider, :twilio, :mail]
151
+ ```
152
+
150
153
  ### Configuring the mail delivery
151
154
 
152
155
  **textris** comes with reasonable defaults for the `mail` delivery method. It will send messages to a Mailinator address specific to the application name, environment and target phone number. You can customize the mail delivery by setting appropriate templates presented below.
@@ -167,18 +170,18 @@ config.textris_mail_subject_template = '%{texter:dh} texter: %{action:h}'
167
170
  config.textris_mail_body_template = '%{content}'
168
171
  ```
169
172
 
170
- ### Template interpolation
173
+ #### Template interpolation
171
174
 
172
175
  You can use the following interpolations in your mail templates:
173
176
 
174
- - `app`: application name (like `AppName`)
175
- - `env`: enviroment name (like `test` or `production`)
176
- - `texter`: texter name (like `User`)
177
- - `action`: action name (like `welcome`)
178
- - `from_name`: name of the sender (like `Our Team`)
179
- - `from_phone`: phone number of the sender (like `48666777888`)
180
- - `to_phone`: phone number of the recipient (like `48111222333`)
181
- - `content`: message content (like `Welcome to our system, Mr Jones!`)
177
+ - `%{app}`: application name (like `AppName`)
178
+ - `%{env}`: enviroment name (like `test` or `production`)
179
+ - `%{texter}`: texter name (like `User`)
180
+ - `%{action}`: action name (like `welcome`)
181
+ - `%{from_name}`: name of the sender (like `Our Team`)
182
+ - `%{from_phone}`: phone number of the sender (like `48666777888`)
183
+ - `%{to_phone}`: phone number of the recipient (like `48111222333`)
184
+ - `%{content}`: message content (like `Welcome to our system, Mr Jones!`)
182
185
 
183
186
  You can add optional interpolation modifiers using the `%{variable:modifiers}` syntax. These are most useful for making names e-mail friendly. The following modifiers are available:
184
187
 
@@ -188,7 +191,7 @@ You can add optional interpolation modifiers using the `%{variable:modifiers}` s
188
191
 
189
192
  ## Contributing
190
193
 
191
- 1. Fork it (https://github.com/visualitypl/codegrade/fork)
194
+ 1. Fork it (https://github.com/visualitypl/textris/fork)
192
195
  2. Create your feature branch (`git checkout -b my-new-feature`)
193
196
  3. Commit your changes (`git commit -am 'Add some feature'`)
194
197
  4. Push to the branch (`git push origin my-new-feature`)
@@ -2,11 +2,17 @@ require 'render_anywhere'
2
2
 
3
3
  module Textris
4
4
  class Base
5
+ class RenderingController < RenderAnywhere::RenderingController
6
+ def default_url_options
7
+ ActionMailer::Base.default_url_options || {}
8
+ end
9
+ end
10
+
5
11
  include RenderAnywhere
6
12
 
7
13
  class << self
8
14
  def deliveries
9
- ::Textris::Delivery::Test.messages
15
+ ::Textris::Delivery::Test.deliveries
10
16
  end
11
17
 
12
18
  def with_defaults(options)
@@ -27,12 +33,6 @@ module Textris
27
33
  end
28
34
  end
29
35
 
30
- class RenderingController < RenderAnywhere::RenderingController
31
- def default_url_options
32
- ActionMailer::Base.default_url_options || {}
33
- end
34
- end
35
-
36
36
  def initialize(action, *args)
37
37
  @action = action
38
38
  @args = args
@@ -49,27 +49,26 @@ module Textris
49
49
  modifiers = directive.split(':')[1] || ''
50
50
 
51
51
  content = get_template_interpolation(var, message, vars)
52
- content = apply_template_modifiers(content, modifiers)
52
+ content = apply_template_modifiers(content, modifiers.chars)
53
53
 
54
54
  content
55
55
  end
56
56
  end
57
57
 
58
58
  def get_template_interpolation(var, message, vars)
59
- content = if var == 'app'
59
+ content = case var
60
+ when 'app'
60
61
  Rails.application.class.parent_name
61
- elsif var == 'env'
62
+ when 'env'
62
63
  Rails.env
63
- elsif var == 'texter' && (texter = message.texter).present?
64
- texter.to_s.split('::').last.sub(/Texter$/, '')
65
- elsif var == 'action' && (action = message.action).present?
66
- action.to_s
67
- elsif var == 'from_name' && (from = message.from_name).present?
68
- from.to_s
69
- elsif (value = vars[var.to_sym]).present?
70
- value
71
- elsif ['content', 'from_phone'].include?(var)
64
+ when 'texter'
65
+ message.texter.to_s.split('::').last.to_s.sub(/Texter$/, '')
66
+ when 'action', 'from_name'
72
67
  message.send(var)
68
+ when 'content', 'from_phone'
69
+ message.send(var)
70
+ else
71
+ value = vars[var.to_sym]
73
72
  end.to_s.strip
74
73
 
75
74
  if content.present?
@@ -80,16 +79,15 @@ module Textris
80
79
  end
81
80
 
82
81
  def apply_template_modifiers(content, modifiers)
83
- if modifiers.include?('d')
84
- content = content.underscore.dasherize
85
- end
86
-
87
- if modifiers.include?('h')
88
- content = content.humanize.gsub(/[-_]/, ' ')
89
- end
90
-
91
- if modifiers.include?('p')
92
- content = Phony.format(content) rescue content
82
+ modifiers.each do |modifier|
83
+ case modifier
84
+ when 'd'
85
+ content = content.underscore.dasherize
86
+ when 'h'
87
+ content = content.humanize.gsub(/[-_]/, ' ')
88
+ when 'p'
89
+ content = Phony.format(content) rescue content
90
+ end
93
91
  end
94
92
 
95
93
  content
@@ -2,14 +2,14 @@ module Textris
2
2
  module Delivery
3
3
  class Test < Textris::Delivery::Base
4
4
  class << self
5
- def messages
6
- @messages ||= []
5
+ def deliveries
6
+ @deliveries ||= []
7
7
  end
8
8
 
9
9
  private
10
10
 
11
11
  def send_message(to, message)
12
- messages.push(::Textris::Message.new(
12
+ deliveries.push(::Textris::Message.new(
13
13
  :content => message.content,
14
14
  :from_name => message.from_name,
15
15
  :from_phone => message.from_phone,
@@ -58,6 +58,7 @@ module Textris
58
58
  end
59
59
 
60
60
  def parse_content(content)
61
+ content = content.to_s
61
62
  content = content.gsub(/\s{1,}/, ' ')
62
63
  content = content.strip
63
64
 
@@ -0,0 +1,3 @@
1
+ module Textris
2
+ VERSION = "0.1.8"
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.1.7
4
+ version: 0.1.8
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-12 00:00:00.000000000 Z
11
+ date: 2014-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.9'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.9'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: actionmailer
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -126,6 +140,7 @@ files:
126
140
  - lib/textris/delivery/test.rb
127
141
  - lib/textris/delivery/twilio.rb
128
142
  - lib/textris/message.rb
143
+ - lib/textris/version.rb
129
144
  homepage: http://github.com/visualitypl/textris
130
145
  licenses:
131
146
  - MIT