maia 3.0.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
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: 3.0.0
4
+ version: 5.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: 2018-02-20 00:00:00.000000000 Z
11
+ date: 2019-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,40 +16,40 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4.2'
19
+ version: '5'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '5'
22
+ version: '7'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '4.2'
29
+ version: '5'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '5'
32
+ version: '7'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: activejob
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: '4.2'
39
+ version: '5'
40
40
  - - "<"
41
41
  - !ruby/object:Gem::Version
42
- version: '5'
42
+ version: '7'
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
46
46
  requirements:
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: '4.2'
49
+ version: '5'
50
50
  - - "<"
51
51
  - !ruby/object:Gem::Version
52
- version: '5'
52
+ version: '7'
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: responders
55
55
  requirement: !ruby/object:Gem::Requirement
@@ -65,41 +65,13 @@ dependencies:
65
65
  - !ruby/object:Gem::Version
66
66
  version: '0'
67
67
  - !ruby/object:Gem::Dependency
68
- name: sqlite3
68
+ name: googleauth
69
69
  requirement: !ruby/object:Gem::Requirement
70
70
  requirements:
71
71
  - - ">="
72
72
  - !ruby/object:Gem::Version
73
73
  version: '0'
74
- type: :development
75
- prerelease: false
76
- version_requirements: !ruby/object:Gem::Requirement
77
- requirements:
78
- - - ">="
79
- - !ruby/object:Gem::Version
80
- version: '0'
81
- - !ruby/object:Gem::Dependency
82
- name: rspec-rails
83
- requirement: !ruby/object:Gem::Requirement
84
- requirements:
85
- - - ">="
86
- - !ruby/object:Gem::Version
87
- version: '0'
88
- type: :development
89
- prerelease: false
90
- version_requirements: !ruby/object:Gem::Requirement
91
- requirements:
92
- - - ">="
93
- - !ruby/object:Gem::Version
94
- version: '0'
95
- - !ruby/object:Gem::Dependency
96
- name: capybara
97
- requirement: !ruby/object:Gem::Requirement
98
- requirements:
99
- - - ">="
100
- - !ruby/object:Gem::Version
101
- version: '0'
102
- type: :development
74
+ type: :runtime
103
75
  prerelease: false
104
76
  version_requirements: !ruby/object:Gem::Requirement
105
77
  requirements:
@@ -107,7 +79,7 @@ dependencies:
107
79
  - !ruby/object:Gem::Version
108
80
  version: '0'
109
81
  - !ruby/object:Gem::Dependency
110
- name: capybara-webkit
82
+ name: sqlite3
111
83
  requirement: !ruby/object:Gem::Requirement
112
84
  requirements:
113
85
  - - ">="
@@ -121,7 +93,7 @@ dependencies:
121
93
  - !ruby/object:Gem::Version
122
94
  version: '0'
123
95
  - !ruby/object:Gem::Dependency
124
- name: launchy
96
+ name: rspec-rails
125
97
  requirement: !ruby/object:Gem::Requirement
126
98
  requirements:
127
99
  - - ">="
@@ -148,20 +120,6 @@ dependencies:
148
120
  - - ">="
149
121
  - !ruby/object:Gem::Version
150
122
  version: '0'
151
- - !ruby/object:Gem::Dependency
152
- name: webmock-rspec-helper
153
- requirement: !ruby/object:Gem::Requirement
154
- requirements:
155
- - - ">="
156
- - !ruby/object:Gem::Version
157
- version: '0'
158
- type: :development
159
- prerelease: false
160
- version_requirements: !ruby/object:Gem::Requirement
161
- requirements:
162
- - - ">="
163
- - !ruby/object:Gem::Version
164
- version: '0'
165
123
  description: Manage device tokens and push messaging with Rails and FCM.
166
124
  email:
167
125
  - loganserman@gmail.com
@@ -181,20 +139,26 @@ files:
181
139
  - config/routes.rb
182
140
  - db/migrate/20150302191320_create_maia_devices.rb
183
141
  - lib/maia.rb
