textris 0.2.3 → 0.3.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 +2 -0
- data/lib/textris.rb +1 -1
- data/lib/textris/delay/sidekiq/proxy.rb +1 -0
- data/lib/textris/delay/sidekiq/serializer.rb +75 -0
- data/lib/textris/delay/sidekiq/worker.rb +4 -2
- data/lib/textris/message.rb +2 -2
- data/lib/textris/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 41a7e696b4cae68e7793538ad07e490c415f048c
|
4
|
+
data.tar.gz: 1cd679882d001d36860d0e9e0129dd096d036422
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67b9819759fb074b871ce4ef1f4aef2c6baeddd9472e111b75beb1ac8ce33530126481d04aac3f47ac3274229bf910341d8a7f9ba926e79b813e36f114a181ac
|
7
|
+
data.tar.gz: 08cffc6511507e0c2898d0f0ea07ea9667e9947054db10fc89031ce0b4d977f1ea1480a3ab9f4643856e867c3a9a31e29495a6b57ce51011f59173fb03eff165
|
data/README.md
CHANGED
@@ -74,6 +74,8 @@ UserTexter.delay_until(1.day.from_now).welcome(user)
|
|
74
74
|
|
75
75
|
> You should not call `deliver` after the action invocation when using delay. It will be called by the *Textris::Delay::Sidekiq::Worker* worker.
|
76
76
|
|
77
|
+
> You can safely pass ActiveRecord records and arrays as delayed action arguments. **textris** will store their `id`'s and find them upon scheduled delivery.
|
78
|
+
|
77
79
|
Keep in mind that **textris** does not install *sidekiq* for you. If you don't have it yet, [install Redis](http://redis.io/topics/quickstart) on your machine and add the *sidekiq* gem to `Gemfile`:
|
78
80
|
|
79
81
|
```ruby
|
data/lib/textris.rb
CHANGED
@@ -5,7 +5,6 @@ require 'phony'
|
|
5
5
|
begin
|
6
6
|
require 'twilio-ruby'
|
7
7
|
rescue LoadError
|
8
|
-
# no twilio-ruby
|
9
8
|
end
|
10
9
|
|
11
10
|
begin
|
@@ -17,6 +16,7 @@ rescue LoadError
|
|
17
16
|
else
|
18
17
|
require 'textris/delay/sidekiq'
|
19
18
|
require 'textris/delay/sidekiq/proxy'
|
19
|
+
require 'textris/delay/sidekiq/serializer'
|
20
20
|
require 'textris/delay/sidekiq/worker'
|
21
21
|
end
|
22
22
|
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module Textris
|
2
|
+
module Delay
|
3
|
+
module Sidekiq
|
4
|
+
module Serializer
|
5
|
+
ACTIVERECORD_POINTER = 'Textris::ActiveRecordPointer'
|
6
|
+
ACTIVERECORD_ARRAY_POINTER = 'Textris::ActiveRecordArrayPointer'
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def serialize(objects)
|
10
|
+
objects.collect do |object|
|
11
|
+
serialize_active_record_object(object) ||
|
12
|
+
serialize_active_record_array(object) ||
|
13
|
+
object
|
14
|
+
end
|
15
|
+
rescue NameError
|
16
|
+
objects
|
17
|
+
end
|
18
|
+
|
19
|
+
def deserialize(objects)
|
20
|
+
objects.collect do |object|
|
21
|
+
deserialize_active_record_object(object) ||
|
22
|
+
deserialize_active_record_array(object) ||
|
23
|
+
object
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def serialize_active_record_object(object)
|
30
|
+
if object.class < ActiveRecord::Base && object.id.present?
|
31
|
+
[ACTIVERECORD_POINTER, object.class.to_s, object.id]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def deserialize_active_record_object(object)
|
36
|
+
if object.is_a?(Array) &&
|
37
|
+
object.try(:length) == 3 &&
|
38
|
+
object[0] == ACTIVERECORD_POINTER
|
39
|
+
object[1].constantize.find(object[2])
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def serialize_active_record_array(array)
|
44
|
+
if array.class < ActiveRecord::Relation
|
45
|
+
[ACTIVERECORD_ARRAY_POINTER, array.model.to_s, array.map(&:id)]
|
46
|
+
elsif array.is_a?(Array) &&
|
47
|
+
(model = get_active_record_common_model(array))
|
48
|
+
[ACTIVERECORD_ARRAY_POINTER, model, array.map(&:id)]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def deserialize_active_record_array(object)
|
53
|
+
if object.is_a?(Array) &&
|
54
|
+
object.try(:length) == 3 &&
|
55
|
+
object[0] == ACTIVERECORD_ARRAY_POINTER
|
56
|
+
object[1].constantize.find(object[2])
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def get_active_record_common_model(items)
|
61
|
+
items = items.collect do |item|
|
62
|
+
if item.class < ActiveRecord::Base
|
63
|
+
item.class.to_s
|
64
|
+
end
|
65
|
+
end.uniq
|
66
|
+
|
67
|
+
if items.size == 1
|
68
|
+
items.first
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -4,11 +4,13 @@ module Textris
|
|
4
4
|
class Worker
|
5
5
|
include ::Sidekiq::Worker
|
6
6
|
|
7
|
-
def perform(texter, action,
|
7
|
+
def perform(texter, action, args)
|
8
8
|
texter = texter.safe_constantize
|
9
9
|
|
10
10
|
if texter.present?
|
11
|
-
|
11
|
+
args = ::Textris::Delay::Sidekiq::Serializer.deserialize(args)
|
12
|
+
|
13
|
+
texter.new(action, *args).call_action.deliver
|
12
14
|
end
|
13
15
|
end
|
14
16
|
end
|
data/lib/textris/message.rb
CHANGED
@@ -63,8 +63,8 @@ module Textris
|
|
63
63
|
|
64
64
|
def parse_to(to)
|
65
65
|
to = [*to]
|
66
|
-
to = to.select { |phone| Phony.plausible?(phone) }
|
67
|
-
to = to.map { |phone| Phony.normalize(phone) }
|
66
|
+
to = to.select { |phone| Phony.plausible?(phone.to_s) }
|
67
|
+
to = to.map { |phone| Phony.normalize(phone.to_s) }
|
68
68
|
|
69
69
|
to
|
70
70
|
end
|
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.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Karol Słuszniak
|
@@ -179,6 +179,7 @@ files:
|
|
179
179
|
- lib/textris/delay/sidekiq.rb
|
180
180
|
- lib/textris/delay/sidekiq/missing.rb
|
181
181
|
- lib/textris/delay/sidekiq/proxy.rb
|
182
|
+
- lib/textris/delay/sidekiq/serializer.rb
|
182
183
|
- lib/textris/delay/sidekiq/worker.rb
|
183
184
|
- lib/textris/delivery.rb
|
184
185
|
- lib/textris/delivery/base.rb
|