notifiable-core 0.1.5 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/db/migrate/201809032135000_add_error_code_to_notification_statuses.rb +8 -0
- data/db/migrate/201809032235000_add_delivered_count_to_notifications.rb +7 -0
- data/lib/notifiable/notification.rb +10 -0
- data/lib/notifiable/notification_status.rb +18 -8
- data/lib/notifiable/notifier_base.rb +4 -6
- data/lib/notifiable/version.rb +1 -1
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 425bb33e77f7b1321f9df9f3dd7f0cfc59804f3bfbd3e156b19f25f464a2a640
|
4
|
+
data.tar.gz: fa9dd36fd58bb92a5f751d015ded197823bb5cd7481d0a662f8da9e6b40498f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f06b405186be419fffbfc69af22cb287406714e480e072aa227fe8a5ff12d3fc451c45f8ff0aa1e653f74a6b3d32f6d0396ea8439e3aeb4212df0ead0e855317
|
7
|
+
data.tar.gz: 9980a92f754834eca0e6bdf408bfcd794860c653c6f9335655e3015fc940336e341100c9031087ead98cf4ba9ffe72effb1702ec8991537a586b41be21da28b9
|
@@ -46,6 +46,16 @@ module Notifiable
|
|
46
46
|
def send_params
|
47
47
|
@send_params ||= (parameters || {}).merge(n_id: id)
|
48
48
|
end
|
49
|
+
|
50
|
+
def delivered!(device_token)
|
51
|
+
increment!(:delivered_count)
|
52
|
+
notification_statuses.find_by(device_token: device_token).delivered! if notification_statuses.exists?(device_token: device_token)
|
53
|
+
end
|
54
|
+
|
55
|
+
def opened!(device_token)
|
56
|
+
increment!(:opened_count)
|
57
|
+
notification_statuses.find_by(device_token: device_token).opened! if notification_statuses.exists?(device_token: device_token)
|
58
|
+
end
|
49
59
|
|
50
60
|
private
|
51
61
|
|
@@ -2,7 +2,12 @@
|
|
2
2
|
|
3
3
|
module Notifiable
|
4
4
|
class NotificationStatus < ActiveRecord::Base
|
5
|
-
self.
|
5
|
+
self.table_name = 'notifiable_statuses'
|
6
|
+
|
7
|
+
REJECTED_STATUS = 1
|
8
|
+
SENT_STATUS = 2
|
9
|
+
DELIVERED_STATUS = 3
|
10
|
+
OPENED_STATUS = 4
|
6
11
|
|
7
12
|
belongs_to :notification, class_name: 'Notifiable::Notification'
|
8
13
|
validates :notification, presence: true
|
@@ -10,15 +15,20 @@ module Notifiable
|
|
10
15
|
belongs_to :device_token, class_name: 'Notifiable::DeviceToken'
|
11
16
|
validates :device_token, presence: true
|
12
17
|
|
13
|
-
|
14
|
-
|
15
|
-
def opened!
|
16
|
-
update_attribute(:status, -1)
|
17
|
-
notification.increment!(:opened_count)
|
18
|
+
def rejected!
|
19
|
+
update_attributes(status: REJECTED_STATUS)
|
18
20
|
end
|
19
21
|
|
20
|
-
def
|
21
|
-
status
|
22
|
+
def sent!
|
23
|
+
update_attributes(status: SENT_STATUS)
|
24
|
+
end
|
25
|
+
|
26
|
+
def delivered!
|
27
|
+
update_attributes(status: DELIVERED_STATUS)
|
28
|
+
end
|
29
|
+
|
30
|
+
def opened!
|
31
|
+
update_attributes(status: OPENED_STATUS)
|
22
32
|
end
|
23
33
|
end
|
24
34
|
end
|
@@ -2,9 +2,7 @@
|
|
2
2
|
require 'logger'
|
3
3
|
|
4
4
|
module Notifiable
|
5
|
-
class NotifierBase
|
6
|
-
OK_STATUS = 0
|
7
|
-
|
5
|
+
class NotifierBase
|
8
6
|
attr_reader :env, :notification
|
9
7
|
|
10
8
|
def self.notifier_attribute(*vars)
|
@@ -43,14 +41,14 @@ module Notifiable
|
|
43
41
|
|
44
42
|
def flush; end
|
45
43
|
|
46
|
-
def processed(device_token, status =
|
44
|
+
def processed(device_token, status = NotificationStatus::SENT_STATUS, error_code = nil, error_message = nil)
|
47
45
|
if @notification.app.save_notification_statuses
|
48
|
-
receipts << { notification_id: notification.id, device_token_id: device_token.id, status: status, created_at: DateTime.now, error_message: error_message }
|
46
|
+
receipts << { notification_id: notification.id, device_token_id: device_token.id, status: status, created_at: DateTime.now, error_code: error_code, error_message: error_message }
|
49
47
|
save_receipts if receipts.count >= Notifiable.notification_status_batch_size
|
50
48
|
end
|
51
49
|
|
52
50
|
@notification.sent_count += 1
|
53
|
-
@notification.gateway_accepted_count += 1 if status ==
|
51
|
+
@notification.gateway_accepted_count += 1 if status == NotificationStatus::SENT_STATUS
|
54
52
|
@notification.save if @notification.sent_count % Notifiable.notification_status_batch_size == 0
|
55
53
|
end
|
56
54
|
|
data/lib/notifiable/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: notifiable-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Brooke-Smith
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-09-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -178,6 +178,20 @@ dependencies:
|
|
178
178
|
- - ">="
|
179
179
|
- !ruby/object:Gem::Version
|
180
180
|
version: '0'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: byebug
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - ">="
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
181
195
|
description:
|
182
196
|
email:
|
183
197
|
- matt@futureworkshops.com
|
@@ -202,6 +216,8 @@ files:
|
|
202
216
|
- db/migrate/201806242135000_add_category_to_notifications.rb
|
203
217
|
- db/migrate/201808242135000_add_error_message_to_notification_statuses.rb
|
204
218
|
- db/migrate/201808272135000_add_status_to_notifications.rb
|
219
|
+
- db/migrate/201809032135000_add_error_code_to_notification_statuses.rb
|
220
|
+
- db/migrate/201809032235000_add_delivered_count_to_notifications.rb
|
205
221
|
- lib/notifiable.rb
|
206
222
|
- lib/notifiable/app.rb
|
207
223
|
- lib/notifiable/device_token.rb
|