rpush 4.1.0 → 5.2.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 (113) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +254 -162
  3. data/README.md +57 -16
  4. data/lib/generators/rpush_migration_generator.rb +2 -0
  5. data/lib/generators/templates/rpush.rb +4 -0
  6. data/lib/generators/templates/rpush_4_1_1_updates.rb +9 -0
  7. data/lib/generators/templates/rpush_4_2_0_updates.rb +10 -0
  8. data/lib/rpush/apns_feedback.rb +1 -0
  9. data/lib/rpush/cli.rb +9 -22
  10. data/lib/rpush/client/active_model.rb +1 -1
  11. data/lib/rpush/client/active_model/apns/notification.rb +9 -1
  12. data/lib/rpush/client/active_model/apns/notification_payload_size_validator.rb +15 -0
  13. data/lib/rpush/client/active_model/apns2/notification.rb +14 -0
  14. data/lib/rpush/client/active_model/gcm/notification.rb +4 -3
  15. data/lib/rpush/client/active_model/wns/notification.rb +8 -0
  16. data/lib/rpush/client/active_record.rb +1 -0
  17. data/lib/rpush/client/active_record/apns/active_record_serializable_notification.rb +65 -0
  18. data/lib/rpush/client/active_record/apns/notification.rb +1 -29
  19. data/lib/rpush/client/active_record/apns2/notification.rb +4 -1
  20. data/lib/rpush/client/active_record/app.rb +1 -1
  21. data/lib/rpush/client/active_record/notification.rb +1 -1
  22. data/lib/rpush/client/redis/apns2/notification.rb +1 -0
  23. data/lib/rpush/client/redis/app.rb +2 -1
  24. data/lib/rpush/client/redis/notification.rb +2 -1
  25. data/lib/rpush/client/redis/pushy/notification.rb +0 -1
  26. data/lib/rpush/configuration.rb +2 -1
  27. data/lib/rpush/daemon.rb +2 -2
  28. data/lib/rpush/daemon/apns/feedback_receiver.rb +2 -1
  29. data/lib/rpush/daemon/apns2/delivery.rb +6 -1
  30. data/lib/rpush/daemon/apnsp8/delivery.rb +7 -2
  31. data/lib/rpush/daemon/app_runner.rb +1 -1
  32. data/lib/rpush/daemon/batch.rb +12 -5
  33. data/lib/rpush/daemon/delivery.rb +1 -2
  34. data/lib/rpush/daemon/dispatcher/apns_http2.rb +4 -2
  35. data/lib/rpush/daemon/dispatcher/apnsp8_http2.rb +2 -1
  36. data/lib/rpush/daemon/signal_handler.rb +1 -1
  37. data/lib/rpush/daemon/store/active_record.rb +1 -1
  38. data/lib/rpush/daemon/store/active_record/reconnectable.rb +1 -1
  39. data/lib/rpush/daemon/store/redis.rb +1 -1
  40. data/lib/rpush/daemon/wns/badge_request.rb +8 -3
  41. data/lib/rpush/daemon/wns/raw_request.rb +9 -2
  42. data/lib/rpush/daemon/wns/toast_request.rb +6 -2
  43. data/lib/rpush/logger.rb +1 -0
  44. data/lib/rpush/version.rb +2 -2
  45. data/spec/.rubocop.yml +1 -1
  46. data/spec/functional/apns2_spec.rb +85 -0
  47. data/spec/functional/gcm_priority_spec.rb +40 -0
  48. data/spec/support/active_record_setup.rb +5 -1
  49. data/spec/support/simplecov_helper.rb +1 -1
  50. data/spec/unit/apns_feedback_spec.rb +17 -6
  51. data/spec/unit/client/active_record/adm/app_spec.rb +2 -54
  52. data/spec/unit/client/active_record/adm/notification_spec.rb +2 -39
  53. data/spec/unit/client/active_record/apns/app_spec.rb +3 -26
  54. data/spec/unit/client/active_record/apns/feedback_spec.rb +1 -5
  55. data/spec/unit/client/active_record/apns/notification_spec.rb +29 -288
  56. data/spec/unit/client/active_record/apns2/app_spec.rb +4 -0
  57. data/spec/unit/client/active_record/apns2/notification_spec.rb +65 -0
  58. data/spec/unit/client/active_record/app_spec.rb +1 -26
  59. data/spec/unit/client/active_record/gcm/app_spec.rb +3 -1
  60. data/spec/unit/client/active_record/gcm/notification_spec.rb +6 -83
  61. data/spec/unit/client/active_record/notification_spec.rb +10 -11
  62. data/spec/unit/client/active_record/pushy/app_spec.rb +2 -13
  63. data/spec/unit/client/active_record/pushy/notification_spec.rb +2 -55
  64. data/spec/unit/client/active_record/shared/app.rb +14 -0
  65. data/spec/unit/{notification_shared.rb → client/active_record/shared/notification.rb} +12 -7
  66. data/spec/unit/client/active_record/wns/badge_notification_spec.rb +1 -11
  67. data/spec/unit/client/active_record/wns/raw_notification_spec.rb +3 -12
  68. data/spec/unit/client/active_record/wpns/app_spec.rb +3 -1
  69. data/spec/unit/client/active_record/wpns/notification_spec.rb +2 -17
  70. data/spec/unit/client/redis/adm/app_spec.rb +5 -0
  71. data/spec/unit/client/redis/adm/notification_spec.rb +5 -0
  72. data/spec/unit/client/redis/apns/app_spec.rb +5 -0
  73. data/spec/unit/client/redis/apns/feedback_spec.rb +5 -0
  74. data/spec/unit/client/redis/apns/notification_spec.rb +50 -0
  75. data/spec/unit/client/redis/apns2/app_spec.rb +4 -0
  76. data/spec/unit/client/redis/apns2/notification_spec.rb +50 -0
  77. data/spec/unit/client/redis/app_spec.rb +5 -0
  78. data/spec/unit/client/redis/gcm/app_spec.rb +5 -0
  79. data/spec/unit/client/redis/gcm/notification_spec.rb +5 -0
  80. data/spec/unit/client/redis/notification_spec.rb +5 -0
  81. data/spec/unit/client/redis/pushy/app_spec.rb +5 -0
  82. data/spec/unit/client/redis/pushy/notification_spec.rb +5 -0
  83. data/spec/unit/client/redis/wns/badge_notification_spec.rb +5 -0
  84. data/spec/unit/client/redis/wns/raw_notification_spec.rb +22 -0
  85. data/spec/unit/client/redis/wpns/app_spec.rb +5 -0
  86. data/spec/unit/client/redis/wpns/notification_spec.rb +5 -0
  87. data/spec/unit/client/shared/adm/app.rb +51 -0
  88. data/spec/unit/client/shared/adm/notification.rb +39 -0
  89. data/spec/unit/client/shared/apns/app.rb +29 -0
  90. data/spec/unit/client/shared/apns/feedback.rb +9 -0
  91. data/spec/unit/client/shared/apns/notification.rb +262 -0
  92. data/spec/unit/client/shared/app.rb +17 -0
  93. data/spec/unit/client/shared/gcm/app.rb +4 -0
  94. data/spec/unit/client/shared/gcm/notification.rb +77 -0
  95. data/spec/unit/client/shared/notification.rb +10 -0
  96. data/spec/unit/client/shared/pushy/app.rb +17 -0
  97. data/spec/unit/client/shared/pushy/notification.rb +55 -0
  98. data/spec/unit/client/shared/wns/badge_notification.rb +15 -0
  99. data/spec/unit/client/shared/wns/raw_notification.rb +21 -0
  100. data/spec/unit/client/shared/wpns/app.rb +4 -0
  101. data/spec/unit/client/shared/wpns/notification.rb +18 -0
  102. data/spec/unit/daemon/apns/feedback_receiver_spec.rb +19 -1
  103. data/spec/unit/daemon/batch_spec.rb +50 -2
  104. data/spec/unit/daemon/delivery_spec.rb +10 -0
  105. data/spec/unit/daemon/gcm/delivery_spec.rb +1 -1
  106. data/spec/unit/daemon/shared/store.rb +312 -0
  107. data/spec/unit/daemon/store/active_record/reconnectable_spec.rb +7 -7
  108. data/spec/unit/daemon/store/active_record_spec.rb +7 -295
  109. data/spec/unit/daemon/store/redis_spec.rb +4 -293
  110. data/spec/unit/daemon/wns/post_request_spec.rb +64 -0
  111. data/spec/unit_spec_helper.rb +3 -0
  112. metadata +114 -14
  113. data/lib/rpush/client/active_model/apns/binary_notification_validator.rb +0 -16
