rpush 4.1.0 → 5.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +254 -162
- data/README.md +57 -16
- data/lib/generators/rpush_migration_generator.rb +2 -0
- data/lib/generators/templates/rpush.rb +4 -0
- data/lib/generators/templates/rpush_4_1_1_updates.rb +9 -0
- data/lib/generators/templates/rpush_4_2_0_updates.rb +10 -0
- data/lib/rpush/apns_feedback.rb +1 -0
- data/lib/rpush/cli.rb +9 -22
- data/lib/rpush/client/active_model.rb +1 -1
- data/lib/rpush/client/active_model/apns/notification.rb +9 -1
- data/lib/rpush/client/active_model/apns/notification_payload_size_validator.rb +15 -0
- data/lib/rpush/client/active_model/apns2/notification.rb +14 -0
- data/lib/rpush/client/active_model/gcm/notification.rb +4 -3
- data/lib/rpush/client/active_model/wns/notification.rb +8 -0
- data/lib/rpush/client/active_record.rb +1 -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 -29
- data/lib/rpush/client/active_record/apns2/notification.rb +4 -1
- data/lib/rpush/client/active_record/app.rb +1 -1
- data/lib/rpush/client/active_record/notification.rb +1 -1
- data/lib/rpush/client/redis/apns2/notification.rb +1 -0
- data/lib/rpush/client/redis/app.rb +2 -1
- data/lib/rpush/client/redis/notification.rb +2 -1
- data/lib/rpush/client/redis/pushy/notification.rb +0 -1
- data/lib/rpush/configuration.rb +2 -1
- data/lib/rpush/daemon.rb +2 -2
- data/lib/rpush/daemon/apns/feedback_receiver.rb +2 -1
- data/lib/rpush/daemon/apns2/delivery.rb +6 -1
- data/lib/rpush/daemon/apnsp8/delivery.rb +7 -2
- 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/dispatcher/apns_http2.rb +4 -2
- data/lib/rpush/daemon/dispatcher/apnsp8_http2.rb +2 -1
- data/lib/rpush/daemon/signal_handler.rb +1 -1
- data/lib/rpush/daemon/store/active_record.rb +1 -1
- data/lib/rpush/daemon/store/active_record/reconnectable.rb +1 -1
- data/lib/rpush/daemon/store/redis.rb +1 -1
- data/lib/rpush/daemon/wns/badge_request.rb +8 -3
- data/lib/rpush/daemon/wns/raw_request.rb +9 -2
- data/lib/rpush/daemon/wns/toast_request.rb +6 -2
- data/lib/rpush/logger.rb +1 -0
- data/lib/rpush/version.rb +2 -2
- data/spec/.rubocop.yml +1 -1
- data/spec/functional/apns2_spec.rb +85 -0
- data/spec/functional/gcm_priority_spec.rb +40 -0
- data/spec/support/active_record_setup.rb +5 -1
- data/spec/support/simplecov_helper.rb +1 -1
- data/spec/unit/apns_feedback_spec.rb +17 -6
- 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 -288
- data/spec/unit/client/active_record/apns2/app_spec.rb +4 -0
- data/spec/unit/client/active_record/apns2/notification_spec.rb +65 -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 -83
- data/spec/unit/client/active_record/notification_spec.rb +10 -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/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/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/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 +262 -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/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/apns/feedback_receiver_spec.rb +19 -1
- data/spec/unit/daemon/batch_spec.rb +50 -2
- data/spec/unit/daemon/delivery_spec.rb +10 -0
- data/spec/unit/daemon/gcm/delivery_spec.rb +1 -1
- 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 +7 -295
- data/spec/unit/daemon/store/redis_spec.rb +4 -293
- data/spec/unit/daemon/wns/post_request_spec.rb +64 -0
- data/spec/unit_spec_helper.rb +3 -0
- metadata +114 -14
- 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::
|
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(
|
24
|
+
write_attribute(:notification, multi_json_dump(attrs.merge(notification || {})))
|
25
25
|
end
|
26
26
|
|
27
27
|
def registration_ids=(ids)
|
@@ -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
|
data/lib/rpush/configuration.rb
CHANGED
@@ -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
|
|
data/lib/rpush/daemon.rb
CHANGED
@@ -109,7 +109,7 @@ module Rpush
|
|
109
109
|
Feeder.stop
|
110
110
|
AppRunner.stop
|
111
111
|
delete_pid_file
|
112
|
-
puts
|
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
|
-
* #{
|
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
|
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
|
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)
|
data/lib/rpush/daemon/batch.rb
CHANGED
@@ -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
|
-
|
39
|
-
|
40
|
-
end
|
39
|
+
def mark_all_retryable(deliver_after, error)
|
40
|
+
retryable_count = 0
|
41
|
+
|
41
42
|
each_notification do |notification|
|
42
|
-
|
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
|
-
|
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.
|
9
|
-
sandbox: 'https://api.
|
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
|
@@ -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.
|
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
|
8
|
-
|
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
|
-
|
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
|
-
|
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
|
data/lib/rpush/logger.rb
CHANGED
data/lib/rpush/version.rb
CHANGED
data/spec/.rubocop.yml
CHANGED