textris 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -5
- data/lib/textris.rb +14 -0
- data/lib/textris/base.rb +11 -6
- data/lib/textris/delay/active_job.rb +21 -0
- data/lib/textris/delay/active_job/job.rb +17 -0
- data/lib/textris/delay/active_job/missing.rb +14 -0
- data/lib/textris/message.rb +14 -6
- data/lib/textris/version.rb +1 -1
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5932f935ac05fd8ca113cb3e218b171153b106c6
|
4
|
+
data.tar.gz: 10c63364aeef04d95d9b6382c9949d1ff867bb47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f371b94fd9a376866847ef1b0faef2896431fa90e526327a66081600b9988f4446b6a3466390512f971ddeeb6fb7d548b545315d7e9ba2393efe2c0fe4a0fcd
|
7
|
+
data.tar.gz: d46bb126af552ef5008fd1aa6a5d3b2e68d16a5f22cd0952b1fb6f3255f7eb55bb571957d7b2c0fe1d68e0e0761cba6de95ad34495af9095f9cc6dff7a892896
|
data/README.md
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
# textris
|
2
2
|
|
3
|
-
[![
|
4
|
-
[![
|
5
|
-
[![
|
6
|
-
[![Code
|
7
|
-
[![
|
3
|
+
[![Gem Version](https://img.shields.io/gem/v/textris.svg?style=flat-square&label=version)](https://rubygems.org/gems/textris)
|
4
|
+
[![Downloads](https://img.shields.io/gem/dt/textris.svg?style=flat-square)](https://rubygems.org/gems/textris)
|
5
|
+
[![Build Status](https://img.shields.io/circleci/project/visualitypl/textris/master.svg?style=flat-square&label=build)](https://circleci.com/gh/visualitypl/textris/tree/master)
|
6
|
+
[![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/visualitypl/textris.svg?style=flat-square)](https://scrutinizer-ci.com/g/visualitypl/textris/?branch=master)
|
7
|
+
[![Code Climate](https://img.shields.io/codeclimate/github/visualitypl/textris.svg?style=flat-square)](https://codeclimate.com/github/visualitypl/textris)
|
8
|
+
[![Test Coverage](https://img.shields.io/codeclimate/coverage/github/visualitypl/textris.svg?style=flat-square)](https://codeclimate.com/github/visualitypl/textris)
|
8
9
|
|
9
10
|
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.
|
10
11
|
|
data/lib/textris.rb
CHANGED
@@ -22,6 +22,20 @@ end
|
|
22
22
|
|
23
23
|
require 'textris/base'
|
24
24
|
require 'textris/message'
|
25
|
+
|
26
|
+
begin
|
27
|
+
require 'active_job'
|
28
|
+
rescue LoadError
|
29
|
+
require 'textris/delay/active_job/missing'
|
30
|
+
|
31
|
+
Textris::Message.include(Textris::Delay::ActiveJob::Missing)
|
32
|
+
else
|
33
|
+
require 'textris/delay/active_job'
|
34
|
+
require 'textris/delay/active_job/job'
|
35
|
+
|
36
|
+
Textris::Message.include(Textris::Delay::ActiveJob)
|
37
|
+
end
|
38
|
+
|
25
39
|
require 'textris/delivery'
|
26
40
|
require 'textris/delivery/base'
|
27
41
|
require 'textris/delivery/test'
|
data/lib/textris/base.rb
CHANGED
@@ -43,17 +43,22 @@ module Textris
|
|
43
43
|
send(@action, *@args)
|
44
44
|
end
|
45
45
|
|
46
|
+
def render_content
|
47
|
+
set_instance_variables_for_rendering
|
48
|
+
|
49
|
+
render(:template => template_name, :formats => ['text'])
|
50
|
+
end
|
51
|
+
|
46
52
|
protected
|
47
53
|
|
48
54
|
def text(options = {})
|
49
|
-
set_instance_variables_for_rendering
|
50
|
-
|
51
55
|
options = self.class.with_defaults(options)
|
52
56
|
options.merge!(
|
53
|
-
:texter
|
54
|
-
:action
|
55
|
-
:
|
56
|
-
|
57
|
+
:texter => self.class,
|
58
|
+
:action => @action,
|
59
|
+
:args => @args,
|
60
|
+
:content => options[:body].is_a?(String) ? options[:body] : nil,
|
61
|
+
:renderer => self)
|
57
62
|
|
58
63
|
::Textris::Message.new(options)
|
59
64
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Textris
|
2
|
+
module Delay
|
3
|
+
module ActiveJob
|
4
|
+
def deliver_now
|
5
|
+
deliver
|
6
|
+
end
|
7
|
+
|
8
|
+
def deliver_later(options = {})
|
9
|
+
job = Textris::Delay::ActiveJob::Job
|
10
|
+
|
11
|
+
[:wait, :wait_until, :queue].each do |option|
|
12
|
+
if options.has_key?(option)
|
13
|
+
job.set(option => options[option])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
job.perform_later(texter(:raw => true).to_s, action.to_s, args)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Textris
|
2
|
+
module Delay
|
3
|
+
module ActiveJob
|
4
|
+
class Job < ::ActiveJob::Base
|
5
|
+
queue_as :textris
|
6
|
+
|
7
|
+
def perform(texter, action, args)
|
8
|
+
texter = texter.safe_constantize
|
9
|
+
|
10
|
+
if texter.present?
|
11
|
+
texter.new(action, *args).call_action.deliver_now
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Textris
|
2
|
+
module Delay
|
3
|
+
module ActiveJob
|
4
|
+
module Missing
|
5
|
+
def active_job_missing(*args)
|
6
|
+
raise(LoadError, "ActiveJob is required to delay sending messages")
|
7
|
+
end
|
8
|
+
|
9
|
+
alias_method :deliver_now, :active_job_missing
|
10
|
+
alias_method :deliver_later, :active_job_missing
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/textris/message.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
module Textris
|
2
2
|
class Message
|
3
|
-
attr_reader :content, :from_name, :from_phone, :to, :texter, :action
|
3
|
+
attr_reader :content, :from_name, :from_phone, :to, :texter, :action, :args
|
4
4
|
|
5
5
|
def initialize(options = {})
|
6
|
-
@to
|
7
|
-
@content
|
6
|
+
@to = parse_to options[:to]
|
7
|
+
@content = parse_content options[:content] if options[:content].present?
|
8
|
+
@renderer = options[:renderer]
|
8
9
|
|
9
10
|
if options.has_key?(:from)
|
10
11
|
@from_name, @from_phone = parse_from options[:from]
|
@@ -13,7 +14,7 @@ module Textris
|
|
13
14
|
@from_phone = options[:from_phone]
|
14
15
|
end
|
15
16
|
|
16
|
-
unless @content.present?
|
17
|
+
unless @content.present? || @renderer.respond_to?(:render)
|
17
18
|
raise(ArgumentError, "Content must be provided")
|
18
19
|
end
|
19
20
|
|
@@ -23,6 +24,7 @@ module Textris
|
|
23
24
|
|
24
25
|
@texter = options[:texter]
|
25
26
|
@action = options[:action]
|
27
|
+
@args = options[:args]
|
26
28
|
end
|
27
29
|
|
28
30
|
def deliver
|
@@ -34,8 +36,10 @@ module Textris
|
|
34
36
|
self
|
35
37
|
end
|
36
38
|
|
37
|
-
def texter
|
38
|
-
if
|
39
|
+
def texter(options = {})
|
40
|
+
if options[:raw]
|
41
|
+
@texter
|
42
|
+
elsif @texter.present?
|
39
43
|
@texter.to_s.split('::').last.to_s.sub(/Texter$/, '')
|
40
44
|
end
|
41
45
|
end
|
@@ -52,6 +56,10 @@ module Textris
|
|
52
56
|
end
|
53
57
|
end
|
54
58
|
|
59
|
+
def content
|
60
|
+
@content ||= @renderer.render_content
|
61
|
+
end
|
62
|
+
|
55
63
|
private
|
56
64
|
|
57
65
|
def parse_from(from)
|
data/lib/textris/version.rb
CHANGED
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.
|
4
|
+
version: 0.4.0
|
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: 2015-
|
11
|
+
date: 2015-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -150,6 +150,20 @@ dependencies:
|
|
150
150
|
- - "~>"
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '4.0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: activejob
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '4.2'
|
160
|
+
type: :runtime
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '4.2'
|
153
167
|
- !ruby/object:Gem::Dependency
|
154
168
|
name: phony
|
155
169
|
requirement: !ruby/object:Gem::Requirement
|
@@ -190,6 +204,9 @@ files:
|
|
190
204
|
- README.md
|
191
205
|
- lib/textris.rb
|
192
206
|
- lib/textris/base.rb
|
207
|
+
- lib/textris/delay/active_job.rb
|
208
|
+
- lib/textris/delay/active_job/job.rb
|
209
|
+
- lib/textris/delay/active_job/missing.rb
|
193
210
|
- lib/textris/delay/sidekiq.rb
|
194
211
|
- lib/textris/delay/sidekiq/missing.rb
|
195
212
|
- lib/textris/delay/sidekiq/proxy.rb
|