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.
Files changed (150) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +74 -2
  3. data/README.md +104 -18
  4. data/lib/generators/templates/add_adm.rb +1 -1
  5. data/lib/generators/templates/add_alert_is_json_to_rapns_notifications.rb +2 -2
  6. data/lib/generators/templates/add_app_to_rapns.rb +2 -2
  7. data/lib/generators/templates/add_fail_after_to_rpush_notifications.rb +1 -1
  8. data/lib/generators/templates/add_gcm.rb +11 -25
  9. data/lib/generators/templates/add_rpush.rb +33 -83
  10. data/lib/generators/templates/add_wpns.rb +1 -1
  11. data/lib/generators/templates/create_rapns_apps.rb +1 -1
  12. data/lib/generators/templates/create_rapns_feedback.rb +3 -9
  13. data/lib/generators/templates/create_rapns_notifications.rb +3 -9
  14. data/lib/generators/templates/rename_rapns_to_rpush.rb +9 -33
  15. data/lib/generators/templates/rpush.rb +4 -0
  16. data/lib/generators/templates/rpush_2_0_0_updates.rb +5 -17
  17. data/lib/generators/templates/rpush_2_1_0_updates.rb +1 -1
  18. data/lib/generators/templates/rpush_2_6_0_updates.rb +1 -1
  19. data/lib/generators/templates/rpush_2_7_0_updates.rb +1 -1
  20. data/lib/generators/templates/rpush_3_0_0_updates.rb +1 -1
  21. data/lib/generators/templates/rpush_3_0_1_updates.rb +1 -1
  22. data/lib/generators/templates/rpush_3_1_0_add_pushy.rb +1 -1
  23. data/lib/generators/templates/rpush_3_1_1_updates.rb +1 -1
  24. data/lib/generators/templates/rpush_3_2_0_add_apns_p8.rb +1 -1
  25. data/lib/generators/templates/rpush_3_2_4_updates.rb +1 -1
  26. data/lib/generators/templates/rpush_3_3_0_updates.rb +1 -1
  27. data/lib/generators/templates/rpush_3_3_1_updates.rb +3 -3
  28. data/lib/generators/templates/rpush_4_1_0_updates.rb +1 -1
  29. data/lib/generators/templates/rpush_4_1_1_updates.rb +1 -1
  30. data/lib/generators/templates/rpush_4_2_0_updates.rb +1 -1
  31. data/lib/rpush/cli.rb +1 -1
  32. data/lib/rpush/client/active_model.rb +5 -1
  33. data/lib/rpush/client/active_model/adm/data_validator.rb +1 -1
  34. data/lib/rpush/client/active_model/apns/app.rb +1 -17
  35. data/lib/rpush/client/active_model/apns/device_token_format_validator.rb +2 -2
  36. data/lib/rpush/client/active_model/apns/notification.rb +13 -1
  37. data/lib/rpush/client/active_model/apns/notification_payload_size_validator.rb +15 -0
  38. data/lib/rpush/client/active_model/apns2/app.rb +7 -1
  39. data/lib/rpush/client/active_model/apns2/notification.rb +14 -0
  40. data/lib/rpush/client/active_model/certificate_private_key_validator.rb +19 -0
  41. data/lib/rpush/client/active_model/gcm/expiry_collapse_key_mutual_inclusion_validator.rb +1 -1
  42. data/lib/rpush/client/active_model/payload_data_size_validator.rb +1 -1
  43. data/lib/rpush/client/active_model/registration_ids_count_validator.rb +1 -1
  44. data/lib/rpush/client/active_model/webpush/app.rb +41 -0
  45. data/lib/rpush/client/active_model/webpush/notification.rb +66 -0
  46. data/lib/rpush/client/active_record.rb +4 -0
  47. data/lib/rpush/client/active_record/apns/active_record_serializable_notification.rb +65 -0
  48. data/lib/rpush/client/active_record/apns/notification.rb +1 -57
  49. data/lib/rpush/client/active_record/apns2/notification.rb +4 -1
  50. data/lib/rpush/client/active_record/apnsp8/notification.rb +1 -0
  51. data/lib/rpush/client/active_record/webpush/app.rb +11 -0
  52. data/lib/rpush/client/active_record/webpush/notification.rb +12 -0
  53. data/lib/rpush/client/redis.rb +3 -0
  54. data/lib/rpush/client/redis/apns2/notification.rb +1 -0
  55. data/lib/rpush/client/redis/apnsp8/notification.rb +2 -0
  56. data/lib/rpush/client/redis/pushy/notification.rb +0 -1
  57. data/lib/rpush/client/redis/webpush/app.rb +15 -0
  58. data/lib/rpush/client/redis/webpush/notification.rb +15 -0
  59. data/lib/rpush/configuration.rb +3 -2
  60. data/lib/rpush/daemon.rb +4 -1
  61. data/lib/rpush/daemon/apns/feedback_receiver.rb +1 -1
  62. data/lib/rpush/daemon/apns2/delivery.rb +14 -2
  63. data/lib/rpush/daemon/apnsp8/delivery.rb +14 -3
  64. data/lib/rpush/daemon/app_runner.rb +1 -1
  65. data/lib/rpush/daemon/batch.rb +12 -5
  66. data/lib/rpush/daemon/delivery.rb +1 -2
  67. data/lib/rpush/daemon/store/active_record/reconnectable.rb +1 -1
  68. data/lib/rpush/daemon/string_helpers.rb +1 -1
  69. data/lib/rpush/daemon/webpush.rb +10 -0
  70. data/lib/rpush/daemon/webpush/delivery.rb +114 -0
  71. data/lib/rpush/logger.rb +1 -0
  72. data/lib/rpush/version.rb +1 -1
  73. data/spec/functional/apns2_spec.rb +99 -2
  74. data/spec/functional/retry_spec.rb +1 -1
  75. data/spec/functional/webpush_spec.rb +30 -0
  76. data/spec/spec_helper.rb +3 -1
  77. data/spec/support/active_record_setup.rb +4 -3
  78. data/spec/support/config/database.yml +4 -4
  79. data/spec/support/simplecov_helper.rb +2 -2
  80. data/spec/unit/client/active_record/adm/app_spec.rb +2 -54
  81. data/spec/unit/client/active_record/adm/notification_spec.rb +2 -39
  82. data/spec/unit/client/active_record/apns/app_spec.rb +3 -26
  83. data/spec/unit/client/active_record/apns/feedback_spec.rb +1 -5
  84. data/spec/unit/client/active_record/apns/notification_spec.rb +29 -293
  85. data/spec/unit/client/active_record/apns2/app_spec.rb +5 -0
  86. data/spec/unit/client/active_record/apns2/notification_spec.rb +65 -0
  87. data/spec/unit/client/active_record/apnsp8/notification_spec.rb +28 -0
  88. data/spec/unit/client/active_record/app_spec.rb +1 -26
  89. data/spec/unit/client/active_record/gcm/app_spec.rb +3 -1
  90. data/spec/unit/client/active_record/gcm/notification_spec.rb +6 -88
  91. data/spec/unit/client/active_record/notification_spec.rb +3 -11
  92. data/spec/unit/client/active_record/pushy/app_spec.rb +2 -13
  93. data/spec/unit/client/active_record/pushy/notification_spec.rb +2 -55
  94. data/spec/unit/client/active_record/shared/app.rb +14 -0
  95. data/spec/unit/{notification_shared.rb → client/active_record/shared/notification.rb} +12 -7
  96. data/spec/unit/client/active_record/webpush/app_spec.rb +6 -0
  97. data/spec/unit/client/active_record/webpush/notification_spec.rb +6 -0
  98. data/spec/unit/client/active_record/wns/badge_notification_spec.rb +1 -11
  99. data/spec/unit/client/active_record/wns/raw_notification_spec.rb +3 -12
  100. data/spec/unit/client/active_record/wpns/app_spec.rb +3 -1
  101. data/spec/unit/client/active_record/wpns/notification_spec.rb +2 -17
  102. data/spec/unit/client/redis/adm/app_spec.rb +5 -0
  103. data/spec/unit/client/redis/adm/notification_spec.rb +5 -0
  104. data/spec/unit/client/redis/apns/app_spec.rb +5 -0
  105. data/spec/unit/client/redis/apns/feedback_spec.rb +5 -0
  106. data/spec/unit/client/redis/apns/notification_spec.rb +50 -0
  107. data/spec/unit/client/redis/apns2/app_spec.rb +4 -0
  108. data/spec/unit/client/redis/apns2/notification_spec.rb +50 -0
  109. data/spec/unit/client/redis/apnsp8/notification_spec.rb +29 -0
  110. data/spec/unit/client/redis/app_spec.rb +5 -0
  111. data/spec/unit/client/redis/gcm/app_spec.rb +5 -0
  112. data/spec/unit/client/redis/gcm/notification_spec.rb +5 -0
  113. data/spec/unit/client/redis/notification_spec.rb +5 -0
  114. data/spec/unit/client/redis/pushy/app_spec.rb +5 -0
  115. data/spec/unit/client/redis/pushy/notification_spec.rb +5 -0
  116. data/spec/unit/client/redis/webpush/app_spec.rb +5 -0
  117. data/spec/unit/client/redis/webpush/notification_spec.rb +5 -0
  118. data/spec/unit/client/redis/wns/badge_notification_spec.rb +5 -0
  119. data/spec/unit/client/redis/wns/raw_notification_spec.rb +22 -0
  120. data/spec/unit/client/redis/wpns/app_spec.rb +5 -0
  121. data/spec/unit/client/redis/wpns/notification_spec.rb +5 -0
  122. data/spec/unit/client/shared/adm/app.rb +51 -0
  123. data/spec/unit/client/shared/adm/notification.rb +39 -0
  124. data/spec/unit/client/shared/apns/app.rb +29 -0
  125. data/spec/unit/client/shared/apns/feedback.rb +9 -0
  126. data/spec/unit/client/shared/apns/notification.rb +277 -0
  127. data/spec/unit/client/shared/app.rb +17 -0
  128. data/spec/unit/client/shared/gcm/app.rb +4 -0
  129. data/spec/unit/client/shared/gcm/notification.rb +77 -0
  130. data/spec/unit/client/shared/notification.rb +10 -0
  131. data/spec/unit/client/shared/pushy/app.rb +17 -0
  132. data/spec/unit/client/shared/pushy/notification.rb +55 -0
  133. data/spec/unit/client/shared/webpush/app.rb +33 -0
  134. data/spec/unit/client/shared/webpush/notification.rb +83 -0
  135. data/spec/unit/client/shared/wns/badge_notification.rb +15 -0
  136. data/spec/unit/client/shared/wns/raw_notification.rb +21 -0
  137. data/spec/unit/client/shared/wpns/app.rb +4 -0
  138. data/spec/unit/client/shared/wpns/notification.rb +18 -0
  139. data/spec/unit/daemon/apnsp8/delivery_spec.rb +53 -0
  140. data/spec/unit/daemon/batch_spec.rb +50 -2
  141. data/spec/unit/daemon/delivery_spec.rb +10 -0
  142. data/spec/unit/daemon/pushy/delivery_spec.rb +5 -3
  143. data/spec/unit/daemon/shared/store.rb +312 -0
  144. data/spec/unit/daemon/store/active_record/reconnectable_spec.rb +7 -7
  145. data/spec/unit/daemon/store/active_record_spec.rb +2 -290
  146. data/spec/unit/daemon/store/redis_spec.rb +2 -291
  147. data/spec/unit/daemon/webpush/delivery_spec.rb +144 -0
  148. data/spec/unit_spec_helper.rb +3 -0
  149. metadata +137 -13
  150. data/lib/rpush/client/active_model/apns/binary_notification_validator.rb +0 -16