@@ -3,36 +3,8 @@ module Rpush
3
3
  module ActiveRecord
4
4
  module Apns
5
5
  class Notification < Rpush::Client::ActiveRecord::Notification
6
- include Deprecatable
7
6
  include Rpush::Client::ActiveModel::Apns::Notification
8
-
9
- def alert=(alert)
10
- if alert.is_a?(Hash)
11
- write_attribute(:alert, multi_json_dump(alert))
12
- self.alert_is_json = true if has_attribute?(:alert_is_json)
13
- else
14
- write_attribute(:alert, alert)
15
- self.alert_is_json = false if has_attribute?(:alert_is_json)
16
- end
17
- end
18
-
19
- def alert
20
- string_or_json = read_attribute(:alert)
21
-
22
- if has_attribute?(:alert_is_json)
23
- if alert_is_json?
24
- multi_json_load(string_or_json)
25
- else
26
- string_or_json
27
- end
28
- else
29
- begin
30
- multi_json_load(string_or_json)
31
- rescue StandardError
32
- string_or_json
33
- end
34
- end
35
- end
7
+ include ActiveRecordSerializableNotification
36
8
  end
37
9
  end
38
10
  end
@@ -2,7 +2,10 @@ module Rpush
2
2
  module Client
3
3
  module ActiveRecord
