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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c892d39927e7381aa8d34757802e9102d3341681
4
- data.tar.gz: 63b2c323d52306386dd787c4304c98f458023715
3
+ metadata.gz: 5932f935ac05fd8ca113cb3e218b171153b106c6
4
+ data.tar.gz: 10c63364aeef04d95d9b6382c9949d1ff867bb47
5
5
  SHA512:
6
- metadata.gz: 2a8b73f20130a57a8b226eff56d89cc39b1b875265edc2bcc1fea1b5cc519bfb72f009bb709436e6490de1e29715955f2faae1f33a3e341b81e4ba99b4d4db55
7
- data.tar.gz: 1ade51f79ebf729434c12c9a470500da2c99e0c4b87af1c01f102c2f41a05bde92f5cc2fc6e36866c9201e57fae632e308edbfcda86190467d2f3c076e3f77df
6
+ metadata.gz: 8f371b94fd9a376866847ef1b0faef2896431fa90e526327a66081600b9988f4446b6a3466390512f971ddeeb6fb7d548b545315d7e9ba2393efe2c0fe4a0fcd
7
+ data.tar.gz: d46bb126af552ef5008fd1aa6a5d3b2e68d16a5f22cd0952b1fb6f3255f7eb55bb571957d7b2c0fe1d68e0e0761cba6de95ad34495af9095f9cc6dff7a892896
data/README.md CHANGED
@@ -1,10 +1,11 @@
1
1
  # textris
2
2
 
3
- [![GitHub version](https://badge.fury.io/gh/visualitypl%2Ftextris.svg)](http://badge.fury.io/gh/visualitypl%2Ftextris)
4
- [![Build Status](https://scrutinizer-ci.com/g/visualitypl/textris/badges/build.png?b=master)](https://scrutinizer-ci.com/g/visualitypl/textris/build-status/master)
5
- [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/visualitypl/textris/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/visualitypl/textris/?branch=master)
6
- [![Code Climate](https://codeclimate.com/github/visualitypl/textris/badges/gpa.svg)](https://codeclimate.com/github/visualitypl/textris)
7
- [![Test Coverage](https://codeclimate.com/github/visualitypl/textris/badges/coverage.svg)](https://codeclimate.com/github/visualitypl/textris)
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
 
@@ -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'
@@ -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 => self.class,
54
- :action => @action,
55
- :content => options[:body].is_a?(String) ? options[:body] : render(
56
- :template => template_name, :formats => ['text']))
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
@@ -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 = parse_to options[:to]
7
- @content = parse_content options[: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 @texter.present?
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)
@@ -1,3 +1,3 @@
1
1
  module Textris
2
- VERSION = '0.3.2'
2
+ VERSION = '0.4.0'
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.2
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-01-17 00:00:00.000000000 Z
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