@@ -1,4 +1,4 @@
1
- class AddWpns < ActiveRecord::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[5.0] : ActiveRecord::Migration
1
+ class AddWpns < ActiveRecord::Migration[5.0]
2
2
  module Rapns
3
3
  class Notification < ActiveRecord::Base
4
4
  self.table_name = 'rapns_notifications'
@@ -1,4 +1,4 @@
1
- class CreateRapnsApps < ActiveRecord::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[5.0] : ActiveRecord::Migration
1
+ class CreateRapnsApps < ActiveRecord::Migration[5.0]
2
2
  def self.up
3
3
  create_table :rapns_apps do |t|
4
4
  t.string :key, null: false
@@ -1,4 +1,4 @@
1
- class CreateRapnsFeedback < ActiveRecord::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[5.0] : ActiveRecord::Migration
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 ActiveRecord.version >= Gem::Version.new('5.1')
14
- if index_name_exists?(:rapns_feedback, :index_rapns_feedback_on_device_token)
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::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[5.0] : ActiveRecord::Migration
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 ActiveRecord.version >= Gem::Version.new('5.1')
25
- if index_name_exists?(:rapns_notifications, 'index_rapns_notifications_multi')
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::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[5.0] : ActiveRecord::Migration
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 ActiveRecord.version >= Gem::Version.new('5.1')
22
- if index_name_exists?(:rpush_notifications, :index_rapns_notifications_multi)
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 ActiveRecord.version >= Gem::Version.new('5.1')
32
- if index_name_exists?(:rpush_feedback, :index_rapns_feedback_on_device_token)
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 ActiveRecord.version >= Gem::Version.new('5.1')
64
- if index_name_exists?(:rpush_notifications, :index_rpush_notifications_multi)
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 ActiveRecord.version >= Gem::Version.new('5.1')
74
- if index_name_exists?(:rpush_feedback, :index_rpush_feedback_on_device_token)
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::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[5.0] : ActiveRecord::Migration
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 ActiveRecord.version >= Gem::Version.new('5.1')
21
- if index_name_exists?(:rpush_notifications, :index_rpush_notifications_multi)
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 ActiveRecord.version >= Gem::Version.new('5.1')
56
- if index_name_exists?(:rpush_notifications, :index_rpush_notifications_multi)
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::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[5.0] : ActiveRecord::Migration
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 Rpush260Updates < ActiveRecord::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[5.0] : ActiveRecord::Migration
1
+ class Rpush260Updates < ActiveRecord::Migration[5.0]
2
2
  def self.up