4
4
  module Apns2
5
- class Notification < Rpush::Client::ActiveRecord::Apns::Notification
5
+ class Notification < Rpush::Client::ActiveRecord::Notification
6
+ include Rpush::Client::ActiveModel::Apns::Notification
7
+ include Rpush::Client::ActiveModel::Apns2::Notification
8
+ include Rpush::Client::ActiveRecord::Apns::ActiveRecordSerializableNotification
6
9
  end
7
10
  end
8
11
  end
@@ -6,7 +6,7 @@ module Rpush
6
6
 
7
7
  has_many :notifications, class_name: 'Rpush::Client::ActiveRecord::Notification', dependent: :destroy
8
8
 
9
- validates :name, presence: true, uniqueness: { scope: [:type, :environment] }
9
+ validates :name, presence: true, uniqueness: { scope: [:type, :environment], case_sensitive: true }
10
10
  end
11
11
  end
12
12
  end
@@ -21,7 +21,7 @@ module Rpush
21
21
  def notification=(attrs)
22
22
  return unless attrs
23
23
  fail ArgumentError, 'must be a Hash' unless attrs.is_a?(Hash)
24
- write_attribute(:notification, multi_json_dump(attrs.merge(data || {})))
24
+ write_attribute(:notification, multi_json_dump(attrs.merge(notification || {})))
25
25
  end
26
26
 
27
27
  def registration_ids=(ids)
@@ -3,6 +3,7 @@ module Rpush
3
3
  module Redis
4
4
  module Apns2
5
5
  class Notification < Rpush::Client::Redis::Notification
6
+ include Rpush::Client::ActiveModel::Apns::Notification
6
7
  include Rpush::Client::ActiveModel::Apns2::Notification
7
8
  end
8
9
  end
