textris 0.2.1 → 0.2.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 +5 -5
- data/lib/textris.rb +6 -0
- data/lib/textris/delivery/base.rb +9 -5
- data/lib/textris/delivery/mail.rb +64 -66
- data/lib/textris/delivery/test.rb +9 -11
- data/lib/textris/delivery/twilio.rb +9 -13
- data/lib/textris/message.rb +1 -1
- data/lib/textris/version.rb +1 -1
- metadata +30 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fce987a7a0c0a6b3997a09358b786b4f6877a141
|
4
|
+
data.tar.gz: 664b9bf8c1b84a0b97395ac343efc10594911614
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d30f3592e4dc6d9582f4d5bcef2bc15f1a0e9e9fc7eb759d70e2b971d2e8a13d7b775254db4ce4beef9ca6ec8971a7607bbf0566aa7fba6841148f74dd25b678
|
7
|
+
data.tar.gz: ffbb528809ef2bb326c0de5c9ee20fbbbe9d250cc49e66e18848035e1b7dd2dbc9caff00a6be48c3a24dc145bd19242280ba9c2ae6a21fd0b983b8f70dc6dc3d
|
data/README.md
CHANGED
@@ -151,18 +151,18 @@ Currently, **textris** comes with `twilio`, `mail` and `test` delivery methods b
|
|
151
151
|
```ruby
|
152
152
|
class MyProviderDelivery < Textris::Delivery::Base
|
153
153
|
# Implement sending message to single phone number
|
154
|
-
def
|
155
|
-
|
154
|
+
def deliver(phone)
|
155
|
+
send_sms(:phone => phone, :text => message.content)
|
156
156
|
end
|
157
157
|
|
158
158
|
# ...or implement sending message to multiple phone numbers at once
|
159
|
-
def
|
160
|
-
|
159
|
+
def deliver_to_all
|
160
|
+
send_multiple_sms(:phone_array => message.to, :text => message.content)
|
161
161
|
end
|
162
162
|
end
|
163
163
|
```
|
164
164
|
|
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 *
|
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 *deliver_to_all*, the *deliver* method will be invoked multiple times.
|
166
166
|
|
167
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.
|
168
168
|
|
data/lib/textris.rb
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
module Textris
|
2
2
|
module Delivery
|
3
3
|
class Base
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
attr_reader :message
|
5
|
+
|
6
|
+
def initialize(message)
|
7
|
+
@message = message
|
8
|
+
end
|
9
|
+
|
10
|
+
def deliver_to_all
|
11
|
+
message.to.each do |to|
|
12
|
+
deliver(to)
|
9
13
|
end
|
10
14
|
end
|
11
15
|
end
|
@@ -7,89 +7,87 @@ module Textris
|
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
-
|
11
|
-
|
10
|
+
def deliver(to)
|
11
|
+
template_vars = { :to_phone => to }
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
from = apply_template from_template, template_vars
|
14
|
+
to = apply_template to_template, template_vars
|
15
|
+
subject = apply_template subject_template, template_vars
|
16
|
+
body = apply_template body_template, template_vars
|
15
17
|
|
16
|
-
|
17
|
-
to
|
18
|
-
|
19
|
-
body = apply_template body_template, message, template_vars
|
18
|
+
::Textris::Delivery::Mail::Mailer.notify(
|
19
|
+
from, to, subject, body).deliver
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
-
from, to, subject, body).deliver
|
23
|
-
end
|
22
|
+
private
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
def from_template
|
25
|
+
Rails.application.config.try(:textris_mail_from_template) ||
|
26
|
+
"%{from_name:d}-%{from_phone}@%{env:d}.%{app:d}.com"
|
27
|
+
end
|
29
28
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
29
|
+
def to_template
|
30
|
+
Rails.application.config.try(:textris_mail_to_template) ||
|
31
|
+
"%{app:d}-%{env:d}-%{to_phone}-texts@mailinator.com"
|
32
|
+
end
|
34
33
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
34
|
+
def subject_template
|
35
|
+
Rails.application.config.try(:textris_mail_subject_template) ||
|
36
|
+
"%{texter:dh} texter: %{action:h}"
|
37
|
+
end
|
39
38
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
39
|
+
def body_template
|
40
|
+
Rails.application.config.try(:textris_mail_body_template) ||
|
41
|
+
"%{content}"
|
42
|
+
end
|
44
43
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
44
|
+
def apply_template(template, variables)
|
45
|
+
template.gsub(/\%\{[a-z_:]+\}/) do |match|
|
46
|
+
directive = match.gsub(/[%{}]/, '')
|
47
|
+
key = directive.split(':').first
|
48
|
+
modifiers = directive.split(':')[1] || ''
|
50
49
|
|
51
|
-
|
52
|
-
|
53
|
-
|
50
|
+
content = get_template_interpolation(key, variables)
|
51
|
+
content = apply_template_modifiers(content, modifiers.chars)
|
52
|
+
content = 'unknown' unless content.present?
|
54
53
|
|
55
|
-
|
56
|
-
end
|
54
|
+
content
|
57
55
|
end
|
56
|
+
end
|
58
57
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
58
|
+
def get_template_interpolation(key, variables)
|
59
|
+
content = case key
|
60
|
+
when 'app', 'env'
|
61
|
+
get_rails_variable(key)
|
62
|
+
when 'texter', 'action', 'from_name', 'from_phone', 'content'
|
63
|
+
message.send(key)
|
64
|
+
else
|
65
|
+
variables[key.to_sym]
|
66
|
+
end.to_s.strip
|
67
|
+
end
|
69
68
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
end
|
69
|
+
def get_rails_variable(var)
|
70
|
+
case var
|
71
|
+
when 'app'
|
72
|
+
Rails.application.class.parent_name
|
73
|
+
when 'env'
|
74
|
+
Rails.env
|
77
75
|
end
|
76
|
+
end
|
78
77
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
end
|
78
|
+
def apply_template_modifiers(content, modifiers)
|
79
|
+
modifiers.each do |modifier|
|
80
|
+
case modifier
|
81
|
+
when 'd'
|
82
|
+
content = content.underscore.dasherize
|
83
|
+
when 'h'
|
84
|
+
content = content.humanize.gsub(/[-_]/, ' ')
|
85
|
+
when 'p'
|
86
|
+
content = Phony.format(content) rescue content
|
89
87
|
end
|
90
|
-
|
91
|
-
content
|
92
88
|
end
|
89
|
+
|
90
|
+
content
|
93
91
|
end
|
94
92
|
end
|
95
93
|
end
|
@@ -5,18 +5,16 @@ module Textris
|
|
5
5
|
def deliveries
|
6
6
|
@deliveries ||= []
|
7
7
|
end
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
:action => message.action,
|
18
|
-
:to => to))
|
19
|
-
end
|
10
|
+
def deliver(to)
|
11
|
+
self.class.deliveries.push(::Textris::Message.new(
|
12
|
+
:content => message.content,
|
13
|
+
:from_name => message.from_name,
|
14
|
+
:from_phone => message.from_phone,
|
15
|
+
:texter => message.texter,
|
16
|
+
:action => message.action,
|
17
|
+
:to => to))
|
20
18
|
end
|
21
19
|
end
|
22
20
|
end
|
@@ -1,21 +1,17 @@
|
|
1
|
-
require 'twilio-ruby'
|
2
|
-
|
3
1
|
module Textris
|
4
2
|
module Delivery
|
5
3
|
class Twilio < Textris::Delivery::Base
|
6
|
-
|
7
|
-
|
4
|
+
def deliver(to)
|
5
|
+
client.messages.create(
|
6
|
+
:from => message.from_phone,
|
7
|
+
:to => to,
|
8
|
+
:body => message.content)
|
9
|
+
end
|
8
10
|
|
9
|
-
|
10
|
-
client.messages.create(
|
11
|
-
:from => message.from_phone,
|
12
|
-
:to => to,
|
13
|
-
:body => message.content)
|
14
|
-
end
|
11
|
+
private
|
15
12
|
|
16
|
-
|
17
|
-
|
18
|
-
end
|
13
|
+
def client
|
14
|
+
@client ||= ::Twilio::REST::Client.new
|
19
15
|
end
|
20
16
|
end
|
21
17
|
end
|
data/lib/textris/message.rb
CHANGED
data/lib/textris/version.rb
CHANGED
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.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Karol Słuszniak
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: codeclimate-test-reporter
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.4'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.4'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rake
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,19 +67,19 @@ dependencies:
|
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '3.1'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
70
|
+
name: rspec-sidekiq
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
73
|
- - "~>"
|
60
74
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0
|
75
|
+
version: '2.0'
|
62
76
|
type: :development
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
80
|
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
|
-
version: '0
|
82
|
+
version: '2.0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: scrutinizer-ocular
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -81,33 +95,33 @@ dependencies:
|
|
81
95
|
- !ruby/object:Gem::Version
|
82
96
|
version: '1.0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
98
|
+
name: simplecov
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
86
100
|
requirements:
|
87
101
|
- - "~>"
|
88
102
|
- !ruby/object:Gem::Version
|
89
|
-
version: '0.
|
103
|
+
version: '0.9'
|
90
104
|
type: :development
|
91
105
|
prerelease: false
|
92
106
|
version_requirements: !ruby/object:Gem::Requirement
|
93
107
|
requirements:
|
94
108
|
- - "~>"
|
95
109
|
- !ruby/object:Gem::Version
|
96
|
-
version: '0.
|
110
|
+
version: '0.9'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
112
|
+
name: twilio-ruby
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
100
114
|
requirements:
|
101
115
|
- - "~>"
|
102
116
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
117
|
+
version: '3.12'
|
104
118
|
type: :development
|
105
119
|
prerelease: false
|
106
120
|
version_requirements: !ruby/object:Gem::Requirement
|
107
121
|
requirements:
|
108
122
|
- - "~>"
|
109
123
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
124
|
+
version: '3.12'
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
126
|
name: actionmailer
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -123,47 +137,33 @@ dependencies:
|
|
123
137
|
- !ruby/object:Gem::Version
|
124
138
|
version: '4.0'
|
125
139
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
127
|
-
requirement: !ruby/object:Gem::Requirement
|
128
|
-
requirements:
|
129
|
-
- - "~>"
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version: '0.0'
|
132
|
-
type: :runtime
|
133
|
-
prerelease: false
|
134
|
-
version_requirements: !ruby/object:Gem::Requirement
|
135
|
-
requirements:
|
136
|
-
- - "~>"
|
137
|
-
- !ruby/object:Gem::Version
|
138
|
-
version: '0.0'
|
139
|
-
- !ruby/object:Gem::Dependency
|
140
|
-
name: twilio-ruby
|
140
|
+
name: phony
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
143
|
- - "~>"
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version: '
|
145
|
+
version: '2.8'
|
146
146
|
type: :runtime
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
150
|
- - "~>"
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version: '
|
152
|
+
version: '2.8'
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
|
-
name:
|
154
|
+
name: render_anywhere
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
157
|
- - "~>"
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version: '
|
159
|
+
version: '0.0'
|
160
160
|
type: :runtime
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
164
|
- - "~>"
|
165
165
|
- !ruby/object:Gem::Version
|
166
|
-
version: '
|
166
|
+
version: '0.0'
|
167
167
|
description: Implement texter classes for sending SMS messages in similar way to how
|
168
168
|
e-mails are sent with ActionMailer-based mailers. Take advantage of e-mail proxying
|
169
169
|
and enhanced phone number parsing, among others.
|