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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e13df5317b09424b8db2890130f2e29d468bbaca
4
- data.tar.gz: 77ea8801bc86ed0ee3378084445e73eeaa2e3e50
3
+ metadata.gz: fce987a7a0c0a6b3997a09358b786b4f6877a141
4
+ data.tar.gz: 664b9bf8c1b84a0b97395ac343efc10594911614
5
5
  SHA512:
6
- metadata.gz: 914d3089beba2457bf2df38e1cf310cf1de2b986b7874704b8cc9658baa0cdfea5584e368e58b4d85711a074312bde4a9a978b8b25bdbd520fadd01787ec7a3c
7
- data.tar.gz: d8e5554a3ed82a078c4d77fd949700b34c4278327397d67c63300655e6bef8992fd054808414cf5698709f9ffe4c786963438163d1cf29a2b20491376fa39fd3
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 self.send_message(phone, message)
155
- some_send_method(:phone => phone, :text => message.content)
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 self.send_message_to_all(message)
160
- other_send_method(:phone_array => message.to, :text => message.content)
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 *send_message_to_all*, the *send_message* method will be invoked multiple times.
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
 
@@ -2,6 +2,12 @@ require 'action_controller'
2
2
  require 'action_mailer'
3
3
  require 'phony'
4
4
 
5
+ begin
6
+ require 'twilio-ruby'
7
+ rescue LoadError
8
+ # no twilio-ruby
9
+ end
10
+
5
11
  begin
6
12
  require 'sidekiq'
7
13
  rescue LoadError
@@ -1,11 +1,15 @@
1
1
  module Textris
2
2
  module Delivery
3
3
  class Base
4
- class << self
5
- def send_message_to_all(message)
6
- message.to.each do |to|
7
- send_message(to, message)
8
- end
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
- class << self
11
- private
10
+ def deliver(to)
11
+ template_vars = { :to_phone => to }
12
12
 
13
- def send_message(to, message)
14
- template_vars = { :to_phone => to }
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
- from = apply_template from_template, message, template_vars
17
- to = apply_template to_template, message, template_vars
18
- subject = apply_template subject_template, message, template_vars
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
- ::Textris::Delivery::Mail::Mailer.notify(
22
- from, to, subject, body).deliver
23
- end
22
+ private
24
23
 
25
- def from_template
26
- Rails.application.config.try(:textris_mail_from_template) ||
27
- "%{from_name:d}-%{from_phone}@%{env:d}.%{app:d}.com"
28
- end
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
- def to_template
31
- Rails.application.config.try(:textris_mail_to_template) ||
32
- "%{app:d}-%{env:d}-%{to_phone}-texts@mailinator.com"
33
- end
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
- def subject_template
36
- Rails.application.config.try(:textris_mail_subject_template) ||
37
- "%{texter:dh} texter: %{action:h}"
38
- end
34
+ def subject_template
35
+ Rails.application.config.try(:textris_mail_subject_template) ||
36
+ "%{texter:dh} texter: %{action:h}"
37
+ end
39
38
 
40
- def body_template
41
- Rails.application.config.try(:textris_mail_body_template) ||
42
- "%{content}"
43
- end
39
+ def body_template
40
+ Rails.application.config.try(:textris_mail_body_template) ||
41
+ "%{content}"
42
+ end
44
43
 
45
- def apply_template(template, message, variables)
46
- template.gsub(/\%\{[a-z_:]+\}/) do |match|
47
- directive = match.gsub(/[%{}]/, '')
48
- key = directive.split(':').first
49
- modifiers = directive.split(':')[1] || ''
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
- content = get_template_interpolation(key, message, variables)
52
- content = apply_template_modifiers(content, modifiers.chars)
53
- content = 'unknown' unless content.present?
50
+ content = get_template_interpolation(key, variables)
51
+ content = apply_template_modifiers(content, modifiers.chars)
52
+ content = 'unknown' unless content.present?
54
53
 
55
- content
56
- end
54
+ content
57
55
  end
56
+ end
58
57
 
59
- def get_template_interpolation(key, message, variables)
60
- content = case key
61
- when 'app', 'env'
62
- get_rails_variable(key)
63
- when 'texter', 'action', 'from_name', 'from_phone', 'content'
64
- message.send(key)
65
- else
66
- variables[key.to_sym]
67
- end.to_s.strip
68
- end
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
- def get_rails_variable(var)
71
- case var
72
- when 'app'
73
- Rails.application.class.parent_name
74
- when 'env'
75
- Rails.env
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
- def apply_template_modifiers(content, modifiers)
80
- modifiers.each do |modifier|
81
- case modifier
82
- when 'd'
83
- content = content.underscore.dasherize
84
- when 'h'
85
- content = content.humanize.gsub(/[-_]/, ' ')
86
- when 'p'
87
- content = Phony.format(content) rescue content
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
- private
10
-
11
- def send_message(to, message)
12
- deliveries.push(::Textris::Message.new(
13
- :content => message.content,
14
- :from_name => message.from_name,
15
- :from_phone => message.from_phone,
16
- :texter => message.texter,
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
- class << self
7
- private
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
- def send_message(to, message)
10
- client.messages.create(
11
- :from => message.from_phone,
12
- :to => to,
13
- :body => message.content)
14
- end
11
+ private
15
12
 
16
- def client
17
- @client ||= ::Twilio::REST::Client.new
18
- end
13
+ def client
14
+ @client ||= ::Twilio::REST::Client.new
19
15
  end
20
16
  end
21
17
  end
@@ -28,7 +28,7 @@ module Textris
28
28
  def deliver
29
29
  deliveries = ::Textris::Delivery.get
30
30
  deliveries.each do |delivery|
31
- delivery.send_message_to_all(self)
31
+ delivery.new(self).deliver_to_all
32
32
  end
33
33
 
34
34
  self
@@ -1,3 +1,3 @@
1
1
  module Textris
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  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.2.1
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: simplecov
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.9'
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.9'
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: codeclimate-test-reporter
98
+ name: simplecov
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
101
  - - "~>"
88
102
  - !ruby/object:Gem::Version
89
- version: '0.4'
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.4'
110
+ version: '0.9'
97
111
  - !ruby/object:Gem::Dependency
98
- name: rspec-sidekiq
112
+ name: twilio-ruby
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
115
  - - "~>"
102
116
  - !ruby/object:Gem::Version
103
- version: '2.0'
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: '2.0'
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: render_anywhere
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: '3.12'
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: '3.12'
152
+ version: '2.8'
153
153
  - !ruby/object:Gem::Dependency
154
- name: phony
154
+ name: render_anywhere
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - "~>"
158
158
  - !ruby/object:Gem::Version
159
- version: '2.8'
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: '2.8'
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.