@@ -18,7 +18,8 @@ module Rpush
18
18
  attribute :apn_key_id, :string
19
19
  attribute :team_id, :string
20
20
  attribute :bundle_id, :string
21
-
21
+ attribute :feedback_enabled, :boolean, default: true
22
+
22
23
  index :name
23
24
 
24
25
  validates :name, presence: true
@@ -20,7 +20,7 @@ module Rpush
20
20
 
21
21
  attribute :badge, :integer
22
22
  attribute :device_token, :string
23
- attribute :sound, :string, default: 'default'
23
+ attribute :sound, [:string, :hash], strict: false, default: 'default'
24
24
  attribute :alert, [:string, :hash], strict: false
25
25
  attribute :data, :hash
26
26
  attribute :expiry, :integer, default: 1.day.to_i
@@ -34,6 +34,7 @@ module Rpush
34
34
  attribute :error_description, :string
35
35
  attribute :deliver_after, :timestamp
36
36
  attribute :alert_is_json, :boolean
37
+ attribute :sound_is_json, :boolean
37
38
  attribute :app_id, :integer
38
39
  attribute :collapse_key, :string
39
40
  attribute :delay_while_idle, :boolean
@@ -9,7 +9,6 @@ module Rpush
9
9
 
10
10
  def time_to_live=(value)
11
11
  self.expiry = value
12
- super
13
12
  end
14
13
  end
15
14
  end
@@ -16,7 +16,7 @@ module Rpush
16
16
  end
17
17
  end
18
18
 
19
- CURRENT_ATTRS = [:push_poll, :embedded, :pid_file, :batch_size, :push, :client, :logger, :log_file, :foreground, :log_level, :plugin, :apns]
19
+ CURRENT_ATTRS = [:push_poll, :embedded, :pid_file, :batch_size, :push, :client, :logger, :log_file, :foreground, :foreground_logging, :log_level, :plugin, :apns]
20
20
  DEPRECATED_ATTRS = []
21
21
  CONFIG_ATTRS = CURRENT_ATTRS + DEPRECATED_ATTRS
22
22
 
@@ -53,6 +53,7 @@ module Rpush
53
53
  self.log_level = (defined?(Rails) && Rails.logger) ? Rails.logger.level : ::Logger::Severity::DEBUG
54
54
  self.plugin = OpenStruct.new
55
55
  self.foreground = false
56
+ self.foreground_logging = true
56
57
 
57
58
  self.apns = ApnsConfiguration.new
58
59
 
@@ -109,7 +109,7 @@ module Rpush
109
109
  Feeder.stop
110
110
  AppRunner.stop
111
111
  delete_pid_file
112
- puts ANSI.green { '✔' } if Rpush.config.foreground
112
+ puts Rainbow('✔').red if Rpush.config.foreground && Rpush.config.foreground_logging
113
113
  end
114
114
  end
115
115
 
@@ -168,7 +168,7 @@ module Rpush
168
168
  if Rpush::Daemon::AppRunner.app_ids.count == 0
169
169
  puts <<-EOS
170
170
 
171
- * #{ANSI.green { 'Is this your first time using Rpush?' }}
171
+ * #{Rainbow('Is this your first time using Rpush?').green}
172
172
  You need to create an App before you can start using Rpush.
173
173
  Please refer to the documentation at https://github.com/rpush/rpush
174
174
 
@@ -24,6 +24,7 @@ module Rpush
24
24
 
25
25
  def start
26
26
  return if Rpush.config.push
27
+ return unless @app.feedback_enabled
27
28
  Rpush.logger.info("[#{@app.name}] Starting feedback receiver... ", true)
28
29
 
29
30
  @thread = Thread.new do
@@ -36,7 +37,7 @@ module Rpush
36
37
  Rpush::Daemon.store.release_connection
37
38
  end
38
39
 
39
- puts ANSI.green { '✔' } if Rpush.config.foreground
40
+ puts Rainbow('✔').green if Rpush.config.foreground && Rpush.config.foreground_logging
40
41
  end
