rpush 5.0.0 → 6.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 +4 -4
- data/CHANGELOG.md +74 -2
- data/README.md +104 -18
- data/lib/generators/templates/add_adm.rb +1 -1
- data/lib/generators/templates/add_alert_is_json_to_rapns_notifications.rb +2 -2
- data/lib/generators/templates/add_app_to_rapns.rb +2 -2
- data/lib/generators/templates/add_fail_after_to_rpush_notifications.rb +1 -1
- data/lib/generators/templates/add_gcm.rb +11 -25
- data/lib/generators/templates/add_rpush.rb +33 -83
- data/lib/generators/templates/add_wpns.rb +1 -1
- data/lib/generators/templates/create_rapns_apps.rb +1 -1
- data/lib/generators/templates/create_rapns_feedback.rb +3 -9
- data/lib/generators/templates/create_rapns_notifications.rb +3 -9
- data/lib/generators/templates/rename_rapns_to_rpush.rb +9 -33
- data/lib/generators/templates/rpush.rb +4 -0
- data/lib/generators/templates/rpush_2_0_0_updates.rb +5 -17
- data/lib/generators/templates/rpush_2_1_0_updates.rb +1 -1
- data/lib/generators/templates/rpush_2_6_0_updates.rb +1 -1
- data/lib/generators/templates/rpush_2_7_0_updates.rb +1 -1
- data/lib/generators/templates/rpush_3_0_0_updates.rb +1 -1
- data/lib/generators/templates/rpush_3_0_1_updates.rb +1 -1
- data/lib/generators/templates/rpush_3_1_0_add_pushy.rb +1 -1
- data/lib/generators/templates/rpush_3_1_1_updates.rb +1 -1
- data/lib/generators/templates/rpush_3_2_0_add_apns_p8.rb +1 -1
- data/lib/generators/templates/rpush_3_2_4_updates.rb +1 -1
- data/lib/generators/templates/rpush_3_3_0_updates.rb +1 -1
- data/lib/generators/templates/rpush_3_3_1_updates.rb +3 -3
- data/lib/generators/templates/rpush_4_1_0_updates.rb +1 -1
- data/lib/generators/templates/rpush_4_1_1_updates.rb +1 -1
- data/lib/generators/templates/rpush_4_2_0_updates.rb +1 -1
- data/lib/rpush/cli.rb +1 -1
- data/lib/rpush/client/active_model.rb +5 -1
- data/lib/rpush/client/active_model/adm/data_validator.rb +1 -1
- data/lib/rpush/client/active_model/apns/app.rb +1 -17
- data/lib/rpush/client/active_model/apns/device_token_format_validator.rb +2 -2
- data/lib/rpush/client/active_model/apns/notification.rb +13 -1
- data/lib/rpush/client/active_model/apns/notification_payload_size_validator.rb +15 -0
- data/lib/rpush/client/active_model/apns2/app.rb +7 -1
- data/lib/rpush/client/active_model/apns2/notification.rb +14 -0
- data/lib/rpush/client/active_model/certificate_private_key_validator.rb +19 -0
- data/lib/rpush/client/active_model/gcm/expiry_collapse_key_mutual_inclusion_validator.rb +1 -1
- data/lib/rpush/client/active_model/payload_data_size_validator.rb +1 -1
- data/lib/rpush/client/active_model/registration_ids_count_validator.rb +1 -1
- data/lib/rpush/client/active_model/webpush/app.rb +41 -0
- data/lib/rpush/client/active_model/webpush/notification.rb +66 -0
- data/lib/rpush/client/active_record.rb +4 -0
- data/lib/rpush/client/active_record/apns/active_record_serializable_notification.rb +65 -0
- data/lib/rpush/client/active_record/apns/notification.rb +1 -57
- data/lib/rpush/client/active_record/apns2/notification.rb +4 -1
- data/lib/rpush/client/active_record/apnsp8/notification.rb +1 -0
- data/lib/rpush/client/active_record/webpush/app.rb +11 -0
- data/lib/rpush/client/active_record/webpush/notification.rb +12 -0
- data/lib/rpush/client/redis.rb +3 -0
- data/lib/rpush/client/redis/apns2/notification.rb +1 -0
- data/lib/rpush/client/redis/apnsp8/notification.rb +2 -0
- data/lib/rpush/client/redis/pushy/notification.rb +0 -1
- data/lib/rpush/client/redis/webpush/app.rb +15 -0
- data/lib/rpush/client/redis/webpush/notification.rb +15 -0
- data/lib/rpush/configuration.rb +3 -2
- data/lib/rpush/daemon.rb +4 -1
- data/lib/rpush/daemon/apns/feedback_receiver.rb +1 -1
- data/lib/rpush/daemon/apns2/delivery.rb +14 -2
- data/lib/rpush/daemon/apnsp8/delivery.rb +14 -3
- data/lib/rpush/daemon/app_runner.rb +1 -1
- data/lib/rpush/daemon/batch.rb +12 -5
- data/lib/rpush/daemon/delivery.rb +1 -2
- data/lib/rpush/daemon/store/active_record/reconnectable.rb +1 -1
- data/lib/rpush/daemon/string_helpers.rb +1 -1
- data/lib/rpush/daemon/webpush.rb +10 -0
- data/lib/rpush/daemon/webpush/delivery.rb +114 -0
- data/lib/rpush/logger.rb +1 -0
- data/lib/rpush/version.rb +1 -1
- data/spec/functional/apns2_spec.rb +99 -2
- data/spec/functional/retry_spec.rb +1 -1
- data/spec/functional/webpush_spec.rb +30 -0
- data/spec/spec_helper.rb +3 -1
- data/spec/support/active_record_setup.rb +4 -3
- data/spec/support/config/database.yml +4 -4
- data/spec/support/simplecov_helper.rb +2 -2
- data/spec/unit/client/active_record/adm/app_spec.rb +2 -54
- data/spec/unit/client/active_record/adm/notification_spec.rb +2 -39
- data/spec/unit/client/active_record/apns/app_spec.rb +3 -26
- data/spec/unit/client/active_record/apns/feedback_spec.rb +1 -5
- data/spec/unit/client/active_record/apns/notification_spec.rb +29 -293
- data/spec/unit/client/active_record/apns2/app_spec.rb +5 -0
- data/spec/unit/client/active_record/apns2/notification_spec.rb +65 -0
- data/spec/unit/client/active_record/apnsp8/notification_spec.rb +28 -0
- data/spec/unit/client/active_record/app_spec.rb +1 -26
- data/spec/unit/client/active_record/gcm/app_spec.rb +3 -1
- data/spec/unit/client/active_record/gcm/notification_spec.rb +6 -88
- data/spec/unit/client/active_record/notification_spec.rb +3 -11
- data/spec/unit/client/active_record/pushy/app_spec.rb +2 -13
- data/spec/unit/client/active_record/pushy/notification_spec.rb +2 -55
- data/spec/unit/client/active_record/shared/app.rb +14 -0
- data/spec/unit/{notification_shared.rb → client/active_record/shared/notification.rb} +12 -7
- data/spec/unit/client/active_record/webpush/app_spec.rb +6 -0
- data/spec/unit/client/active_record/webpush/notification_spec.rb +6 -0
- data/spec/unit/client/active_record/wns/badge_notification_spec.rb +1 -11
- data/spec/unit/client/active_record/wns/raw_notification_spec.rb +3 -12
- data/spec/unit/client/active_record/wpns/app_spec.rb +3 -1
- data/spec/unit/client/active_record/wpns/notification_spec.rb +2 -17
- data/spec/unit/client/redis/adm/app_spec.rb +5 -0
- data/spec/unit/client/redis/adm/notification_spec.rb +5 -0
- data/spec/unit/client/redis/apns/app_spec.rb +5 -0
- data/spec/unit/client/redis/apns/feedback_spec.rb +5 -0
- data/spec/unit/client/redis/apns/notification_spec.rb +50 -0
- data/spec/unit/client/redis/apns2/app_spec.rb +4 -0
- data/spec/unit/client/redis/apns2/notification_spec.rb +50 -0
- data/spec/unit/client/redis/apnsp8/notification_spec.rb +29 -0
- data/spec/unit/client/redis/app_spec.rb +5 -0
- data/spec/unit/client/redis/gcm/app_spec.rb +5 -0
- data/spec/unit/client/redis/gcm/notification_spec.rb +5 -0
- data/spec/unit/client/redis/notification_spec.rb +5 -0
- data/spec/unit/client/redis/pushy/app_spec.rb +5 -0
- data/spec/unit/client/redis/pushy/notification_spec.rb +5 -0
- data/spec/unit/client/redis/webpush/app_spec.rb +5 -0
- data/spec/unit/client/redis/webpush/notification_spec.rb +5 -0
- data/spec/unit/client/redis/wns/badge_notification_spec.rb +5 -0
- data/spec/unit/client/redis/wns/raw_notification_spec.rb +22 -0
- data/spec/unit/client/redis/wpns/app_spec.rb +5 -0
- data/spec/unit/client/redis/wpns/notification_spec.rb +5 -0
- data/spec/unit/client/shared/adm/app.rb +51 -0
- data/spec/unit/client/shared/adm/notification.rb +39 -0
- data/spec/unit/client/shared/apns/app.rb +29 -0
- data/spec/unit/client/shared/apns/feedback.rb +9 -0
- data/spec/unit/client/shared/apns/notification.rb +277 -0
- data/spec/unit/client/shared/app.rb +17 -0
- data/spec/unit/client/shared/gcm/app.rb +4 -0
- data/spec/unit/client/shared/gcm/notification.rb +77 -0
- data/spec/unit/client/shared/notification.rb +10 -0
- data/spec/unit/client/shared/pushy/app.rb +17 -0
- data/spec/unit/client/shared/pushy/notification.rb +55 -0
- data/spec/unit/client/shared/webpush/app.rb +33 -0
- data/spec/unit/client/shared/webpush/notification.rb +83 -0
- data/spec/unit/client/shared/wns/badge_notification.rb +15 -0
- data/spec/unit/client/shared/wns/raw_notification.rb +21 -0
- data/spec/unit/client/shared/wpns/app.rb +4 -0
- data/spec/unit/client/shared/wpns/notification.rb +18 -0
- data/spec/unit/daemon/apnsp8/delivery_spec.rb +53 -0
- data/spec/unit/daemon/batch_spec.rb +50 -2
- data/spec/unit/daemon/delivery_spec.rb +10 -0
- data/spec/unit/daemon/pushy/delivery_spec.rb +5 -3
- data/spec/unit/daemon/shared/store.rb +312 -0
- data/spec/unit/daemon/store/active_record/reconnectable_spec.rb +7 -7
- data/spec/unit/daemon/store/active_record_spec.rb +2 -290
- data/spec/unit/daemon/store/redis_spec.rb +2 -291
- data/spec/unit/daemon/webpush/delivery_spec.rb +144 -0
- data/spec/unit_spec_helper.rb +3 -0
- metadata +137 -13
- data/lib/rpush/client/active_model/apns/binary_notification_validator.rb +0 -16
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class CreateRapnsFeedback < ActiveRecord::
|
|
1
|
+
class CreateRapnsFeedback < ActiveRecord::Migration[5.0]
|
|
2
2
|
def self.up
|
|
3
3
|
create_table :rapns_feedback do |t|
|
|
4
4
|
t.string :device_token, null: false, limit: 64
|
|
@@ -10,14 +10,8 @@ class CreateRapnsFeedback < ActiveRecord::VERSION::MAJOR >= 5 ? ActiveRecord::Mi
|
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def self.down
|
|
13
|
-
if
|
|
14
|
-
|
|
15
|
-
remove_index :rapns_feedback, name: :index_rapns_feedback_on_device_token
|
|
16
|
-
end
|
|
17
|
-
else
|
|
18
|
-
if index_name_exists?(:rapns_feedback, :index_rapns_feedback_on_device_token, true)
|
|
19
|
-
remove_index :rapns_feedback, name: :index_rapns_feedback_on_device_token
|
|
20
|
-
end
|
|
13
|
+
if index_name_exists?(:rapns_feedback, :index_rapns_feedback_on_device_token)
|
|
14
|
+
remove_index :rapns_feedback, name: :index_rapns_feedback_on_device_token
|
|
21
15
|
end
|
|
22
16
|
|
|
23
17
|
drop_table :rapns_feedback
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class CreateRapnsNotifications < ActiveRecord::
|
|
1
|
+
class CreateRapnsNotifications < ActiveRecord::Migration[5.0]
|
|
2
2
|
def self.up
|
|
3
3
|
create_table :rapns_notifications do |t|
|
|
4
4
|
t.integer :badge, null: true
|
|
@@ -21,14 +21,8 @@ class CreateRapnsNotifications < ActiveRecord::VERSION::MAJOR >= 5 ? ActiveRecor
|
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def self.down
|
|
24
|
-
if
|
|
25
|
-
|
|
26
|
-
remove_index :rapns_notifications, name: 'index_rapns_notifications_multi'
|
|
27
|
-
end
|
|
28
|
-
else
|
|
29
|
-
if index_name_exists?(:rapns_notifications, 'index_rapns_notifications_multi', true)
|
|
30
|
-
remove_index :rapns_notifications, name: 'index_rapns_notifications_multi'
|
|
31
|
-
end
|
|
24
|
+
if index_name_exists?(:rapns_notifications, 'index_rapns_notifications_multi')
|
|
25
|
+
remove_index :rapns_notifications, name: 'index_rapns_notifications_multi'
|
|
32
26
|
end
|
|
33
27
|
|
|
34
28
|
drop_table :rapns_notifications
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class RenameRapnsToRpush < ActiveRecord::
|
|
1
|
+
class RenameRapnsToRpush < ActiveRecord::Migration[5.0]
|
|
2
2
|
module Rpush
|
|
3
3
|
class App < ActiveRecord::Base
|
|
4
4
|
self.table_name = 'rpush_apps'
|
|
@@ -18,24 +18,12 @@ class RenameRapnsToRpush < ActiveRecord::VERSION::MAJOR >= 5 ? ActiveRecord::Mig
|
|
|
18
18
|
rename_table :rapns_apps, :rpush_apps
|
|
19
19
|
rename_table :rapns_feedback, :rpush_feedback
|
|
20
20
|
|
|
21
|
-
if
|
|
22
|
-
|
|
23
|
-
rename_index :rpush_notifications, :index_rapns_notifications_multi, :index_rpush_notifications_multi
|
|
24
|
-
end
|
|
25
|
-
else
|
|
26
|
-
if index_name_exists?(:rpush_notifications, :index_rapns_notifications_multi, true)
|
|
27
|
-
rename_index :rpush_notifications, :index_rapns_notifications_multi, :index_rpush_notifications_multi
|
|
28
|
-
end
|
|
21
|
+
if index_name_exists?(:rpush_notifications, :index_rapns_notifications_multi)
|
|
22
|
+
rename_index :rpush_notifications, :index_rapns_notifications_multi, :index_rpush_notifications_multi
|
|
29
23
|
end
|
|
30
24
|
|
|
31
|
-
if
|
|
32
|
-
|
|
33
|
-
rename_index :rpush_feedback, :index_rapns_feedback_on_device_token, :index_rpush_feedback_on_device_token
|
|
34
|
-
end
|
|
35
|
-
else
|
|
36
|
-
if index_name_exists?(:rpush_feedback, :index_rapns_feedback_on_device_token, true)
|
|
37
|
-
rename_index :rpush_feedback, :index_rapns_feedback_on_device_token, :index_rpush_feedback_on_device_token
|
|
38
|
-
end
|
|
25
|
+
if index_name_exists?(:rpush_feedback, :index_rapns_feedback_on_device_token)
|
|
26
|
+
rename_index :rpush_feedback, :index_rapns_feedback_on_device_token, :index_rpush_feedback_on_device_token
|
|
39
27
|
end
|
|
40
28
|
|
|
41
29
|
update_type(RenameRapnsToRpush::Rpush::Notification, 'Rapns::Apns::Notification', 'Rpush::Apns::Notification')
|
|
@@ -60,24 +48,12 @@ class RenameRapnsToRpush < ActiveRecord::VERSION::MAJOR >= 5 ? ActiveRecord::Mig
|
|
|
60
48
|
update_type(RenameRapnsToRpush::Rpush::App, 'Rpush::Adm::App', 'Rapns::Adm::App')
|
|
61
49
|
update_type(RenameRapnsToRpush::Rpush::App, 'Rpush::Wpns::App', 'Rapns::Wpns::App')
|
|
62
50
|
|
|
63
|
-
if
|
|
64
|
-
|
|
65
|
-
rename_index :rpush_notifications, :index_rpush_notifications_multi, :index_rapns_notifications_multi
|
|
66
|
-
end
|
|
67
|
-
else
|
|
68
|
-
if index_name_exists?(:rpush_notifications, :index_rpush_notifications_multi, true)
|
|
69
|
-
rename_index :rpush_notifications, :index_rpush_notifications_multi, :index_rapns_notifications_multi
|
|
70
|
-
end
|
|
51
|
+
if index_name_exists?(:rpush_notifications, :index_rpush_notifications_multi)
|
|
52
|
+
rename_index :rpush_notifications, :index_rpush_notifications_multi, :index_rapns_notifications_multi
|
|
71
53
|
end
|
|
72
54
|
|
|
73
|
-
if
|
|
74
|
-
|
|
75
|
-
rename_index :rpush_feedback, :index_rpush_feedback_on_device_token, :index_rapns_feedback_on_device_token
|
|
76
|
-
end
|
|
77
|
-
else
|
|
78
|
-
if index_name_exists?(:rpush_feedback, :index_rpush_feedback_on_device_token, true)
|
|
79
|
-
rename_index :rpush_feedback, :index_rpush_feedback_on_device_token, :index_rapns_feedback_on_device_token
|
|
80
|
-
end
|
|
55
|
+
if index_name_exists?(:rpush_feedback, :index_rpush_feedback_on_device_token)
|
|
56
|
+
rename_index :rpush_feedback, :index_rpush_feedback_on_device_token, :index_rapns_feedback_on_device_token
|
|
81
57
|
end
|
|
82
58
|
|
|
83
59
|
rename_table :rpush_notifications, :rapns_notifications
|
|
@@ -26,6 +26,10 @@ Rpush.configure do |config|
|
|
|
26
26
|
# Define a custom logger.
|
|
27
27
|
# config.logger = MyLogger.new
|
|
28
28
|
|
|
29
|
+
# By default in foreground mode logs are directed both to the logger and to stdout.
|
|
30
|
+
# If the logger goes to stdout, you can disable foreground logging to avoid duplication.
|
|
31
|
+
# config.foreground_logging = false
|
|
32
|
+
|
|
29
33
|
# config.apns.feedback_receiver.enabled = true
|
|
30
34
|
# config.apns.feedback_receiver.frequency = 60
|
|
31
35
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class Rpush200Updates < ActiveRecord::
|
|
1
|
+
class Rpush200Updates < ActiveRecord::Migration[5.0]
|
|
2
2
|
module Rpush
|
|
3
3
|
class App < ActiveRecord::Base
|
|
4
4
|
self.table_name = 'rpush_apps'
|
|
@@ -17,14 +17,8 @@ class Rpush200Updates < ActiveRecord::VERSION::MAJOR >= 5 ? ActiveRecord::Migrat
|
|
|
17
17
|
add_column :rpush_notifications, :processing, :boolean, null: false, default: false
|
|
18
18
|
add_column :rpush_notifications, :priority, :integer, null: true
|
|
19
19
|
|
|
20
|
-
if
|
|
21
|
-
|
|
22
|
-
remove_index :rpush_notifications, name: :index_rpush_notifications_multi
|
|
23
|
-
end
|
|
24
|
-
else
|
|
25
|
-
if index_name_exists?(:rpush_notifications, :index_rpush_notifications_multi, true)
|
|
26
|
-
remove_index :rpush_notifications, name: :index_rpush_notifications_multi
|
|
27
|
-
end
|
|
20
|
+
if index_name_exists?(:rpush_notifications, :index_rpush_notifications_multi)
|
|
21
|
+
remove_index :rpush_notifications, name: :index_rpush_notifications_multi
|
|
28
22
|
end
|
|
29
23
|
|
|
30
24
|
add_index :rpush_notifications, [:delivered, :failed], name: 'index_rpush_notifications_multi', where: 'NOT delivered AND NOT failed'
|
|
@@ -52,14 +46,8 @@ class Rpush200Updates < ActiveRecord::VERSION::MAJOR >= 5 ? ActiveRecord::Migrat
|
|
|
52
46
|
change_column :rpush_feedback, :app_id, :string
|
|
53
47
|
rename_column :rpush_feedback, :app_id, :app
|
|
54
48
|
|
|
55
|
-
if
|
|
56
|
-
|
|
57
|
-
remove_index :rpush_notifications, name: :index_rpush_notifications_multi
|
|
58
|
-
end
|
|
59
|
-
else
|
|
60
|
-
if index_name_exists?(:rpush_notifications, :index_rpush_notifications_multi, true)
|
|
61
|
-
remove_index :rpush_notifications, name: :index_rpush_notifications_multi
|
|
62
|
-
end
|
|
49
|
+
if index_name_exists?(:rpush_notifications, :index_rpush_notifications_multi)
|
|
50
|
+
remove_index :rpush_notifications, name: :index_rpush_notifications_multi
|
|
63
51
|
end
|
|
64
52
|
|
|
65
53
|
add_index :rpush_notifications, [:app_id, :delivered, :failed, :deliver_after], name: 'index_rpush_notifications_multi'
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class Rpush210Updates < ActiveRecord::
|
|
1
|
+
class Rpush210Updates < ActiveRecord::Migration[5.0]
|
|
2
2
|
def self.up
|
|
3
3
|
add_column :rpush_notifications, :url_args, :text, null: true
|
|
4
4
|
add_column :rpush_notifications, :category, :string, null: true
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class Rpush270Updates < ActiveRecord::
|
|
1
|
+
class Rpush270Updates < ActiveRecord::Migration[5.0]
|
|
2
2
|
def self.up
|
|
3
3
|
change_column :rpush_notifications, :alert, :text
|
|
4
4
|
add_column :rpush_notifications, :notification, :text
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class Rpush300Updates < ActiveRecord::
|
|
1
|
+
class Rpush300Updates < ActiveRecord::Migration[5.0]
|
|
2
2
|
def self.up
|
|
3
3
|
add_column :rpush_notifications, :mutable_content, :boolean, default: false
|
|
4
4
|
change_column :rpush_notifications, :sound, :string, default: nil
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class Rpush301Updates < ActiveRecord::
|
|
1
|
+
class Rpush301Updates < ActiveRecord::Migration[5.0]
|
|
2
2
|
def self.up
|
|
3
3
|
change_column_null :rpush_notifications, :mutable_content, false
|
|
4
4
|
change_column_null :rpush_notifications, :content_available, false
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class Rpush311Updates < ActiveRecord::
|
|
1
|
+
class Rpush311Updates < ActiveRecord::Migration[5.0]
|
|
2
2
|
def self.up
|
|
3
3
|
change_table :rpush_notifications do |t|
|
|
4
4
|
t.remove_index name: 'index_rpush_notifications_multi'
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class Rpush320AddApnsP8 < ActiveRecord::
|
|
1
|
+
class Rpush320AddApnsP8 < ActiveRecord::Migration[5.0]
|
|
2
2
|
def self.up
|
|
3
3
|
add_column :rpush_apps, :apn_key, :string, null: true
|
|
4
4
|
add_column :rpush_apps, :apn_key_id, :string, null: true
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
class Rpush331Updates < ActiveRecord::
|
|
1
|
+
class Rpush331Updates < ActiveRecord::Migration[5.0]
|
|
2
2
|
def self.up
|
|
3
3
|
change_column :rpush_notifications, :device_token, :string, null: true
|
|
4
4
|
change_column :rpush_feedback, :device_token, :string, null: true
|
|
5
5
|
end
|
|
6
6
|
|
|
7
7
|
def self.down
|
|
8
|
-
change_column :rpush_notifications, :device_token, :string,
|
|
9
|
-
change_column :rpush_feedback, :device_token, :string,
|
|
8
|
+
change_column :rpush_notifications, :device_token, :string, null: true, limit: 64
|
|
9
|
+
change_column :rpush_feedback, :device_token, :string, null: true, limit: 64
|
|
10
10
|
end
|
|
11
11
|
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class Rpush410Updates < ActiveRecord::
|
|
1
|
+
class Rpush410Updates < ActiveRecord::Migration["#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}"]
|
|
2
2
|
def self.up
|
|
3
3
|
add_column :rpush_notifications, :dry_run, :boolean, null: false, default: false
|
|
4
4
|
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class Rpush411Updates < ActiveRecord::
|
|
1
|
+
class Rpush411Updates < ActiveRecord::Migration["#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}"]
|
|
2
2
|
def self.up
|
|
3
3
|
add_column :rpush_apps, :feedback_enabled, :boolean, default: true
|
|
4
4
|
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class Rpush420Updates < ActiveRecord::
|
|
1
|
+
class Rpush420Updates < ActiveRecord::Migration["#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}"]
|
|
2
2
|
def self.up
|
|
3
3
|
add_column :rpush_notifications, :sound_is_json, :boolean, null: true, default: false
|
|
4
4
|
end
|
data/lib/rpush/cli.rb
CHANGED
|
@@ -14,7 +14,7 @@ module Rpush
|
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
class_option :config, type: :string, aliases: '-c', default: default_config_path
|
|
17
|
-
class_option 'rails-env', type: :string, aliases: '-e', default: 'development'
|
|
17
|
+
class_option 'rails-env', type: :string, aliases: '-e', default: ENV.fetch('RAILS_ENV', 'development')
|
|
18
18
|
|
|
19
19
|
option :foreground, type: :boolean, aliases: '-f', default: false
|
|
20
20
|
option 'pid-file', type: :string, aliases: '-p'
|
|
@@ -3,11 +3,12 @@ require 'active_model'
|
|
|
3
3
|
require 'rpush/client/active_model/notification'
|
|
4
4
|
require 'rpush/client/active_model/payload_data_size_validator'
|
|
5
5
|
require 'rpush/client/active_model/registration_ids_count_validator'
|
|
6
|
+
require 'rpush/client/active_model/certificate_private_key_validator'
|
|
6
7
|
|
|
7
|
-
require 'rpush/client/active_model/apns/binary_notification_validator'
|
|
8
8
|
require 'rpush/client/active_model/apns/device_token_format_validator'
|
|
9
9
|
require 'rpush/client/active_model/apns/app'
|
|
10
10
|
require 'rpush/client/active_model/apns/notification'
|
|
11
|
+
require 'rpush/client/active_model/apns/notification_payload_size_validator'
|
|
11
12
|
|
|
12
13
|
require 'rpush/client/active_model/apns2/app'
|
|
13
14
|
require 'rpush/client/active_model/apns2/notification'
|
|
@@ -32,3 +33,6 @@ require 'rpush/client/active_model/wns/notification'
|
|
|
32
33
|
require 'rpush/client/active_model/pushy/app'
|
|
33
34
|
require 'rpush/client/active_model/pushy/notification'
|
|
34
35
|
require 'rpush/client/active_model/pushy/time_to_live_validator'
|
|
36
|
+
|
|
37
|
+
require 'rpush/client/active_model/webpush/app'
|
|
38
|
+
require 'rpush/client/active_model/webpush/notification'
|
|
@@ -5,7 +5,7 @@ module Rpush
|
|
|
5
5
|
class DataValidator < ::ActiveModel::Validator
|
|
6
6
|
def validate(record)
|
|
7
7
|
return unless record.collapse_key.nil? && record.data.nil?
|
|
8
|
-
record.errors
|
|
8
|
+
record.errors.add :data, 'must be set unless collapse_key is specified'
|
|
9
9
|
end
|
|
10
10
|
end
|
|
11
11
|
end
|
|
@@ -7,29 +7,13 @@ module Rpush
|
|
|
7
7
|
base.instance_eval do
|
|
8
8
|
validates :environment, presence: true, inclusion: { in: %w(development production sandbox) }
|
|
9
9
|
validates :certificate, presence: true
|
|
10
|
-
|
|
10
|
+
validates_with Rpush::Client::ActiveModel::CertificatePrivateKeyValidator
|
|
11
11
|
end
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def service_name
|
|
15
15
|
'apns'
|
|
16
16
|
end
|
|
17
|
-
|
|
18
|
-
private
|
|
19
|
-
|
|
20
|
-
def certificate_has_matching_private_key
|
|
21
|
-
result = false
|
|
22
|
-
if certificate.present?
|
|
23
|
-
begin
|
|
24
|
-
x509 = OpenSSL::X509::Certificate.new(certificate)
|
|
25
|
-
pkey = OpenSSL::PKey::RSA.new(certificate, password)
|
|
26
|
-
result = x509 && pkey
|
|
27
|
-
rescue OpenSSL::OpenSSLError
|
|
28
|
-
errors.add :certificate, 'value must contain a certificate and a private key.'
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
result
|
|
32
|
-
end
|
|
33
17
|
end
|
|
34
18
|
end
|
|
35
19
|
end
|
|
@@ -4,8 +4,8 @@ module Rpush
|
|
|
4
4
|
module Apns
|
|
5
5
|
class DeviceTokenFormatValidator < ::ActiveModel::Validator
|
|
6
6
|
def validate(record)
|
|
7
|
-
return if record.device_token =~
|
|
8
|
-
record.errors
|
|
7
|
+
return if record.device_token =~ /\A[a-z0-9]\w+\z/i
|
|
8
|
+
record.errors.add :device_token, "is invalid"
|
|
9
9
|
end
|
|
10
10
|
end
|
|
11
11
|
end
|
|
@@ -7,15 +7,23 @@ module Rpush
|
|
|
7
7
|
APNS_PRIORITY_IMMEDIATE = 10
|
|
8
8
|
APNS_PRIORITY_CONSERVE_POWER = 5
|
|
9
9
|
APNS_PRIORITIES = [APNS_PRIORITY_IMMEDIATE, APNS_PRIORITY_CONSERVE_POWER]
|
|
10
|
+
MAX_PAYLOAD_BYTESIZE = 2048
|
|
11
|
+
|
|
12
|
+
module ClassMethods
|
|
13
|
+
def max_payload_bytesize
|
|
14
|
+
MAX_PAYLOAD_BYTESIZE
|
|
15
|
+
end
|
|
16
|
+
end
|
|
10
17
|
|
|
11
18
|
def self.included(base)
|
|
19
|
+
base.extend ClassMethods
|
|
12
20
|
base.instance_eval do
|
|
13
21
|
validates :device_token, presence: true
|
|
14
22
|
validates :badge, numericality: true, allow_nil: true
|
|
15
23
|
validates :priority, inclusion: { in: APNS_PRIORITIES }, allow_nil: true
|
|
16
24
|
|
|
17
25
|
validates_with Rpush::Client::ActiveModel::Apns::DeviceTokenFormatValidator
|
|
18
|
-
validates_with Rpush::Client::ActiveModel::Apns::
|
|
26
|
+
validates_with Rpush::Client::ActiveModel::Apns::NotificationPayloadSizeValidator
|
|
19
27
|
|
|
20
28
|
base.const_set('APNS_DEFAULT_EXPIRY', APNS_DEFAULT_EXPIRY) unless base.const_defined?('APNS_DEFAULT_EXPIRY')
|
|
21
29
|
base.const_set('APNS_PRIORITY_IMMEDIATE', APNS_PRIORITY_IMMEDIATE) unless base.const_defined?('APNS_PRIORITY_IMMEDIATE')
|
|
@@ -44,6 +52,10 @@ module Rpush
|
|
|
44
52
|
self.data = (data || {}).merge(CONTENT_AVAILABLE_KEY => true)
|
|
45
53
|
end
|
|
46
54
|
|
|
55
|
+
def content_available?
|
|
56
|
+
(self.data || {})[CONTENT_AVAILABLE_KEY]
|
|
57
|
+
end
|
|
58
|
+
|
|
47
59
|
def as_json(options = nil) # rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity
|
|
48
60
|
json = ActiveSupport::OrderedHash.new
|
|
49
61
|
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module Rpush
|
|
2
|
+
module Client
|
|
3
|
+
module ActiveModel
|
|
4
|
+
module Apns
|
|
5
|
+
class NotificationPayloadSizeValidator < ::ActiveModel::Validator
|
|
6
|
+
def validate(record)
|
|
7
|
+
limit = record.class.max_payload_bytesize
|
|
8
|
+
return unless record.payload.bytesize > limit
|
|
9
|
+
record.errors.add :base, "APN notification cannot be larger than #{limit} bytes. Try condensing your alert and device attributes."
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -3,7 +3,13 @@ module Rpush
|
|
|
3
3
|
module ActiveModel
|
|
4
4
|
module Apns2
|
|
5
5
|
module App
|
|
6
|
-
|
|
6
|
+
def self.included(base)
|
|
7
|
+
base.instance_eval do
|
|
8
|
+
validates :environment, presence: true, inclusion: { in: %w(development production sandbox) }
|
|
9
|
+
validates :certificate, presence: true
|
|
10
|
+
validates_with Rpush::Client::ActiveModel::CertificatePrivateKeyValidator
|
|
11
|
+
end
|
|
12
|
+
end
|
|
7
13
|
|
|
8
14
|
def service_name
|
|
9
15
|
'apns2'
|
|
@@ -3,6 +3,20 @@ module Rpush
|
|
|
3
3
|
module ActiveModel
|
|
4
4
|
module Apns2
|
|
5
5
|
include Rpush::Client::ActiveModel::Apns
|
|
6
|
+
|
|
7
|
+
module Notification
|
|
8
|
+
MAX_PAYLOAD_BYTESIZE = 4096
|
|
9
|
+
|
|
10
|
+
module ClassMethods
|
|
11
|
+
def max_payload_bytesize
|
|
12
|
+
MAX_PAYLOAD_BYTESIZE
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.included(base)
|
|
17
|
+
base.extend ClassMethods
|
|
18
|
+
end
|
|
19
|
+
end
|
|
6
20
|
end
|
|
7
21
|
end
|
|
8
22
|
end
|