maia 0.0.8 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/app/controllers/concerns/maia/controller.rb +1 -1
- data/app/models/maia/device.rb +13 -6
- data/db/migrate/20150302191320_create_maia_devices.rb +1 -0
- data/lib/maia/dry_run.rb +5 -1
- data/lib/maia/message.rb +83 -32
- data/lib/maia/poke.rb +5 -1
- data/lib/maia/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NjUwMmY4YjUwNzE4YmU2ZWZkNjUxNTA2MWUyZTllYTE2MTI3OTI4Nw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NGZlYzZmODgwYjAxNTQzOWU5ZDk5MWQ5NDJmNjU2ZjY4M2IyOWNkOA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NjQ2ODJjNWY1NzkxMDZjY2I2MzMxMDhjYjZjM2JlMTBiZWI2M2NlN2ZjMDIx
|
10
|
+
ZWJmNGEwZTUwNGEzODU3ZmEzNDQ0NDBjYjNkYzYxNmE4NmI4MDJjMWVjZDQ4
|
11
|
+
MmU5ZWYxOTRmNjFlMzFiNzhkZDFmNzBmYTRmOTk3NDBmNTNhNmE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
N2JhMDJiMzYwNDQ3MWI1NWMyZGI1MTAyNWRjMzhjNjFiNDM0NmU4ODFkMjQz
|
14
|
+
ODliOTE0NmY0OTYzNTllMjhhYzlkYzBiZDZiY2RjYjY0ZTY3ZjMxNDc1MzBl
|
15
|
+
YWVkMGJmNGM2NTEzMzIyN2IzMjc3YTA1YzMxZTU2MTI1ODQ4Yzk=
|
data/app/models/maia/device.rb
CHANGED
@@ -3,6 +3,7 @@ module Maia
|
|
3
3
|
belongs_to :pushable, polymorphic: true
|
4
4
|
|
5
5
|
validates :token, presence: true, uniqueness: { scope: :pushable }
|
6
|
+
validates :platform, inclusion: { in: %w(ios android) }, allow_nil: true
|
6
7
|
|
7
8
|
before_save :reset_token_expiry
|
8
9
|
|
@@ -19,13 +20,19 @@ module Maia
|
|
19
20
|
end
|
20
21
|
|
21
22
|
def self.owned_by(pushable)
|
22
|
-
|
23
|
-
table = pushable.table.name
|
24
|
-
joins("JOIN #{table} ON #{table}.id = #{table_name}.pushable_id").
|
25
|
-
where(pushable_type: klass).
|
26
|
-
merge(pushable).
|
27
|
-
uniq
|
23
|
+
where(pushable: pushable).uniq
|
28
24
|
end
|
29
25
|
|
26
|
+
def self.ios
|
27
|
+
where platform: 'ios'
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.android
|
31
|
+
where platform: 'android'
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.unknown
|
35
|
+
where platform: nil
|
36
|
+
end
|
30
37
|
end
|
31
38
|
end
|
data/lib/maia/dry_run.rb
CHANGED
data/lib/maia/message.rb
CHANGED
@@ -3,43 +3,55 @@ module Maia
|
|
3
3
|
MAX_TOKENS_AT_ONCE = 999
|
4
4
|
|
5
5
|
def send_to(pushable, wait: false)
|
6
|
-
devices =
|
7
|
-
|
8
|
-
when ActiveRecord::Relation
|
9
|
-
Device.owned_by pushable
|
10
|
-
when ActiveRecord::Base
|
11
|
-
pushable.devices
|
12
|
-
else
|
13
|
-
fail 'Maia can only send to ActiveRecord objects!'
|
14
|
-
end
|
6
|
+
devices = Device.owned_by pushable
|
7
|
+
worker = wait ? Maia::Messenger.set(wait: wait) : Maia::Messenger
|
15
8
|
|
16
|
-
enqueue devices, to_h
|
9
|
+
enqueue worker, devices.android, to_h(notify: notify?(:android))
|
10
|
+
enqueue worker, devices.ios, to_h(notify: notify?(:ios))
|
11
|
+
enqueue worker, devices.unknown, to_h(notify: notify?(:unknown))
|
17
12
|
end
|
18
13
|
|
19
|
-
def enqueue(devices, payload
|
20
|
-
|
21
|
-
|
22
|
-
devices.pluck(:token).each_slice(MAX_TOKENS_AT_ONCE) do |tokens|
|
14
|
+
def enqueue(worker, devices, payload)
|
15
|
+
devices.pluck(:token).each_slice MAX_TOKENS_AT_ONCE do |tokens|
|
23
16
|
worker.perform_later tokens, payload.deep_stringify_keys
|
24
17
|
end
|
25
18
|
end
|
26
19
|
|
27
|
-
def
|
28
|
-
''
|
20
|
+
def title
|
29
21
|
end
|
30
22
|
|
31
|
-
def
|
23
|
+
def body
|
24
|
+
end
|
25
|
+
|
26
|
+
def icon
|
32
27
|
end
|
33
28
|
|
34
29
|
def sound
|
35
30
|
'default'
|
36
31
|
end
|
37
32
|
|
38
|
-
def
|
39
|
-
|
33
|
+
def badge
|
34
|
+
end
|
35
|
+
|
36
|
+
def color
|
37
|
+
end
|
38
|
+
|
39
|
+
def action
|
40
|
+
end
|
41
|
+
|
42
|
+
def title_i18n
|
43
|
+
[]
|
44
|
+
end
|
45
|
+
|
46
|
+
def body_i18n
|
47
|
+
[]
|
48
|
+
end
|
49
|
+
|
50
|
+
def data
|
40
51
|
end
|
41
52
|
|
42
53
|
def priority
|
54
|
+
:normal
|
43
55
|
end
|
44
56
|
|
45
57
|
def content_available?
|
@@ -50,21 +62,60 @@ module Maia
|
|
50
62
|
false
|
51
63
|
end
|
52
64
|
|
53
|
-
def
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
65
|
+
def notify?(_platform = :unknown)
|
66
|
+
true
|
67
|
+
end
|
68
|
+
|
69
|
+
def notification
|
70
|
+
{
|
71
|
+
title: title,
|
72
|
+
body: body,
|
73
|
+
icon: icon,
|
74
|
+
sound: sound,
|
75
|
+
badge: badge,
|
76
|
+
color: color,
|
77
|
+
click_action: action
|
78
|
+
}.merge(i18n).compact
|
79
|
+
end
|
80
|
+
|
81
|
+
def to_h(notify: true)
|
82
|
+
payload = {
|
83
|
+
priority: priority.to_s,
|
84
|
+
dry_run: dry_run?,
|
85
|
+
content_available: content_available?,
|
86
|
+
data: data
|
62
87
|
}
|
63
88
|
|
64
|
-
|
65
|
-
|
66
|
-
hash.merge!(content_available: true) if content_available?
|
67
|
-
hash
|
89
|
+
payload[:notification] = notification if notify
|
90
|
+
payload.compact
|
68
91
|
end
|
92
|
+
|
93
|
+
private
|
94
|
+
def i18n
|
95
|
+
{}.tap do |hash|
|
96
|
+
hash[:body_loc_key] = body_i18n.first
|
97
|
+
hash[:body_loc_args] = body_i18n_args
|
98
|
+
hash[:title_loc_key] = title_i18n_key
|
99
|
+
hash[:title_loc_args] = title_i18n_args
|
100
|
+
end.compact
|
101
|
+
end
|
102
|
+
|
103
|
+
def body_i18n_key
|
104
|
+
body_i18n.first
|
105
|
+
end
|
106
|
+
|
107
|
+
def body_i18n_args
|
108
|
+
args = body_i18n.drop 1
|
109
|
+
args if args.any?
|
110
|
+
end
|
111
|
+
|
112
|
+
def title_i18n_key
|
113
|
+
title_i18n.first
|
114
|
+
end
|
115
|
+
|
116
|
+
def title_i18n_args
|
117
|
+
args = title_i18n.drop 1
|
118
|
+
args if args.any?
|
119
|
+
end
|
69
120
|
end
|
70
121
|
end
|
data/lib/maia/poke.rb
CHANGED
data/lib/maia/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: maia
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Logan Serman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-05-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|