41
42
 
42
43
  def stop
@@ -7,6 +7,7 @@ module Rpush
7
7
 
8
8
  class Delivery < Rpush::Daemon::Delivery
9
9
  RETRYABLE_CODES = [ 429, 500, 503 ]
10
+ CLIENT_JOIN_TIMEOUT = 60
10
11
 
11
12
  def initialize(app, http2_client, batch)
12
13
  @app = app
@@ -20,7 +21,11 @@ module Rpush
20
21
  end
21
22
 
22
23
  # Send all preprocessed requests at once
23
- @client.join
24
+ @client.join(timeout: CLIENT_JOIN_TIMEOUT)
25
+ rescue NetHttp2::AsyncRequestTimeout => error
26
+ mark_batch_retryable(Time.now + 10.seconds, error)
27
+ @client.close
28
+ raise
24
29
  rescue Errno::ECONNREFUSED, SocketError => error
25
30
  mark_batch_retryable(Time.now + 10.seconds, error)
26
31
  raise
@@ -7,6 +7,7 @@ module Rpush
7
7
 
8
8
  class Delivery < Rpush::Daemon::Delivery
9
9
  RETRYABLE_CODES = [ 429, 500, 503 ]
10
+ CLIENT_JOIN_TIMEOUT = 60
10
11
 
11
12
  def initialize(app, http2_client, token_provider, batch)
12
13
  @app = app
@@ -22,7 +23,11 @@ module Rpush
22
23
  end
23
24
 
24
25
  # Send all preprocessed requests at once
25
- @client.join
26
+ @client.join(timeout: CLIENT_JOIN_TIMEOUT)
27
+ rescue NetHttp2::AsyncRequestTimeout => error
28
+ mark_batch_retryable(Time.now + 10.seconds, error)
29
+ @client.close
30
+ raise
26
31
  rescue Errno::ECONNREFUSED, SocketError, HTTP2::Error::StreamLimitExceeded => error
27
32
  # TODO restart connection when StreamLimitExceeded
28
33
  mark_batch_retryable(Time.now + 10.seconds, error)
@@ -133,7 +138,7 @@ module Rpush
133
138
  jwt_token = @token_provider.token
134
139
 
135
140
  headers = {}
136
-
141
+
137
142
  headers['content-type'] = 'application/json'
138
143
  headers['apns-expiration'] = '0'
139
144
  headers['apns-priority'] = '10'
@@ -29,7 +29,7 @@ module Rpush
29
29
  Rpush.logger.info("[#{app.name}] Starting #{pluralize(app.connections, 'dispatcher')}... ", true)
30
30
  runner = @runners[app.id] = new(app)
31
31
  runner.start_dispatchers
32
- puts ANSI.green { '✔' } if Rpush.config.foreground
32
+ puts Rainbow('✔').green if Rpush.config.foreground && Rpush.config.foreground_logging
33
33
  runner.start_loops
34
34
  rescue StandardError => e
35
35
  @runners.delete(app.id)
@@ -2,6 +2,7 @@ module Rpush
2
2
  module Daemon
3
3
  class Batch
4
4
  include Reflectable
5
+ include Loggable
5
6
 
6
7
  attr_reader :num_processed, :notifications, :delivered, :failed, :retryable
7
8
 
@@ -31,16 +32,21 @@ module Rpush
31
32
  @retryable[deliver_after] ||= []
32
33
  @retryable[deliver_after] << notification
33
34
  end
35
+
34
36
  Rpush::Daemon.store.mark_retryable(notification, deliver_after, persist: false)
35
37
  end
36
38
 
37
- def mark_all_retryable(deliver_after)
38
- @mutex.synchronize do
39
- @retryable[deliver_after] = @notifications
40
- end
39
+ def mark_all_retryable(deliver_after, error)
40
+ retryable_count = 0
41
+
41
42
  each_notification do |notification|