3
3
  add_column :rpush_notifications, :content_available, :boolean, default: false
4
4
  end
@@ -1,4 +1,4 @@
1
- class Rpush270Updates < ActiveRecord::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[5.0] : ActiveRecord::Migration
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::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[5.0] : ActiveRecord::Migration
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::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[5.0] : ActiveRecord::Migration
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 Rpush310AddPushy < ActiveRecord::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[5.0] : ActiveRecord::Migration
1
+ class Rpush310AddPushy < ActiveRecord::Migration[5.0]
2
2
  def self.up
3
3
  add_column :rpush_notifications, :external_device_id, :string, null: true
4
4
  end
@@ -1,4 +1,4 @@
1
- class Rpush311Updates < ActiveRecord::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[5.0] : ActiveRecord::Migration
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::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[5.0] : ActiveRecord::Migration
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,4 +1,4 @@
1
- class Rpush324Updates < ActiveRecord::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[5.0] : ActiveRecord::Migration
1
+ class Rpush324Updates < ActiveRecord::Migration[5.0]
2
2
  def self.up
3
3
  change_column :rpush_apps, :apn_key, :text, null: true
4
4
  end
@@ -1,4 +1,4 @@
1
- class Rpush330Updates < ActiveRecord::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[5.0] : ActiveRecord::Migration
1
+ class Rpush330Updates < ActiveRecord::Migration[5.0]
2
2
  def self.up
3
3
  add_column :rpush_notifications, :thread_id, :string, null: true
4
4
  end
@@ -1,11 +1,11 @@
1
- class Rpush331Updates < ActiveRecord::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[5.0] : ActiveRecord::Migration
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, { null: true, limit: 64 }
9
- change_column :rpush_feedback, :device_token, :string, { null: true, limit: 64 }
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::VERSION::MAJOR >= 5 ? ActiveRecord::Migration["#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}"] : ActiveRecord::Migration
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::VERSION::MAJOR >= 5 ? ActiveRecord::Migration["#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}"] : ActiveRecord::Migration
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::VERSION::MAJOR >= 5 ? ActiveRecord::Migration["#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}"] : ActiveRecord::Migration
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[:data] << 'must be set unless collapse_key is specified'
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
- validate :certificate_has_matching_private_key
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 =~ /^[a-z0-9]\w+$/i
8
- record.errors[:device_token] << "is invalid"
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::BinaryNotificationValidator
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
- extend Rpush::Client::ActiveModel::Apns::App
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