rpush 1.0.0-java → 2.0.0-java

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 (201) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -0
  3. data/README.md +37 -22
  4. data/bin/rpush +13 -4
  5. data/lib/generators/rpush_generator.rb +2 -0
  6. data/lib/generators/templates/add_adm.rb +5 -5
  7. data/lib/generators/templates/add_alert_is_json_to_rapns_notifications.rb +1 -1
  8. data/lib/generators/templates/add_app_to_rapns.rb +2 -2
  9. data/lib/generators/templates/add_fail_after_to_rpush_notifications.rb +1 -1
  10. data/lib/generators/templates/add_gcm.rb +32 -32
  11. data/lib/generators/templates/add_rpush.rb +67 -67
  12. data/lib/generators/templates/add_wpns.rb +2 -2
  13. data/lib/generators/templates/create_rapns_apps.rb +5 -5
  14. data/lib/generators/templates/create_rapns_feedback.rb +2 -2
  15. data/lib/generators/templates/create_rapns_notifications.rb +15 -15
  16. data/lib/generators/templates/rpush.rb +28 -7
  17. data/lib/generators/templates/rpush_2_0_0_updates.rb +42 -0
  18. data/lib/rpush/client/active_model/adm/app.rb +23 -0
  19. data/lib/rpush/client/active_model/adm/data_validator.rb +14 -0
  20. data/lib/rpush/client/active_model/adm/notification.rb +28 -0
  21. data/lib/rpush/client/active_model/apns/app.rb +37 -0
  22. data/lib/rpush/client/active_model/apns/binary_notification_validator.rb +16 -0
  23. data/lib/rpush/client/active_model/apns/device_token_format_validator.rb +14 -0
  24. data/lib/rpush/client/active_model/apns/notification.rb +90 -0
  25. data/lib/rpush/client/active_model/gcm/app.rb +19 -0
  26. data/lib/rpush/client/active_model/gcm/expiry_collapse_key_mutual_inclusion_validator.rb +14 -0
  27. data/lib/rpush/client/active_model/gcm/notification.rb +31 -0
  28. data/lib/rpush/client/active_model/notification.rb +26 -0
  29. data/lib/rpush/client/active_model/payload_data_size_validator.rb +13 -0
  30. data/lib/rpush/client/active_model/registration_ids_count_validator.rb +13 -0
  31. data/lib/rpush/client/active_model/wpns/app.rb +13 -0
  32. data/lib/rpush/client/active_model/wpns/notification.rb +17 -0
  33. data/lib/rpush/client/active_model.rb +21 -0
  34. data/lib/rpush/client/active_record/adm/app.rb +11 -0
  35. data/lib/rpush/client/active_record/adm/notification.rb +11 -0
  36. data/lib/rpush/client/active_record/apns/app.rb +11 -0
  37. data/lib/rpush/client/active_record/apns/feedback.rb +22 -0
  38. data/lib/rpush/client/active_record/apns/notification.rb +46 -0
  39. data/lib/rpush/client/active_record/app.rb +17 -0
  40. data/lib/rpush/client/active_record/gcm/app.rb +11 -0
  41. data/lib/rpush/client/active_record/gcm/notification.rb +11 -0
  42. data/lib/rpush/client/active_record/notification.rb +38 -0
  43. data/lib/rpush/client/active_record/wpns/app.rb +11 -0
  44. data/lib/rpush/client/active_record/wpns/notification.rb +11 -0
  45. data/lib/rpush/client/active_record.rb +19 -0
  46. data/lib/rpush/client/redis/adm/app.rb +14 -0
  47. data/lib/rpush/client/redis/adm/notification.rb +11 -0
  48. data/lib/rpush/client/redis/apns/app.rb +11 -0
  49. data/lib/rpush/client/redis/apns/feedback.rb +20 -0
  50. data/lib/rpush/client/redis/apns/notification.rb +11 -0
  51. data/lib/rpush/client/redis/app.rb +24 -0
  52. data/lib/rpush/client/redis/gcm/app.rb +11 -0
  53. data/lib/rpush/client/redis/gcm/notification.rb +11 -0
  54. data/lib/rpush/client/redis/notification.rb +68 -0
  55. data/lib/rpush/client/redis/wpns/app.rb +11 -0
  56. data/lib/rpush/client/redis/wpns/notification.rb +11 -0
  57. data/lib/rpush/client/redis.rb +35 -0
  58. data/lib/rpush/configuration.rb +27 -6
  59. data/lib/rpush/daemon/adm/delivery.rb +56 -55
  60. data/lib/rpush/daemon/apns/delivery.rb +20 -44
  61. data/lib/rpush/daemon/apns/feedback_receiver.rb +11 -8
  62. data/lib/rpush/daemon/apns.rb +6 -5
  63. data/lib/rpush/daemon/app_runner.rb +103 -99
  64. data/lib/rpush/daemon/batch.rb +54 -40
  65. data/lib/rpush/daemon/delivery.rb +13 -3
  66. data/lib/rpush/daemon/delivery_error.rb +10 -2
  67. data/lib/rpush/daemon/dispatcher/apns_tcp.rb +114 -0
  68. data/lib/rpush/daemon/dispatcher/http.rb +3 -3
  69. data/lib/rpush/daemon/dispatcher/tcp.rb +3 -3
  70. data/lib/rpush/daemon/dispatcher_loop.rb +37 -23
  71. data/lib/rpush/daemon/errors.rb +18 -0
  72. data/lib/rpush/daemon/feeder.rb +28 -39
  73. data/lib/rpush/daemon/gcm/delivery.rb +19 -20
  74. data/lib/rpush/daemon/interruptible_sleep.rb +26 -45
  75. data/lib/rpush/daemon/loggable.rb +2 -4
  76. data/lib/rpush/daemon/proc_title.rb +16 -0
  77. data/lib/rpush/daemon/queue_payload.rb +12 -0
  78. data/lib/rpush/daemon/reflectable.rb +3 -5
  79. data/lib/rpush/daemon/retry_header_parser.rb +6 -6
  80. data/lib/rpush/daemon/retryable_error.rb +2 -0
  81. data/lib/rpush/daemon/ring_buffer.rb +16 -0
  82. data/lib/rpush/daemon/service_config_methods.rb +23 -7
  83. data/lib/rpush/daemon/signal_handler.rb +56 -0
  84. data/lib/rpush/daemon/store/active_record/reconnectable.rb +21 -17
  85. data/lib/rpush/daemon/store/active_record.rb +71 -38
  86. data/lib/rpush/daemon/store/interface.rb +19 -0
  87. data/lib/rpush/daemon/store/redis.rb +149 -0
  88. data/lib/rpush/daemon/string_helpers.rb +15 -0
  89. data/lib/rpush/daemon/synchronizer.rb +60 -0
  90. data/lib/rpush/daemon/tcp_connection.rb +6 -11
  91. data/lib/rpush/daemon/wpns/delivery.rb +21 -30
  92. data/lib/rpush/daemon.rb +40 -60
  93. data/lib/rpush/deprecatable.rb +4 -3
  94. data/lib/rpush/deprecation.rb +7 -10
  95. data/lib/rpush/embed.rb +8 -3
  96. data/lib/rpush/logger.rb +11 -15
  97. data/lib/rpush/push.rb +1 -2
  98. data/lib/rpush/reflection.rb +8 -12
  99. data/lib/rpush/version.rb +1 -1
  100. data/lib/rpush.rb +5 -29
  101. data/lib/tasks/quality.rake +35 -0
  102. data/lib/tasks/test.rake +1 -5
  103. data/spec/.rubocop.yml +4 -0
  104. data/spec/functional/adm_spec.rb +3 -6
  105. data/spec/functional/apns_spec.rb +117 -24
  106. data/spec/functional/embed_spec.rb +20 -20
  107. data/spec/functional/gcm_spec.rb +4 -7
  108. data/spec/functional/new_app_spec.rb +59 -0
  109. data/spec/functional/retry_spec.rb +46 -0
  110. data/spec/functional/synchronization_spec.rb +68 -0
  111. data/spec/functional/wpns_spec.rb +3 -6
  112. data/spec/functional_spec_helper.rb +26 -0
  113. data/spec/integration/rpush_spec.rb +13 -0
  114. data/spec/integration/support/gcm_success_response.json +1 -0
  115. data/spec/spec_helper.rb +60 -0
  116. data/spec/support/active_record_setup.rb +48 -0
  117. data/{config → spec/support/config}/database.yml +0 -0
  118. data/spec/support/install.sh +43 -7
  119. data/spec/support/simplecov_helper.rb +9 -5
  120. data/spec/support/simplecov_quality_formatter.rb +10 -6
  121. data/spec/unit/apns_feedback_spec.rb +3 -3
  122. data/spec/unit/{adm → client/active_record/adm}/app_spec.rb +3 -3
  123. data/spec/unit/{adm → client/active_record/adm}/notification_spec.rb +5 -7
  124. data/spec/unit/client/active_record/apns/app_spec.rb +29 -0
  125. data/spec/unit/client/active_record/apns/feedback_spec.rb +9 -0
  126. data/spec/unit/client/active_record/apns/notification_spec.rb +231 -0
  127. data/spec/unit/client/active_record/app_spec.rb +30 -0
  128. data/spec/unit/client/active_record/gcm/app_spec.rb +4 -0
  129. data/spec/unit/{gcm → client/active_record/gcm}/notification_spec.rb +5 -7
  130. data/spec/unit/client/active_record/notification_spec.rb +21 -0
  131. data/spec/unit/client/active_record/wpns/app_spec.rb +4 -0
  132. data/spec/unit/client/active_record/wpns/notification_spec.rb +21 -0
  133. data/spec/unit/configuration_spec.rb +12 -5
  134. data/spec/unit/daemon/adm/delivery_spec.rb +66 -55
  135. data/spec/unit/daemon/apns/certificate_expired_error_spec.rb +3 -3
  136. data/spec/unit/daemon/apns/delivery_spec.rb +90 -83
  137. data/spec/unit/daemon/apns/feedback_receiver_spec.rb +22 -17
  138. data/spec/unit/daemon/app_runner_spec.rb +78 -186
  139. data/spec/unit/daemon/batch_spec.rb +52 -115
  140. data/spec/unit/daemon/delivery_spec.rb +15 -1
  141. data/spec/unit/daemon/dispatcher/http_spec.rb +3 -2
  142. data/spec/unit/daemon/dispatcher/tcp_spec.rb +10 -9
  143. data/spec/unit/daemon/dispatcher_loop_spec.rb +6 -24
  144. data/spec/unit/daemon/feeder_spec.rb +38 -39
  145. data/spec/unit/daemon/gcm/delivery_spec.rb +122 -101
  146. data/spec/unit/daemon/reflectable_spec.rb +2 -2
  147. data/spec/unit/daemon/retryable_error_spec.rb +1 -1
  148. data/spec/unit/daemon/service_config_methods_spec.rb +6 -3
  149. data/spec/unit/daemon/signal_handler_spec.rb +95 -0
  150. data/spec/unit/daemon/store/active_record/reconnectable_spec.rb +48 -27
  151. data/spec/unit/daemon/store/active_record_spec.rb +38 -47
  152. data/spec/unit/daemon/tcp_connection_spec.rb +22 -34
  153. data/spec/unit/daemon/wpns/delivery_spec.rb +58 -50
  154. data/spec/unit/daemon_spec.rb +48 -82
  155. data/spec/unit/embed_spec.rb +6 -4
  156. data/spec/unit/logger_spec.rb +35 -43
  157. data/spec/unit/notification_shared.rb +9 -79
  158. data/spec/unit/push_spec.rb +6 -10
  159. data/spec/unit/reflection_spec.rb +25 -25
  160. data/spec/unit/rpush_spec.rb +1 -2
  161. data/spec/unit_spec_helper.rb +33 -88
  162. metadata +126 -76
  163. data/lib/rpush/TODO +0 -3
  164. data/lib/rpush/adm/app.rb +0 -15
  165. data/lib/rpush/adm/data_validator.rb +0 -11
  166. data/lib/rpush/adm/notification.rb +0 -29
  167. data/lib/rpush/apns/app.rb +0 -29
  168. data/lib/rpush/apns/binary_notification_validator.rb +0 -12
  169. data/lib/rpush/apns/device_token_format_validator.rb +0 -12
  170. data/lib/rpush/apns/feedback.rb +0 -16
  171. data/lib/rpush/apns/notification.rb +0 -84
  172. data/lib/rpush/app.rb +0 -18
  173. data/lib/rpush/daemon/apns/certificate_expired_error.rb +0 -20
  174. data/lib/rpush/daemon/apns/disconnection_error.rb +0 -20
  175. data/lib/rpush/daemon/dispatcher_loop_collection.rb +0 -33
  176. data/lib/rpush/daemon/too_many_requests_error.rb +0 -20
  177. data/lib/rpush/gcm/app.rb +0 -11
  178. data/lib/rpush/gcm/expiry_collapse_key_mutual_inclusion_validator.rb +0 -11
  179. data/lib/rpush/gcm/notification.rb +0 -30
  180. data/lib/rpush/notification.rb +0 -69
  181. data/lib/rpush/notifier.rb +0 -52
  182. data/lib/rpush/payload_data_size_validator.rb +0 -10
  183. data/lib/rpush/railtie.rb +0 -11
  184. data/lib/rpush/registration_ids_count_validator.rb +0 -10
  185. data/lib/rpush/wpns/app.rb +0 -9
  186. data/lib/rpush/wpns/notification.rb +0 -26
  187. data/lib/tasks/cane.rake +0 -18
  188. data/lib/tasks/rpush.rake +0 -16
  189. data/spec/unit/apns/app_spec.rb +0 -29
  190. data/spec/unit/apns/feedback_spec.rb +0 -9
  191. data/spec/unit/apns/notification_spec.rb +0 -208
  192. data/spec/unit/app_spec.rb +0 -30
  193. data/spec/unit/daemon/apns/disconnection_error_spec.rb +0 -18
  194. data/spec/unit/daemon/dispatcher_loop_collection_spec.rb +0 -37
  195. data/spec/unit/daemon/interruptible_sleep_spec.rb +0 -68
  196. data/spec/unit/daemon/too_many_requests_error_spec.rb +0 -14
  197. data/spec/unit/gcm/app_spec.rb +0 -4
  198. data/spec/unit/notification_spec.rb +0 -15
  199. data/spec/unit/notifier_spec.rb +0 -49
  200. data/spec/unit/wpns/app_spec.rb +0 -4
  201. data/spec/unit/wpns/notification_spec.rb +0 -30