42
- Rpush::Daemon.store.mark_retryable(notification, deliver_after, persist: false)
43
+ next if notification.delivered || notification.failed
44
+
45
+ retryable_count += 1
46
+ mark_retryable(notification, deliver_after)
43
47
  end
48
+
49
+ log_warn("Will retry #{retryable_count} of #{@notifications.size} notifications after #{deliver_after.strftime('%Y-%m-%d %H:%M:%S')} due to error (#{error.class.name}, #{error.message})")
44
50
  end
45
51
 
46
52
  def mark_delivered(notification)
@@ -54,6 +60,7 @@ module Rpush
54
60
  @mutex.synchronize do
55
61
  @delivered = @notifications
56
62
  end
63
+
57
64
  each_notification do |notification|
58
65
  Rpush::Daemon.store.mark_delivered(notification, Time.now, persist: false)
59
66
  end
@@ -20,8 +20,7 @@ module Rpush
20
20
  end
21
21
 
22
22
  def mark_batch_retryable(deliver_after, error)
23
- log_warn("Will retry #{@batch.notifications.size} notifications after #{deliver_after.strftime('%Y-%m-%d %H:%M:%S')} due to error (#{error.class.name}, #{error.message})")
24
- @batch.mark_all_retryable(deliver_after)
23
+ @batch.mark_all_retryable(deliver_after, error)
25
24
  end
26
25
 
27
26
  def mark_delivered
@@ -2,11 +2,13 @@ module Rpush
2
2
  module Daemon
3
3
  module Dispatcher
4
4
  class ApnsHttp2
5
+ include Loggable
6
+ include Reflectable
5
7
 
6
8
  URLS = {
7
9
  production: 'https://api.push.apple.com:443',
8
- development: 'https://api.development.push.apple.com:443',
9
- sandbox: 'https://api.development.push.apple.com:443'
10
+ development: 'https://api.sandbox.push.apple.com:443',
11
+ sandbox: 'https://api.sandbox.push.apple.com:443'
10
12
  }
11
13
 
12
14
  DEFAULT_TIMEOUT = 60
@@ -7,7 +7,8 @@ module Rpush
7
7
 
8
8
  URLS = {
9
9
  production: 'https://api.push.apple.com',
10
- development: 'https://api.development.push.apple.com'
10
+ development: 'https://api.sandbox.push.apple.com',
11
+ sandbox: 'https://api.sandbox.push.apple.com'
11
12
  }
12
13
 
13
14
  DEFAULT_TIMEOUT = 60
@@ -29,7 +29,7 @@ module Rpush
29
29
 
30
30
  def self.start_handler(read_io)
31
31
  @thread = Thread.new do
32
- while readable_io = IO.select([read_io]) # rubocop:disable AssignmentInCondition
32
+ while readable_io = IO.select([read_io]) # rubocop:disable Lint/AssignmentInCondition
33
33
  signal = readable_io.first[0].gets.strip
34
34
 
35
35
  begin
@@ -183,7 +183,7 @@ module Rpush
183
183
 
184
184
  private
185
185
 
186
- def create_gcm_like_notification(notification, attrs, data, registration_ids, deliver_after, app) # rubocop:disable ParameterLists
186
+ def create_gcm_like_notification(notification, attrs, data, registration_ids, deliver_after, app) # rubocop:disable Metrics/ParameterLists
187
187
  with_database_reconnect_and_retry do
188
188
  notification.assign_attributes(attrs)
189
189
  notification.data = data
@@ -67,7 +67,7 @@ module Rpush
67
67
 
68
68
  def check_database_is_connected
69
69
  # Simply asking the adapter for the connection state is not sufficient.
70
- Rpush::Client::ActiveRecord::Notification.count
70
+ Rpush::Client::ActiveRecord::Notification.exists?
71
71
  end
72
72
 
73
73
  def sleep_to_avoid_thrashing
@@ -138,7 +138,7 @@ module Rpush
138
138
  nil
139
139
  end
140
140
 
