rpush 4.1.1 → 4.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 +24 -0
- data/README.md +1 -1
- data/lib/generators/rpush_migration_generator.rb +1 -0
- data/lib/generators/templates/rpush_4_2_0_updates.rb +10 -0
- data/lib/rpush/client/active_model/gcm/notification.rb +2 -1
- data/lib/rpush/client/active_model/wns/notification.rb +8 -0
- data/lib/rpush/client/active_record/apns/notification.rb +28 -0
- 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/notification.rb +2 -1
- data/lib/rpush/daemon/apns/feedback_receiver.rb +1 -0
- 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/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/version.rb +2 -2
- data/spec/.rubocop.yml +1 -1
- data/spec/support/active_record_setup.rb +3 -1
- data/spec/unit/client/active_record/apns/notification_spec.rb +7 -2
- data/spec/unit/client/active_record/gcm/notification_spec.rb +5 -0
- data/spec/unit/client/active_record/notification_spec.rb +7 -0
- data/spec/unit/daemon/apns/feedback_receiver_spec.rb +19 -1
- data/spec/unit/daemon/gcm/delivery_spec.rb +1 -1
- data/spec/unit/daemon/store/active_record_spec.rb +5 -5
- data/spec/unit/daemon/store/redis_spec.rb +2 -2
- data/spec/unit/daemon/wns/post_request_spec.rb +64 -0
- metadata +8 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 91aa7f4768e10352a77935b5ac2fbf8dd8c992de2267718c15621d1a50b7a890
|
4
|
+
data.tar.gz: bd90e3daaac2067e15848a5616b01e3e76aa51d62e177b3307a7147488fccbe6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3efd360c52d048188749ad07de23b0aec1590f306ecd735eeb676fa7026273429a97c2719caf050a72d91ef533005f99adb0499b7c3f6aa5269a5143d6643c72
|
7
|
+
data.tar.gz: c7b3d1acbb95bf1e298851f3cdbd5b17833dc90aa621dd5482578e0400266e11d87580578087cd402e0449f69f076bcf621db200f175b8393c59277f23ff8482
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,29 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## Unreleased
|
4
|
+
|
5
|
+
Nothing so far.
|
6
|
+
|
7
|
+
## 4.2.0 (2019-12-13)
|
8
|
+
|
9
|
+
[Full Changelog](https://github.com/rpush/rpush/compare/v4.1.1...v4.2.0)
|
10
|
+
|
11
|
+
**Merged pull requests:**
|
12
|
+
|
13
|
+
- Fix Rails 6.1 related deprecation warnings [\#541](https://github.com/rpush/rpush/pull/541) ([dsantosmerino](https://github.com/dsantosmerino))
|
14
|
+
- GCM notification incorrectly mixes data into notification hashes [\#535](https://github.com/rpush/rpush/pull/535) ([mkon](https://github.com/mkon))
|
15
|
+
- handle priority in WNS [\#533](https://github.com/rpush/rpush/pull/533) ([Fivell](https://github.com/Fivell))
|
16
|
+
- Update development apns urls to match documentation [\#524](https://github.com/rpush/rpush/pull/524) ([jhottenstein](https://github.com/jhottenstein))
|
17
|
+
- Update README to remove incorrect info [\#523](https://github.com/rpush/rpush/pull/523) ([sharang-d](https://github.com/sharang-d))
|
18
|
+
- Fix and improve Travis setup [\#520](https://github.com/rpush/rpush/pull/520) ([aried3r](https://github.com/aried3r))
|
19
|
+
- Explicitly use Rails 6.0.0 [\#519](https://github.com/rpush/rpush/pull/519) ([jsantos](https://github.com/jsantos))
|
20
|
+
- Stale bot config change [\#515](https://github.com/rpush/rpush/pull/515) ([aried3r](https://github.com/aried3r))
|
21
|
+
- Add stale bot configuration. [\#514](https://github.com/rpush/rpush/pull/514) ([drn](https://github.com/drn))
|
22
|
+
- Correctly use feedback_enabled. [\#511](https://github.com/rpush/rpush/pull/511) ([kirbycool](https://github.com/kirbycool))
|
23
|
+
- Update apns_http2.rb [\#510](https://github.com/rpush/rpush/pull/510) ([mldoscar](https://github.com/mldoscar))
|
24
|
+
- Add `mutable_content` support for GCM [\#506](https://github.com/rpush/rpush/pull/506) ([hon3st](https://github.com/hon3st))
|
25
|
+
- Add support for critical alerts [\#502](https://github.com/rpush/rpush/pull/502) ([servn](https://github.com/servn))
|
26
|
+
|
3
27
|
## 4.1.1 (2019-05-13)
|
4
28
|
|
5
29
|
### Added
|
data/README.md
CHANGED
@@ -21,7 +21,7 @@ Rpush aims to be the *de facto* gem for sending push notifications in Ruby. Its
|
|
21
21
|
|
22
22
|
#### Feature Highlights
|
23
23
|
|
24
|
-
* Use [**ActiveRecord**](https://github.com/rpush/rpush/wiki/Using-ActiveRecord) or [**Redis**](https://github.com/rpush/rpush/wiki/Using-Redis) for storage.
|
24
|
+
* Use [**ActiveRecord**](https://github.com/rpush/rpush/wiki/Using-ActiveRecord) or [**Redis**](https://github.com/rpush/rpush/wiki/Using-Redis) for storage.
|
25
25
|
* Plugins for [**Bugsnag**](https://github.com/rpush/rpush-plugin-bugsnag),
|
26
26
|
[**Sentry**](https://github.com/rpush/rpush-plugin-sentry), [**StatsD**](https://github.com/rpush/rpush-plugin-statsd) or [write your own](https://github.com/rpush/rpush/wiki/Writing-a-Plugin).
|
27
27
|
* Seamless integration with your projects, including **Rails**.
|
@@ -52,6 +52,7 @@ class RpushMigrationGenerator < Rails::Generators::Base
|
|
52
52
|
add_rpush_migration('rpush_3_3_1_updates')
|
53
53
|
add_rpush_migration('rpush_4_1_0_updates')
|
54
54
|
add_rpush_migration('rpush_4_1_1_updates')
|
55
|
+
add_rpush_migration('rpush_4_2_0_updates')
|
55
56
|
end
|
56
57
|
|
57
58
|
protected
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class Rpush420Updates < ActiveRecord::VERSION::MAJOR >= 5 ? ActiveRecord::Migration["#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}"] : ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
add_column :rpush_notifications, :sound_is_json, :boolean, null: true, default: false
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.down
|
7
|
+
remove_column :rpush_notifications, :sound_is_json
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
@@ -35,7 +35,7 @@ module Rpush
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
def as_json(options = nil)
|
38
|
+
def as_json(options = nil) # rubocop:disable Metrics/PerceivedComplexity
|
39
39
|
json = {
|
40
40
|
'registration_ids' => registration_ids,
|
41
41
|
'delay_while_idle' => delay_while_idle,
|
@@ -43,6 +43,7 @@ module Rpush
|
|
43
43
|
}
|
44
44
|
json['collapse_key'] = collapse_key if collapse_key
|
45
45
|
json['content_available'] = content_available if content_available
|
46
|
+
json['mutable_content'] = mutable_content if mutable_content
|
46
47
|
json['dry_run'] = dry_run if dry_run
|
47
48
|
json['notification'] = notification if notification
|
48
49
|
json['priority'] = priority_for_notification if priority
|
@@ -3,6 +3,13 @@ module Rpush
|
|
3
3
|
module ActiveModel
|
4
4
|
module Wns
|
5
5
|
module Notification
|
6
|
+
WNS_PRIORITY_HIGH = 1
|
7
|
+
WNS_PRIORITY_MEDIUM = 2
|
8
|
+
WNS_PRIORITY_LOW = 3
|
9
|
+
WNS_PRIORITY_VERY_LOW = 4
|
10
|
+
|
11
|
+
WNS_PRIORITIES = [WNS_PRIORITY_HIGH, WNS_PRIORITY_MEDIUM, WNS_PRIORITY_LOW, WNS_PRIORITY_VERY_LOW]
|
12
|
+
|
6
13
|
module InstanceMethods
|
7
14
|
def alert=(value)
|
8
15
|
return unless value
|
@@ -23,6 +30,7 @@ module Rpush
|
|
23
30
|
validates :uri, presence: true
|
24
31
|
validates :uri, format: { with: %r{https?://[\S]+} }
|
25
32
|
validates :data, presence: true, unless: :skip_data_validation?
|
33
|
+
validates :priority, inclusion: { in: WNS_PRIORITIES }, allow_nil: true
|
26
34
|
end
|
27
35
|
end
|
28
36
|
end
|
@@ -33,6 +33,34 @@ module Rpush
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
36
|
+
|
37
|
+
def sound=(sound)
|
38
|
+
if sound.is_a?(Hash)
|
39
|
+
write_attribute(:sound, multi_json_dump(sound))
|
40
|
+
self.sound_is_json = true if has_attribute?(:sound_is_json)
|
41
|
+
else
|
42
|
+
write_attribute(:sound, sound)
|
43
|
+
self.sound_is_json = false if has_attribute?(:sound_is_json)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def sound
|
48
|
+
string_or_json = read_attribute(:sound)
|
49
|
+
|
50
|
+
if has_attribute?(:sound_is_json)
|
51
|
+
if sound_is_json?
|
52
|
+
multi_json_load(string_or_json)
|
53
|
+
else
|
54
|
+
string_or_json
|
55
|
+
end
|
56
|
+
else
|
57
|
+
begin
|
58
|
+
multi_json_load(string_or_json)
|
59
|
+
rescue StandardError
|
60
|
+
string_or_json
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
36
64
|
end
|
37
65
|
end
|
38
66
|
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
|
@@ -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
|
@@ -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/version.rb
CHANGED
data/spec/.rubocop.yml
CHANGED
@@ -41,6 +41,7 @@ require 'generators/templates/rpush_3_3_0_updates'
|
|
41
41
|
require 'generators/templates/rpush_3_3_1_updates'
|
42
42
|
require 'generators/templates/rpush_4_1_0_updates'
|
43
43
|
require 'generators/templates/rpush_4_1_1_updates'
|
44
|
+
require 'generators/templates/rpush_4_2_0_updates'
|
44
45
|
|
45
46
|
migrations = [
|
46
47
|
AddRpush,
|
@@ -57,7 +58,8 @@ migrations = [
|
|
57
58
|
Rpush330Updates,
|
58
59
|
Rpush331Updates,
|
59
60
|
Rpush410Updates,
|
60
|
-
Rpush411Updates
|
61
|
+
Rpush411Updates,
|
62
|
+
Rpush420Updates
|
61
63
|
]
|
62
64
|
|
63
65
|
unless ENV['TRAVIS']
|
@@ -82,8 +82,8 @@ describe Rpush::Client::ActiveRecord::Apns::Notification, "as_json" do
|
|
82
82
|
end
|
83
83
|
|
84
84
|
it "should include the sound if present" do
|
85
|
-
notification = Rpush::Client::ActiveRecord::Apns::Notification.new(
|
86
|
-
expect(notification.as_json["aps"]["
|
85
|
+
notification = Rpush::Client::ActiveRecord::Apns::Notification.new(sound: "my_sound.aiff")
|
86
|
+
expect(notification.as_json["aps"]["sound"]).to eq "my_sound.aiff"
|
87
87
|
end
|
88
88
|
|
89
89
|
it "should not include the sound key if the sound is not present" do
|
@@ -91,6 +91,11 @@ describe Rpush::Client::ActiveRecord::Apns::Notification, "as_json" do
|
|
91
91
|
expect(notification.as_json["aps"].key?("sound")).to be_falsey
|
92
92
|
end
|
93
93
|
|
94
|
+
it "should encode the sound as JSON if it is a Hash" do
|
95
|
+
notification = Rpush::Client::ActiveRecord::Apns::Notification.new(sound: { 'name' => "my_sound.aiff", 'critical' => 1, 'volume' => 0.5 })
|
96
|
+
expect(notification.as_json["aps"]["sound"]).to eq('name' => "my_sound.aiff", 'critical' => 1, 'volume' => 0.5)
|
97
|
+
end
|
98
|
+
|
94
99
|
it "should include attributes for the device" do
|
95
100
|
notification = Rpush::Client::ActiveRecord::Apns::Notification.new
|
96
101
|
notification.data = { omg: :lol, wtf: :dunno }
|
@@ -37,6 +37,11 @@ describe Rpush::Client::ActiveRecord::Gcm::Notification do
|
|
37
37
|
expect(notification.as_json['content_available']).to eq true
|
38
38
|
end
|
39
39
|
|
40
|
+
it 'includes mutable_content in the payload' do
|
41
|
+
notification.mutable_content = true
|
42
|
+
expect(notification.as_json['mutable_content']).to eq true
|
43
|
+
end
|
44
|
+
|
40
45
|
it 'sets the priority to high when set to high' do
|
41
46
|
notification.priority = 'high'
|
42
47
|
expect(notification.as_json['priority']).to eq 'high'
|
@@ -18,4 +18,11 @@ describe Rpush::Client::ActiveRecord::Notification do
|
|
18
18
|
expect(notification.app).to be_valid
|
19
19
|
expect(notification).to be_valid
|
20
20
|
end
|
21
|
+
|
22
|
+
it 'does not mix notification and data payloads' do
|
23
|
+
notification.data = { key: 'this is data' }
|
24
|
+
notification.notification = { key: 'this is notification' }
|
25
|
+
expect(notification.data).to eq('key' => 'this is data')
|
26
|
+
expect(notification.notification).to eq('key' => 'this is notification')
|
27
|
+
end
|
21
28
|
end if active_record?
|
@@ -7,7 +7,16 @@ describe Rpush::Daemon::Apns::FeedbackReceiver, 'check_for_feedback' do
|
|
7
7
|
let(:frequency) { 60 }
|
8
8
|
let(:certificate) { double }
|
9
9
|
let(:password) { double }
|
10
|
-
let(:
|
10
|
+
let(:feedback_enabled) { true }
|
11
|
+
let(:app) do
|
12
|
+
double(
|
13
|
+
name: 'my_app',
|
14
|
+
password: password,
|
15
|
+
certificate: certificate,
|
16
|
+
feedback_enabled: feedback_enabled,
|
17
|
+
environment: 'production'
|
18
|
+
)
|
19
|
+
end
|
11
20
|
let(:connection) { double(connect: nil, read: nil, close: nil) }
|
12
21
|
let(:logger) { double(error: nil, info: nil) }
|
13
22
|
let(:receiver) { Rpush::Daemon::Apns::FeedbackReceiver.new(app) }
|
@@ -93,6 +102,15 @@ describe Rpush::Daemon::Apns::FeedbackReceiver, 'check_for_feedback' do
|
|
93
102
|
expect(receiver).to receive(:check_for_feedback).at_least(:once)
|
94
103
|
receiver.start
|
95
104
|
end
|
105
|
+
|
106
|
+
context 'with feedback_enabled false' do
|
107
|
+
let(:feedback_enabled) { false }
|
108
|
+
|
109
|
+
it 'does not check for feedback when started' do
|
110
|
+
expect(receiver).not_to receive(:check_for_feedback)
|
111
|
+
receiver.start
|
112
|
+
end
|
113
|
+
end
|
96
114
|
end
|
97
115
|
|
98
116
|
describe 'stop' do
|
@@ -40,7 +40,7 @@ describe Rpush::Daemon::Gcm::Delivery do
|
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'creates a new notification for the unavailable devices' do
|
43
|
-
notification.
|
43
|
+
notification.update(registration_ids: %w(id_0 id_1 id_2), data: { 'one' => 1 }, collapse_key: 'thing', delay_while_idle: true)
|
44
44
|
allow(response).to receive_messages(header: { 'retry-after' => 10 })
|
45
45
|
attrs = { 'collapse_key' => 'thing', 'delay_while_idle' => true, 'app_id' => app.id }
|
46
46
|
expect(store).to receive(:create_gcm_notification).with(attrs, notification.data,
|
@@ -69,27 +69,27 @@ describe Rpush::Daemon::Store::ActiveRecord do
|
|
69
69
|
end
|
70
70
|
|
71
71
|
it 'loads an undelivered notification without deliver_after set' do
|
72
|
-
notification.
|
72
|
+
notification.update!(delivered: false, deliver_after: nil)
|
73
73
|
expect(store.deliverable_notifications(Rpush.config.batch_size)).to eq [notification]
|
74
74
|
end
|
75
75
|
|
76
76
|
it 'loads an notification with a deliver_after time in the past' do
|
77
|
-
notification.
|
77
|
+
notification.update!(delivered: false, deliver_after: 1.hour.ago)
|
78
78
|
expect(store.deliverable_notifications(Rpush.config.batch_size)).to eq [notification]
|
79
79
|
end
|
80
80
|
|
81
81
|
it 'does not load an notification with a deliver_after time in the future' do
|
82
|
-
notification.
|
82
|
+
notification.update!(delivered: false, deliver_after: 1.hour.from_now)
|
83
83
|
expect(store.deliverable_notifications(Rpush.config.batch_size)).to be_empty
|
84
84
|
end
|
85
85
|
|
86
86
|
it 'does not load a previously delivered notification' do
|
87
|
-
notification.
|
87
|
+
notification.update!(delivered: true, delivered_at: time)
|
88
88
|
expect(store.deliverable_notifications(Rpush.config.batch_size)).to be_empty
|
89
89
|
end
|
90
90
|
|
91
91
|
it "does not enqueue a notification that has previously failed delivery" do
|
92
|
-
notification.
|
92
|
+
notification.update!(delivered: false, failed: true)
|
93
93
|
expect(store.deliverable_notifications(Rpush.config.batch_size)).to be_empty
|
94
94
|
end
|
95
95
|
end
|
@@ -51,12 +51,12 @@ describe Rpush::Daemon::Store::Redis do
|
|
51
51
|
end
|
52
52
|
|
53
53
|
it 'loads an undelivered notification without deliver_after set' do
|
54
|
-
notification.
|
54
|
+
notification.update!(delivered: false, deliver_after: nil)
|
55
55
|
expect(store.deliverable_notifications(Rpush.config.batch_size)).to eq [notification]
|
56
56
|
end
|
57
57
|
|
58
58
|
it 'loads an notification with a deliver_after time in the past' do
|
59
|
-
notification.
|
59
|
+
notification.update!(delivered: false, deliver_after: 1.hour.ago)
|
60
60
|
expect(store.deliverable_notifications(Rpush.config.batch_size)).to eq [notification]
|
61
61
|
end
|
62
62
|
|
@@ -30,6 +30,8 @@ describe Rpush::Daemon::Wns::PostRequest do
|
|
30
30
|
expect(request.body).to include('<toast>')
|
31
31
|
expect(request.body).to include('MyApp')
|
32
32
|
expect(request.body).to include('Example notification')
|
33
|
+
# no priority header
|
34
|
+
expect { request.fetch('X-WNS-PRIORITY') }.to raise_error(KeyError)
|
33
35
|
end
|
34
36
|
|
35
37
|
context 'with launch' do
|
@@ -55,6 +57,29 @@ describe Rpush::Daemon::Wns::PostRequest do
|
|
55
57
|
end
|
56
58
|
end
|
57
59
|
|
60
|
+
context 'with priority' do
|
61
|
+
let(:notification) do
|
62
|
+
Rpush::Wns::Notification.create!(
|
63
|
+
app: app,
|
64
|
+
data: {
|
65
|
+
title: "MyApp",
|
66
|
+
body: "Example notification"
|
67
|
+
},
|
68
|
+
uri: "http://some.example/",
|
69
|
+
priority: 1
|
70
|
+
)
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'creates a request characteristic for toast notification with priority' do
|
74
|
+
request = Rpush::Daemon::Wns::PostRequest.create(notification, 'token')
|
75
|
+
expect(request['X-WNS-Type']).to eq('wns/toast')
|
76
|
+
expect(request['Content-Type']).to eq('text/xml')
|
77
|
+
expect(request['X-WNS-PRIORITY']).to eq('1')
|
78
|
+
expect(request.body).to include('MyApp')
|
79
|
+
expect(request.body).to include('Example notification')
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
58
83
|
context 'with sound' do
|
59
84
|
let(:notification) do
|
60
85
|
Rpush::Wns::Notification.create!(
|
@@ -95,6 +120,25 @@ describe Rpush::Daemon::Wns::PostRequest do
|
|
95
120
|
expect(request['Content-Type']).to eq('application/octet-stream')
|
96
121
|
expect(request.body).to eq("{\"foo\":\"foo\",\"bar\":\"bar\"}")
|
97
122
|
end
|
123
|
+
|
124
|
+
context 'with priority' do
|
125
|
+
let(:notification) do
|
126
|
+
Rpush::Wns::RawNotification.create!(
|
127
|
+
app: app,
|
128
|
+
data: { foo: 'foo', bar: 'bar' },
|
129
|
+
uri: "http://some.example/",
|
130
|
+
priority: 3
|
131
|
+
)
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'creates a request characteristic for raw notification with priority' do
|
135
|
+
request = Rpush::Daemon::Wns::PostRequest.create(notification, 'token')
|
136
|
+
expect(request['X-WNS-Type']).to eq('wns/raw')
|
137
|
+
expect(request['X-WNS-PRIORITY']).to eq('3')
|
138
|
+
expect(request['Content-Type']).to eq('application/octet-stream')
|
139
|
+
expect(request.body).to eq("{\"foo\":\"foo\",\"bar\":\"bar\"}")
|
140
|
+
end
|
141
|
+
end
|
98
142
|
end
|
99
143
|
|
100
144
|
context 'BadgeNotification' do
|
@@ -113,5 +157,25 @@ describe Rpush::Daemon::Wns::PostRequest do
|
|
113
157
|
expect(request.body).to include('<badge')
|
114
158
|
expect(request.body).to include('42')
|
115
159
|
end
|
160
|
+
|
161
|
+
context 'with priority' do
|
162
|
+
let(:notification) do
|
163
|
+
Rpush::Wns::BadgeNotification.create!(
|
164
|
+
app: app,
|
165
|
+
uri: "http://some.example/",
|
166
|
+
badge: 42,
|
167
|
+
priority: 4
|
168
|
+
)
|
169
|
+
end
|
170
|
+
|
171
|
+
it 'creates a request characteristic for badge notification with priority' do
|
172
|
+
request = Rpush::Daemon::Wns::PostRequest.create(notification, 'token')
|
173
|
+
expect(request['X-WNS-Type']).to eq('wns/badge')
|
174
|
+
expect(request['X-WNS-PRIORITY']).to eq('4')
|
175
|
+
expect(request['Content-Type']).to eq('text/xml')
|
176
|
+
expect(request.body).to include('<badge')
|
177
|
+
expect(request.body).to include('42')
|
178
|
+
end
|
179
|
+
end
|
116
180
|
end
|
117
181
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rpush
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ian Leitch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|
@@ -392,6 +392,7 @@ files:
|
|
392
392
|
- lib/generators/templates/rpush_3_3_1_updates.rb
|
393
393
|
- lib/generators/templates/rpush_4_1_0_updates.rb
|
394
394
|
- lib/generators/templates/rpush_4_1_1_updates.rb
|
395
|
+
- lib/generators/templates/rpush_4_2_0_updates.rb
|
395
396
|
- lib/rpush.rb
|
396
397
|
- lib/rpush/apns_feedback.rb
|
397
398
|
- lib/rpush/cli.rb
|
@@ -610,7 +611,10 @@ files:
|
|
610
611
|
homepage: https://github.com/rpush/rpush
|
611
612
|
licenses:
|
612
613
|
- MIT
|
613
|
-
metadata:
|
614
|
+
metadata:
|
615
|
+
bug_tracker_uri: https://github.com/rpush/rpush/issues
|
616
|
+
changelog_uri: https://github.com/rpush/rpush/blob/master/CHANGELOG.md
|
617
|
+
source_code_uri: https://github.com/rpush/rpush
|
614
618
|
post_install_message: |
|
615
619
|
When upgrading, don't forget to run `bundle exec rpush init` to get all the latest migrations.
|
616
620
|
|
@@ -630,7 +634,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
630
634
|
- !ruby/object:Gem::Version
|
631
635
|
version: '0'
|
632
636
|
requirements: []
|
633
|
-
rubygems_version: 3.0.
|
637
|
+
rubygems_version: 3.0.4
|
634
638
|
signing_key:
|
635
639
|
specification_version: 4
|
636
640
|
summary: The push notification service for Ruby.
|