textris 0.1.9 → 0.2.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: cb703c3bd61fb19f5b040f6225d6c390fc1c2473
4
- data.tar.gz: a42312ca7c46a2f18dc15b739c58ae87157b85c4
3
+ metadata.gz: 1e6cb842843c6a7f189e4f59b35d8f8501453757
4
+ data.tar.gz: 8f40de6578336302ed61860b06601578a2291b97
5
5
  SHA512:
6
- metadata.gz: e30b26878f3cc4894b9b3189a29579c1b4fdc06a7f84a5a3bbf598c9be940725fd14304d34fb1a3d2e8a6598aa044810b0311335ca4807b889abb32fa1f98650
7
- data.tar.gz: 43f57914ef22307eb2095b787f68763c1a5ce0ac0069b1225d2f349d5f89687c977052cb4617df16daaa3773be3cb71753cc6dbac5d077b2058db8a47b05e58b
6
+ metadata.gz: a8be0a77ed1bdba813eda54f4bae86a7b28a5451a6e7f167ad1705caaac8a2caef0ae92e2042043219f1f735bca37ae0909134b0cd2eed378345252bb4f8d2c8
7
+ data.tar.gz: 4fe1195f482cced30d505148fecdf44329226a70851cebe87d905c3ed9cbc5abf3a02faedcafcd6a3343fe54c205890bdcf8186f0ed2dfe37fd5c6bb6205659a
data/README.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # textris
2
2
 