@@ -0,0 +1,22 @@
1
+ module Rpush
2
+ module Client
3
+ module ActiveRecord
4
+ module Apns
5
+ class Feedback < ::ActiveRecord::Base
6
+ self.table_name = 'rpush_feedback'
7
+
8
+ if Rpush.attr_accessible_available?
9
+ attr_accessible :device_token, :failed_at, :app_id
10
+ end
11
+
12
+ belongs_to :app, class_name: 'Rpush::Client::ActiveRecord::App'
13
+
14
+ validates :device_token, presence: true
15
+ validates :failed_at, presence: true
16
+
17
+ validates_with Rpush::Client::ActiveModel::Apns::DeviceTokenFormatValidator
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,46 @@
1
+ module Rpush
2
+ module Client
3
+ module ActiveRecord
4
+ module Apns
5
+ class Notification < Rpush::Client::ActiveRecord::Notification
6
+ include Deprecatable
7
+ include Rpush::Client::ActiveModel::Apns::Notification
8
+
9
+ alias_method :attributes_for_device=, :data=
10
+ alias_method :attributes_for_device, :data
11
+
12
+ deprecated(:attributes_for_device, '2.1.0', 'Use :data instead.')
13
+ deprecated(:attributes_for_device=, '2.1.0', 'Use :data instead.')
14
+
15
+ def alert=(alert)
16
+ if alert.is_a?(Hash)
17
+ write_attribute(:alert, multi_json_dump(alert))
18
+ self.alert_is_json = true if has_attribute?(:alert_is_json)
19
+ else
20
+ write_attribute(:alert, alert)
21
+ self.alert_is_json = false if has_attribute?(:alert_is_json)
22
+ end
23
+ end
24
+
25
+ def alert
26
+ string_or_json = read_attribute(:alert)
27
+
28
+ if has_attribute?(:alert_is_json)
29
+ if alert_is_json?
30
+ multi_json_load(string_or_json)
31
+ else
32
+ string_or_json
33
+ end
34
+ else
35
+ begin
36
+ multi_json_load(string_or_json)
37
+ rescue StandardError
38
+ string_or_json
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,17 @@
1
+ module Rpush
2
+ module Client
3
+ module ActiveRecord
4
+ class App < ::ActiveRecord::Base
5
+ self.table_name = 'rpush_apps'
6
+
7
+ if Rpush.attr_accessible_available?
8
+ attr_accessible :name, :environment, :certificate, :password, :connections, :auth_key, :client_id, :client_secret
9
+ end
10
+
11
+ has_many :notifications, class_name: 'Rpush::Client::ActiveRecord::Notification', dependent: :destroy
12
+
13
+ validates :name, presence: true, uniqueness: { scope: [:type, :environment] }
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ module Rpush
2
+ module Client
3
+ module ActiveRecord
4
+ module Gcm
5
+ class App < Rpush::Client::ActiveRecord::App
6
+ include Rpush::Client::ActiveModel::Gcm::App
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Rpush
2
+ module Client
3
+ module ActiveRecord
4
+ module Gcm
5
+ class Notification < Rpush::Client::ActiveRecord::Notification
6
+ include Rpush::Client::ActiveModel::Gcm::Notification
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,38 @@
1
+ module Rpush
2
+ module Client
3
+ module ActiveRecord
4
+ class Notification < ::ActiveRecord::Base
5
+ include Rpush::MultiJsonHelper
6
+ include Rpush::Client::ActiveModel::Notification
7
+
8
+ self.table_name = 'rpush_notifications'
9
+
10
+ # TODO: Dump using multi json.
11
+ serialize :registration_ids
12
+
13
+ belongs_to :app, class_name: 'Rpush::Client::ActiveRecord::App'
14
+
15
+ if Rpush.attr_accessible_available?
16
+ attr_accessible :badge, :device_token, :sound, :alert, :data, :expiry, :delivered,
17
+ :delivered_at, :failed, :failed_at, :error_code, :error_description, :deliver_after,
18
+ :alert_is_json, :app, :app_id, :collapse_key, :delay_while_idle, :registration_ids, :uri
19
+ end
20
+
21
+ def data=(attrs)
22
+ return unless attrs
23
+ fail ArgumentError, "must be a Hash" unless attrs.is_a?(Hash)
24
+ write_attribute(:data, multi_json_dump(attrs.merge(data || {})))
25
+ end
26
+
27
+ def registration_ids=(ids)
28
+ ids = [ids] if ids && !ids.is_a?(Array)
29
+ super
30
+ end
31
+
32
+ def data
33
+ multi_json_load(read_attribute(:data)) if read_attribute(:data)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,11 @@
1
+ module Rpush
2
+ module Client
3
+ module ActiveRecord
4
+ module Wpns
5
+ class App < Rpush::Client::ActiveRecord::App
6
+ include Rpush::Client::ActiveModel::Wpns::App
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Rpush
2
+ module Client
3
+ module ActiveRecord
4
+ module Wpns
5
+ class Notification < Rpush::Client::ActiveRecord::Notification
6
+ include Rpush::Client::ActiveModel::Wpns::Notification
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,19 @@
1
+ require 'active_record'
2
+
3
+ require 'rpush/client/active_model'
4
+
5
+ require 'rpush/client/active_record/notification'
6
+ require 'rpush/client/active_record/app'
7
+
8
+ require 'rpush/client/active_record/apns/notification'
9
+ require 'rpush/client/active_record/apns/feedback'
10
+ require 'rpush/client/active_record/apns/app'
11
+
12
+ require 'rpush/client/active_record/gcm/notification'
13
+ require 'rpush/client/active_record/gcm/app'
14
+
15
+ require 'rpush/client/active_record/wpns/notification'
16
+ require 'rpush/client/active_record/wpns/app'
17
+
18
+ require 'rpush/client/active_record/adm/notification'
19
+ require 'rpush/client/active_record/adm/app'
@@ -0,0 +1,14 @@
1
+ module Rpush
2
+ module Client
3
+ module Redis
4
+ module Adm
5
+ class App < Rpush::Client::Redis::App
6
+ include Rpush::Client::ActiveModel::Adm::App
7
+
8
+ attribute :access_token, :string
9
+ attribute :access_token_expiration, :timestamp
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ module Rpush
2
+ module Client
3
+ module Redis
4
+ module Adm
5
+ class Notification < Rpush::Client::Redis::Notification
6
+ include Rpush::Client::ActiveModel::Adm::Notification
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Rpush
2
+ module Client
3
+ module Redis
4
+ module Apns
5
+ class App < Rpush::Client::Redis::App
6
+ include Rpush::Client::ActiveModel::Apns::App
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,20 @@
1
+ module Rpush
2
+ module Client
3
+ module Redis
4
+ module Apns
5
+ class Feedback
6
+ include Modis::Model
7
+
8
+ attribute :app_id, :integer
9
+ attribute :device_token, :string
10
+ attribute :failed_at, :timestamp
11
+
12
+ validates :device_token, presence: true
13
+ validates :failed_at, presence: true
14
+
15
+ validates_with Rpush::Client::ActiveModel::Apns::DeviceTokenFormatValidator
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,11 @@
1
+ module Rpush
2
+ module Client
3
+ module Redis
4
+ module Apns
5
+ class Notification < Rpush::Client::Redis::Notification
6
+ include Rpush::Client::ActiveModel::Apns::Notification
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,24 @@
1
+ module Rpush
2
+ module Client
3
+ module Redis
4
+ class App
5
+ include Modis::Model
6
+ self.namespace = 'apps'
7
+
8
+ attribute :name, :string
9
+ attribute :environment, :string
10
+ attribute :certificate, :string
11
+ attribute :password, :string
12
+ attribute :connections, :integer, default: 1
13
+ attribute :auth_key, :string
14
+ attribute :client_id, :string
15
+ attribute :client_secret, :string
16
+
17
+ index :name
18
+
19
+ validates :name, presence: true
20
+ validates_numericality_of :connections, greater_than: 0, only_integer: true
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,11 @@
1
+ module Rpush
2
+ module Client
3
+ module Redis
4
+ module Gcm
5
+ class App < Rpush::Client::Redis::App
6
+ include Rpush::Client::ActiveModel::Gcm::App
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Rpush
2
+ module Client
3
+ module Redis
4
+ module Gcm
5
+ class Notification < Rpush::Client::Redis::Notification
6
+ include Rpush::Client::ActiveModel::Gcm::Notification
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,68 @@
1
+ module Rpush
2
+ module Client
3
+ module Redis
4
+ class Notification
5
+ include Rpush::MultiJsonHelper
6
+ include Modis::Model
7
+ include Rpush::Client::ActiveModel::Notification
8
+
9
+ after_create :register_notification
10
+
11
+ self.namespace = 'notifications'
12
+
13
+ def self.absolute_pending_namespace
14
+ "#{absolute_namespace}:pending"
15
+ end
16
+
17
+ def self.absolute_retryable_namespace
18
+ "#{absolute_namespace}:retryable"
19
+ end
20
+
21
+ attribute :badge, :integer
22
+ attribute :device_token, :string
23
+ attribute :sound, :string, default: 'default'
24
+ attribute :alert, [:string, :hash], strict: false
25
+ attribute :data, :hash
26
+ attribute :expiry, :integer, default: 1.day.to_i
27
+ attribute :delivered, :boolean
28
+ attribute :delivered_at, :timestamp
29
+ attribute :failed, :boolean
30
+ attribute :failed_at, :timestamp
31
+ attribute :fail_after, :timestamp
32
+ attribute :retries, :integer, default: 0
33
+ attribute :error_code, :integer
34
+ attribute :error_description, :string
35
+ attribute :deliver_after, :timestamp
36
+ attribute :alert_is_json, :boolean
37
+ attribute :app_id, :integer
38
+ attribute :collapse_key, :string
39
+ attribute :delay_while_idle, :boolean
40
+ attribute :registration_ids, :array
41
+ attribute :uri, :string
42
+ attribute :priority, :integer
43
+
44
+ def app
45
+ return nil unless app_id
46
+ @app ||= Rpush::Client::Redis::App.find(app_id)
47
+ end
48
+
49
+ def app=(app)
50
+ @app = app
51
+ if app
52
+ self.app_id = app.id
53
+ else
54
+ self.app_id = nil
55
+ end
56
+ end
57
+
58
+ private
59
+
60
+ def register_notification
61
+ Modis.with_connection do |redis|
62
+ redis.zadd(self.class.absolute_pending_namespace, id, id)
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,11 @@
1
+ module Rpush
2
+ module Client
3
+ module Redis
4
+ module Wpns
5
+ class App < Rpush::Client::Redis::App
6
+ include Rpush::Client::ActiveModel::Wpns::App
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Rpush
2
+ module Client
3
+ module Redis
4
+ module Wpns
5
+ class Notification < Rpush::Client::Redis::Notification
6
+ include Rpush::Client::ActiveModel::Wpns::Notification
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,35 @@
1
+ # :nocov:
2
+ begin
3
+ require 'modis'
4
+ rescue LoadError
5
+ puts
6
+ str = "* Please add 'rpush-redis' to your Gemfile to use the Redis client. *"
7
+ puts "*" * str.size
8
+ puts str
9
+ puts "*" * str.size
10
+ puts
11
+ end
12
+
13
+ require 'redis'
14
+
15
+ require 'rpush/client/active_model'
16
+
17
+ require 'rpush/client/redis/app'
18
+ require 'rpush/client/redis/notification'
19
+
20
+ require 'rpush/client/redis/apns/app'
21
+ require 'rpush/client/redis/apns/notification'
22
+ require 'rpush/client/redis/apns/feedback'
23
+
24
+ require 'rpush/client/redis/gcm/app'
25
+ require 'rpush/client/redis/gcm/notification'
26
+
27
+ require 'rpush/client/redis/adm/app'
28
+ require 'rpush/client/redis/adm/notification'
29
+
30
+ require 'rpush/client/redis/wpns/app'
31
+ require 'rpush/client/redis/wpns/notification'
32
+
33
+ Modis.configure do |config|
34
+ config.namespace = :rpush
35
+ end
@@ -4,12 +4,28 @@ module Rpush
4
4
  end