184
- - lib/maia/dry_run.rb
142
+ - lib/maia/devices.rb
185
143
  - lib/maia/engine.rb
186
- - lib/maia/error.rb
187
- - lib/maia/fcm.rb
144
+ - lib/maia/error/generic.rb
145
+ - lib/maia/error/no_credentials.rb
146
+ - lib/maia/error/unregistered.rb
188
147
  - lib/maia/fcm/connection.rb
148
+ - lib/maia/fcm/credentials.rb
149
+ - lib/maia/fcm/gateway.rb
189
150
  - lib/maia/fcm/notification.rb
151
+ - lib/maia/fcm/platform/android.rb
152
+ - lib/maia/fcm/platform/apns.rb
190
153
  - lib/maia/fcm/response.rb
191
- - lib/maia/fcm/response_collection.rb
192
- - lib/maia/fcm/result.rb
193
- - lib/maia/fcm/result_collection.rb
194
- - lib/maia/fcm/service.rb
154
+ - lib/maia/fcm/serializer.rb
195
155
  - lib/maia/message.rb
196
- - lib/maia/messenger.rb
156
+ - lib/maia/messengers/activejob.rb
157
+ - lib/maia/messengers/array.rb
158
+ - lib/maia/messengers/inline.rb
197
159
  - lib/maia/poke.rb
160
+ - lib/maia/token.rb
161
+ - lib/maia/topic.rb
198
162
  - lib/maia/version.rb
199
163
  homepage: https://github.com/lserman/maia
200
164
  licenses:
@@ -216,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
216
180
  version: '0'
217
181
  requirements: []
218
182
  rubyforge_project:
219
- rubygems_version: 2.7.6
183
+ rubygems_version: 2.7.7
220
184
  signing_key:
221
185
  specification_version: 4
222
186
  summary: Manage device tokens and push messaging with Rails and FCM.