3
- [![Build Status](https://travis-ci.org/visualitypl/textris.svg)](https://travis-ci.org/visualitypl/textris)
4
- [![Code Climate](https://codeclimate.com/github/visualitypl/textris/badges/gpa.svg)](https://codeclimate.com/github/visualitypl/textris)
3
+ [![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
4
  [![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)
5
+ [![Code Climate](https://codeclimate.com/github/visualitypl/textris/badges/gpa.svg)](https://codeclimate.com/github/visualitypl/textris)
6
+ [![Test Coverage](https://codeclimate.com/github/visualitypl/textris/badges/coverage.svg)](https://codeclimate.com/github/visualitypl/textris)
6
7
 
7
8
  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
9
 
@@ -13,6 +14,7 @@ Unlike similar gems, **textris** has some unique features:
13
14
  - built-in support for the Twilio API thanks to the [twilio-ruby](https://github.com/twilio/twilio-ruby) gem
14
15
  - multiple, per-environment configurable and chainable delivery methods
15
16
  - extensible with any number of custom delivery methods (also chainable)
17
+ - background and scheduled processing thanks to integration with the [sidekiq](https://github.com/mperham/sidekiq) gem
16
18
  - support for testing using self-explanatory `Textris::Base.deliveries`
17
19
  - simple, extensible, fully tested code written from the ground up instead of copying *ActionMailer*
18
20
 
@@ -60,6 +62,30 @@ class User < ActiveRecord::Base
60
62
  end
61
63
  ```
62
64
 
65
+ ### Background and scheduled processing
66
+
67
+ Thanks to Sidekiq integration, you can send text messages in the background to speed things up, retry in case of failures or just to do it at specified time. To do so, first include the `Textris::Delay::Sidekiq` module in your texter:
68
+
69
+ ```ruby
70
+ class UserTexter < Textris::Base
71
+ include Textris::Delay::Sidekiq
72
+
73
+ def welcome(user)
74
+ # ...
75
+ end
76
+ end
77
+ ```
78
+
79
+ Then use one of three delay methods.
80
+
81
+ ```ruby
82
+ UserTexter.delay.welcome(user)
83
+ UserTexter.delay_for(1.hour).welcome(user)
84
+ UserTexter.delay_until(1.day.from_now).welcome(user)
85
+ ```
86
+
87
+ > You should not call `deliver` after the action invocation when using delay. It will be called by the *Textris::Delay::Sidekiq::Worker* worker.
88
+
63
89
  ## Testing
64
90
 
65
91
  Access all messages that were sent with the `:test` delivery:
@@ -9,3 +9,4 @@ require 'textris/delivery/base'
9
9
  require 'textris/delivery/test'
10
10
  require 'textris/delivery/mail'
11
11
  require 'textris/delivery/twilio'
12
+ require 'textris/delay/sidekiq'
@@ -0,0 +1,67 @@
1
+ require 'sidekiq'
2
+
3
+ module Textris
4
+ module Delay
5
+ module Sidekiq
6
+ class Worker
7
+ include ::Sidekiq::Worker
8
+
9
+ def perform(texter, action, params)
10
+ texter = texter.safe_constantize
11
+
12
+ if texter.present?
13
+ texter.new(action, *params).call_action.deliver
14
+ end
15
+ end
16
+ end
17
+
18
+ class Proxy
19
+ def initialize(texter, options = {})
20
+ @texter = texter
21
+ @perform_in = options[:perform_in]
22
+ @perform_at = options[:perform_at]
23
+ end
24
+
25
+ private
26
+
27
+ def method_missing(method_name, *args)
28
+ args = [@texter, method_name, args]
29
+
30
+ if @perform_in
31
+ ::Textris::Delay::Sidekiq::Worker.perform_in(@perform_in, *args)
32
+ elsif @perform_at
33
+ ::Textris::Delay::Sidekiq::Worker.perform_at(@perform_at, *args)
34
+ else
35
+ ::Textris::Delay::Sidekiq::Worker.perform_async(*args)
36
+ end
37
+ end
38
+ end
39
+
40
+ class << self
41
+ def included(base)
42
+ base.extend(self)
43
+ end
44
+ end
45
+
46
+ def delay
47
+ ::Textris::Delay::Sidekiq::Proxy.new(self)
48
+ end
49
+
50
+ def delay_for(interval)
51
+ unless interval.is_a?(Fixnum)
52
+ raise(ArgumentError, "Proper interval must be provided")
53
+ end
54
+
55
+ ::Textris::Delay::Sidekiq::Proxy.new(self, :perform_in => interval)
56
+ end
57
+
58
+ def delay_until(timestamp)
59
+ unless timestamp.respond_to?(:to_time)
60
+ raise(ArgumentError, "Proper timestamp must be provided")
61
+ end
62
+
63
+ ::Textris::Delay::Sidekiq::Proxy.new(self, :perform_at => timestamp)
64
+ end
65
+ end
66
+ end
67
+ end
@@ -1,3 +1,3 @@
1
1
  module Textris
2
- VERSION = "0.1.9"
2
+ VERSION = "0.2.0"
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.1.9
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karol Słuszniak
@@ -80,6 +80,34 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '1.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: codeclimate-test-reporter
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.4'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.4'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec-sidekiq
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '2.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '2.0'
83
111
  - !ruby/object:Gem::Dependency
84
112
  name: actionmailer
85
113
  requirement: !ruby/object:Gem::Requirement
@@ -136,6 +164,20 @@ dependencies:
136
164
  - - "~>"
137
165
  - !ruby/object:Gem::Version
138
166
  version: '2.8'
167
+ - !ruby/object:Gem::Dependency
168
+ name: sidekiq
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '3.2'
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: '3.2'
139
181
  description: Implement texter classes for sending SMS messages in similar way to how
140
182
  e-mails are sent with ActionMailer-based mailers. Take advantage of e-mail proxying
141
183
  and enhanced phone number parsing, among others.
@@ -148,6 +190,7 @@ files:
148
190
  - README.md
149
191
  - lib/textris.rb
150
192
  - lib/textris/base.rb
193
+ - lib/textris/delay/sidekiq.rb
151
194
  - lib/textris/delivery.rb
152
195
  - lib/textris/delivery/base.rb
153
196
  - lib/textris/delivery/mail.rb