5
5
 
6
6
  def self.configure
7
- yield config if block_given?
7
+ if block_given?
8
+ yield config
9
+ initialize_client
10
+ end
11
+ end
12
+
13
+ def self.initialize_client
14
+ return if @client_initialized
15
+ require "rpush/client/#{config.client}"
16
+ client_module = Rpush::Client.const_get(config.client.to_s.camelize)
17
+ Rpush.send(:include, client_module)
18
+
19
+ [:Apns, :Gcm, :Wpns, :Adm].each do |service|
20
+ Rpush.const_set(service, client_module.const_get(service))
21
+ end
22
+
23
+ @client_initialized = true
8
24
  end
9
25
 
10
26
  CONFIG_ATTRS = [:foreground, :push_poll, :feedback_poll, :embedded,
11
- :check_for_errors, :pid_file, :batch_size, :push, :store, :logger,
12
- :batch_storage_updates, :wakeup]
27
+ :check_for_errors, :pid_file, :batch_size, :push, :client, :logger,
28
+ :batch_storage_updates, :log_dir, :environment]
13
29
 
14
30
  class ConfigurationWithoutDefaults < Struct.new(*CONFIG_ATTRS)
15
31
  end
@@ -17,6 +33,11 @@ module Rpush
17
33
  class Configuration < Struct.new(*CONFIG_ATTRS)
18
34
  include Deprecatable
19
35
 
36
+ deprecated(:batch_storage_updates=, '2.1.0', 'Updates are now always batched by the storage backends.')
37
+ deprecated(:check_for_errors=, '2.1.0', 'APNs error detection is now performed asynchronously and does not require pauses.')
38
+
39
+ delegate :redis_options, :redis_options=, to: :Modis
40
+
20
41
  def initialize
21
42
  super
22
43
  set_defaults
@@ -60,16 +81,16 @@ module Rpush
60
81
 
61
82
  self.push_poll = 2
62
83
  self.feedback_poll = 60
63
- self.check_for_errors = true
64
84
  self.batch_size = 100
65
85
  self.pid_file = nil
66
- self.store = :active_record
86
+ self.client = :active_record
67
87
  self.logger = nil
68
- self.batch_storage_updates = true
88
+ self.log_dir = Rails.root
69
89
 
70
90
  # Internal options.
71
91
  self.embedded = false
72
92
  self.push = false
93
+ self.environment = Rails.env
73
94
  end
74
95
  end
75
96
  end