141
- def create_gcm_like_notification(notification, attrs, data, registration_ids, deliver_after, app) # rubocop:disable ParameterLists
141
+ def create_gcm_like_notification(notification, attrs, data, registration_ids, deliver_after, app) # rubocop:disable Metrics/ParameterLists
142
142
  notification.assign_attributes(attrs)
143
143
  notification.data = data
144
144
  notification.registration_ids = registration_ids
@@ -4,14 +4,19 @@ module Rpush
4
4
  class BadgeRequest
5
5
  def self.create(notification, access_token)
6
6
  body = BadgeRequestPayload.new(notification).to_xml
7
- uri = URI.parse(notification.uri)
8
- post = Net::HTTP::Post.new(
9
- uri.request_uri,
7
+ uri = URI.parse(notification.uri)
8
+ headers = {
10
9
  "Content-Length" => body.length.to_s,
11
10
  "Content-Type" => "text/xml",
12
11
  "X-WNS-Type" => "wns/badge",
13
12
  "X-WNS-RequestForStatus" => "true",
14
13
  "Authorization" => "Bearer #{access_token}"
14
+ }
15
+ headers['X-WNS-PRIORITY'] = notification.priority.to_s if notification.priority
16
+
17
+ post = Net::HTTP::Post.new(
18
+ uri.request_uri,
19
+ headers
15
20
  )
16
21
  post.body = body
17
22
  post
@@ -5,14 +5,21 @@ module Rpush
5
5
  def self.create(notification, access_token)
6
6
  body = notification.data.to_json
7
7
  uri = URI.parse(notification.uri)
8
- post = Net::HTTP::Post.new(
9
- uri.request_uri,
8
+ headers = {
10
9
  "Content-Length" => body.length.to_s,
11
10
  "Content-Type" => "application/octet-stream",
12
11
  "X-WNS-Type" => "wns/raw",
13
12
  "X-WNS-RequestForStatus" => "true",
14
13
  "Authorization" => "Bearer #{access_token}"
14
+ }
15
+
16
+ headers['X-WNS-PRIORITY'] = notification.priority.to_s if notification.priority
17
+
18
+ post = Net::HTTP::Post.new(
19
+ uri.request_uri,
20
+ headers
15
21
  )
22
+
16
23
  post.body = body
17
24
  post
18
25
  end
@@ -5,13 +5,17 @@ module Rpush
5
5
  def self.create(notification, access_token)
6
6
  body = ToastRequestPayload.new(notification).to_xml
7
7
  uri = URI.parse(notification.uri)
8
- post = Net::HTTP::Post.new(
9
- uri.request_uri,
8
+ headers = {
10
9
  "Content-Length" => body.length.to_s,
11
10
  "Content-Type" => "text/xml",
12
11
  "X-WNS-Type" => "wns/toast",
13
12
  "X-WNS-RequestForStatus" => "true",
14
13
  "Authorization" => "Bearer #{access_token}"
14
+ }
15
+ headers['X-WNS-PRIORITY'] = notification.priority.to_s if notification.priority
16
+ post = Net::HTTP::Post.new(
17
+ uri.request_uri,
18
+ headers
15
19
  )
16
20
  post.body = body
17
21
  post
@@ -79,6 +79,7 @@ module Rpush
79
79
  end
80
80
 
81
81
  def log_foreground(io, formatted_msg, inline)
82
+ return unless Rpush.config.foreground_logging
82
83
  return unless io == STDERR || Rpush.config.foreground
83
84
 
84
85
  if inline
@@ -1,7 +1,7 @@
1
1
  module Rpush
2
2
  module VERSION
3
- MAJOR = 4
4
- MINOR = 1
3
+ MAJOR = 5
4
+ MINOR = 2
5
5
  TINY = 0
6
6
  PRE = nil
7
7
 
@@ -1,4 +1,4 @@
1
1
  inherit_from: ../.rubocop.yml
2
2
 
3
- RescueModifier:
3
+ Style/RescueModifier:
4
4
  Enabled: false