data/lib/maia/dry_run.rb DELETED
@@ -1,15 +0,0 @@
1
- module Maia
2
- class DryRun < Message
3
- def title
4
- ''
5
- end
6
-
7
- def body
8
- ''
9
- end
10
-
11
- def dry_run?
12
- true
13
- end
14
- end
15
- end
data/lib/maia/error.rb DELETED
@@ -1,4 +0,0 @@
1
- module Maia
2
- class Error < StandardError
3
- end
4
- end
data/lib/maia/fcm.rb DELETED
@@ -1,7 +0,0 @@
1
- module Maia
2
- module FCM
3
- class << self
4
- attr_accessor :key
5
- end
6
- end
7
- end
@@ -1,34 +0,0 @@
1
- module Maia
2
- module FCM
3
- class ResponseCollection
4
- include Enumerable
5
-
6
- def initialize(notification, responses = [])
7
- @notification = notification
8
- @responses = responses
9
- end
10
-
11
- def results
12
- collection = ResultCollection.new
13
- @responses.each do |response|
14
- response.results.each do |result|
15
- collection << result
16
- end
17
- end
18
- collection
19
- end
20
-
21
- def [](index)
22
- @responses[index]
23
- end
24
-
25
- def <<(response)
26
- @responses.concat Array(response).flatten
27
- end
28
-
29
- def each(&block)
30
- @responses.each(&block)
31
- end
32
- end
33
- end
34
- end
@@ -1,31 +0,0 @@
1
- module Maia
2
- module FCM
3
- class Result
4
- include ActiveModel::Model
5
-
6
- attr_accessor :message_id, :registration_id, :error
7
- attr_reader :token
8
-
9
- def initialize(attributes, token)
10
- super attributes
11
- @token = token
12
- end
13
-
14
- def success?
15
- message_id.present?
16
- end
17
-
18
- def fail?
19
- !success?
20
- end
21
-
22
- def canonical_id
23
- registration_id
24
- end
25
-
26
- def has_canonical_id?
27
- canonical_id.present?
28
- end
29
- end
30
- end
31
- end
@@ -1,35 +0,0 @@
1
- module Maia
2
- module FCM
3
- class ResultCollection
4
- include Enumerable
5
-
6
- def initialize(results = [])
7
- @results = results
8
- end
9
-
10
- def succeeded
11
- @results.select(&:success?)
12
- end
13
-
14
- def failed
15
- @results.select(&:fail?)
16
- end
17
-
18
- def with_canonical_ids
19
- @results.select(&:has_canonical_id?)
20
- end
21
-
22
- def [](index)
23
- @results[index]
24
- end
25
-
26
- def <<(result)
27
- @results << result
28
- end
29
-
30
- def each(&block)
31
- @results.each(&block)
32
- end
33
- end
34
- end
35
- end
@@ -1,48 +0,0 @@
1
- module Maia
2
- module FCM
3
- class Service
4
- def initialize
5
- @connection ||= FCM::Connection.new key
6
- end
7
-
8
- def key
9
- ENV.fetch 'FCM_KEY', Maia::FCM.key
10
- end
11
-
12
- def deliver(notification, *tokens, topic: nil)
13
- responses = ResponseCollection.new notification
14
- responses << deliver_all(notification, tokens)
15
- responses << deliver_all(notification, topic) if topic
16
- responses
17
- end
18
-
19
- private
20
- def deliver_all(notification, recipients)
21
- batch(recipients).map do |batch|
22
- if batch.many?
23
- multicast notification, batch
24
- elsif batch.one?
25
- unicast notification, batch.first
26
- end
27
- end
28
- end
29
-
30
- def unicast(notification, recipient)
31
- deliver! notification, recipient, to: recipient
32
- end
33
-
34
- def multicast(notification, recipients)
35
- deliver! notification, recipients, registration_ids: recipients
36
- end
37
-
38
- def deliver!(notification, recipients, params = {})
39
- payload = notification.to_h.merge params
40
- Response.new @connection.write(payload), Array(recipients)
41
- end
42
-
43
- def batch(recipients, batch_size: Maia::BATCH_SIZE)
44
- Array(recipients).flatten.compact.each_slice batch_size
45
- end
46
- end
47
- end
48
- end
@@ -1,61 +0,0 @@
1
- module Maia
2
- class Messenger < ActiveJob::Base
3
- def perform(tokens, payload)
4
- logger.info "Pushing to #{tokens.size} token(s)..."
5
- logger.info "Payload: #{payload}"
6
-
7
- notification = FCM::Notification.new payload
8
- responses = fcm.deliver notification, tokens
9
-
10
- responses.each do |response|
11
- raise Maia::Error, response.error if response.error
12
- handle_errors response.results.failed
13
- update_devices_to_use_canonical_ids response.results.with_canonical_ids
14
- end
15
- end
16
-
17
- private
18
- def fcm
19
- @_service ||= FCM::Service.new
20
- end
21
-
22
- def handle_errors(results)
23
- results.each do |result|
24
- device = Maia::Device.find_by token: result.token
25
- next unless device.present?
26
-
27
- if device_unrecoverable? result.error
28
- log_error "Destroying device #{device.id}", result, device
29
- device.destroy
30
- else
31
- log_error "Push to device #{device.id} failed", result, device
32
- end
33
- end
34
- end
35
-
36
- def device_unrecoverable?(error)
37
- error =~ /InvalidRegistration|NotRegistered|MismatchSenderId/
38
- end
39
-
40
- def log_error(message, result, device)
41
- logger.info "#{message} (error: #{result.error}, token: #{device.token})"
42
- end
43
-
44
- def update_devices_to_use_canonical_ids(results)
45
- results.each do |result|
46
- device = Maia::Device.find_by token: result.token
47
- next if device.nil?
48
-
49
- if user_already_has_token_registered?(device.pushable, result.canonical_id)
50
- device.destroy
51
- else
52
- device.update token: result.canonical_id
53
- end
54
- end
55
- end
56
-
57
- def user_already_has_token_registered?(user, token)
58
- user.devices.exists? token: token
59
- end
60
- end
61
- end