ruby-push-notifications 0.2.2 → 0.3.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.
- checksums.yaml +4 -4
- data/.ruby-style.yml +1 -1
- data/Gemfile.lock +1 -1
- data/examples/apns.rb +5 -2
- data/examples/gcm.rb +5 -2
- data/examples/mpns.rb +5 -2
- data/lib/ruby-push-notifications/apns/apns_notification.rb +1 -3
- data/lib/ruby-push-notifications/apns/apns_pusher.rb +1 -1
- data/lib/ruby-push-notifications/apns/apns_results.rb +30 -0
- data/lib/ruby-push-notifications/apns.rb +1 -0
- data/lib/ruby-push-notifications/gcm/gcm_notification.rb +1 -3
- data/lib/ruby-push-notifications/gcm/gcm_response.rb +1 -0
- data/lib/ruby-push-notifications/mpns/mpns_notification.rb +1 -3
- data/lib/ruby-push-notifications/mpns/mpns_response.rb +1 -0
- data/lib/ruby-push-notifications/mpns/mpns_result.rb +1 -1
- data/lib/ruby-push-notifications/notification_results_manager.rb +14 -0
- data/lib/ruby-push-notifications/version.rb +1 -1
- data/lib/ruby-push-notifications.rb +1 -0
- data/spec/ruby-push-notifications/apns/apns_notification_spec.rb +28 -17
- data/spec/ruby-push-notifications/apns/apns_pusher_spec.rb +30 -33
- data/spec/ruby-push-notifications/gcm/gcm_notification_spec.rb +13 -0
- data/spec/ruby-push-notifications/mpns/mpns_notification_spec.rb +10 -0
- data/spec/support/results_shared_examples.rb +31 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a7eaae46825cd8916811bc2026c97c0714d9d65
|
4
|
+
data.tar.gz: 991a6c2960c32cc9de04cb0ef84daac41863da33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e536c3e750f114ad262920acbd63c9f3dd020aaded4088ac718725a33d87b558ce2caf237cf2a7aa9c41ca98300982a4280f64b587872d18380fd1581435b11e
|
7
|
+
data.tar.gz: 2118a29ead19bafc9edd4ac2b58333e11dbd060395dc35245f9cc2093b13df0a40a5e2cc33eded400e55a7c3b138bbd5ff4561d75fa190f2e6e2e7612bd1cd44
|
data/.ruby-style.yml
CHANGED
@@ -507,7 +507,7 @@ Metrics/CyclomaticComplexity:
|
|
507
507
|
Metrics/LineLength:
|
508
508
|
Description: Limit lines to 80 characters.
|
509
509
|
StyleGuide: https://github.com/bbatsov/ruby-style-guide#80-character-limits
|
510
|
-
Enabled:
|
510
|
+
Enabled: false
|
511
511
|
Max: 80
|
512
512
|
AllowURI: true
|
513
513
|
URISchemes:
|
data/Gemfile.lock
CHANGED
data/examples/apns.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
1
|
+
#!/usr/bin/env bundle exec ruby
|
2
2
|
|
3
3
|
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
4
4
|
|
@@ -13,4 +13,7 @@ notification = RubyPushNotifications::APNS::APNSNotification.new tokens, { aps:
|
|
13
13
|
|
14
14
|
pusher = RubyPushNotifications::APNS::APNSPusher.new(File.read('/path/to/your/apps/certificate.pem'), true)
|
15
15
|
pusher.push [notification]
|
16
|
-
p
|
16
|
+
p 'Notification sending results:'
|
17
|
+
p "Success: #{notification.success}, Failed: #{notification.failed}"
|
18
|
+
p 'Details:'
|
19
|
+
p notification.individual_results
|
data/examples/gcm.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
1
|
+
#!/usr/bin/env bundle exec ruby
|
2
2
|
|
3
3
|
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
4
4
|
|
@@ -13,4 +13,7 @@ notification = RubyPushNotifications::GCM::GCMNotification.new registration_ids,
|
|
13
13
|
|
14
14
|
pusher = RubyPushNotifications::GCM::GCMPusher.new "Your app's GCM key"
|
15
15
|
pusher.push [notification]
|
16
|
-
p
|
16
|
+
p 'Notification sending results:'
|
17
|
+
p "Success: #{notification.success}, Failed: #{notification.failed}"
|
18
|
+
p 'Details:'
|
19
|
+
p notification.individual_results
|
data/examples/mpns.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
1
|
+
#!/usr/bin/env bundle exec ruby
|
2
2
|
|
3
3
|
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
4
4
|
|
@@ -14,4 +14,7 @@ notification = RubyPushNotifications::MPNS::MPNSNotification.new device_urls, {
|
|
14
14
|
|
15
15
|
pusher = RubyPushNotifications::MPNS::MPNSPusher.new
|
16
16
|
pusher.push [notification]
|
17
|
-
p
|
17
|
+
p 'Notification sending results:'
|
18
|
+
p "Success: #{notification.success}, Failed: #{notification.failed}"
|
19
|
+
p 'Details:'
|
20
|
+
p notification.individual_results
|
@@ -10,13 +10,11 @@ module RubyPushNotifications
|
|
10
10
|
#
|
11
11
|
# @author Carlos Alonso
|
12
12
|
class APNSNotification
|
13
|
+
include RubyPushNotifications::NotificationResultsManager
|
13
14
|
|
14
15
|
# @private. 4 weeks in seconds
|
15
16
|
WEEKS_4 = 2419200
|
16
17
|
|
17
|
-
# @return [Array]. Array with the results from sending this notification
|
18
|
-
attr_accessor :results
|
19
|
-
|
20
18
|
# Initializes the APNS Notification
|
21
19
|
#
|
22
20
|
# @param [Array]. Array containing all destinations for the notification
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module RubyPushNotifications
|
2
|
+
module APNS
|
3
|
+
# This class is responsible for holding and
|
4
|
+
# managing result of a pushed notification.
|
5
|
+
#
|
6
|
+
# @author Carlos Alonso
|
7
|
+
class APNSResults
|
8
|
+
|
9
|
+
# @return [Array] of each destination's individual result.
|
10
|
+
attr_reader :individual_results
|
11
|
+
|
12
|
+
# Initializes the result
|
13
|
+
#
|
14
|
+
# @param [Array] containing each destination's individual result.
|
15
|
+
def initialize(results)
|
16
|
+
@individual_results = results
|
17
|
+
end
|
18
|
+
|
19
|
+
# @return [Integer] numer of successfully pushed notifications
|
20
|
+
def success
|
21
|
+
@success ||= individual_results.count { |r| r == NO_ERROR_STATUS_CODE }
|
22
|
+
end
|
23
|
+
|
24
|
+
# @return [Integer] number of failed notifications
|
25
|
+
def failed
|
26
|
+
@failed ||= individual_results.count { |r| r != NO_ERROR_STATUS_CODE }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -7,9 +7,7 @@ module RubyPushNotifications
|
|
7
7
|
#
|
8
8
|
# @author Carlos Alonso
|
9
9
|
class GCMNotification
|
10
|
-
|
11
|
-
# @return [Array]. Array with the results from sending this notification
|
12
|
-
attr_accessor :results
|
10
|
+
include RubyPushNotifications::NotificationResultsManager
|
13
11
|
|
14
12
|
# Initializes the notification
|
15
13
|
#
|
@@ -21,6 +21,7 @@ module RubyPushNotifications
|
|
21
21
|
# @return [Array] Array of a GCMResult for every receiver of the notification
|
22
22
|
# sent indicating the result of the operation.
|
23
23
|
attr_reader :results
|
24
|
+
alias_method :individual_results, :results
|
24
25
|
|
25
26
|
# Initializes the GCMResponse and runs response parsing
|
26
27
|
#
|
@@ -7,9 +7,7 @@ module RubyPushNotifications
|
|
7
7
|
# (http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202945)
|
8
8
|
#
|
9
9
|
class MPNSNotification
|
10
|
-
|
11
|
-
# @return [MPNSResponse]. MPNSResponse with the results from sending this notification.
|
12
|
-
attr_accessor :results
|
10
|
+
include RubyPushNotifications::NotificationResultsManager
|
13
11
|
|
14
12
|
# @return [Hash]. Payload to send.
|
15
13
|
# Toast :title => a bold message
|
@@ -16,6 +16,7 @@ module RubyPushNotifications
|
|
16
16
|
# @return [Array] Array of a MPNSResult for every receiver of the notification
|
17
17
|
# sent indicating the result of the operation.
|
18
18
|
attr_reader :results
|
19
|
+
alias_method :individual_results, :results
|
19
20
|
|
20
21
|
# Initializes the MPNSResponse and runs response parsing
|
21
22
|
#
|
@@ -32,7 +32,7 @@ module RubyPushNotifications
|
|
32
32
|
# @return [String]. The subscription status.
|
33
33
|
attr_accessor :subscription_status
|
34
34
|
|
35
|
-
def initialize(device_url, headers
|
35
|
+
def initialize(device_url, headers)
|
36
36
|
@device_url = device_url
|
37
37
|
@notification_status = headers[X_NOTIFICATION_STATUS]
|
38
38
|
@device_connection_status = headers[X_DEVICE_CONNECTION_STATUS]
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module RubyPushNotifications
|
2
|
+
# This module contains the required behavior expected by particular notifications
|
3
|
+
#
|
4
|
+
# @author Carlos Alonso
|
5
|
+
module NotificationResultsManager
|
6
|
+
extend Forwardable
|
7
|
+
|
8
|
+
def_delegators :@results, :success, :failed, :individual_results
|
9
|
+
|
10
|
+
# The corresponding object with the results from sending this notification
|
11
|
+
# that also will respond to #success, #failed and #individual_results
|
12
|
+
attr_accessor :results
|
13
|
+
end
|
14
|
+
end
|
@@ -2,28 +2,39 @@
|
|
2
2
|
module RubyPushNotifications
|
3
3
|
module APNS
|
4
4
|
describe APNSNotification do
|
5
|
-
describe 'building messages for each token' do
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
let(:device_tokens) { ['12', '34'] }
|
7
|
+
let(:data) { { a: 1 } }
|
8
|
+
let(:notification) { APNSNotification.new device_tokens, data }
|
9
|
+
let(:notif_id) { 1 }
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
11
|
+
it 'successfully creates the apns binary' do
|
12
|
+
json = JSON.dump data
|
13
|
+
expect do |b|
|
14
|
+
notification.each_message notif_id, &b
|
15
|
+
end.to yield_successive_args apns_binary(json, device_tokens[0], notif_id), apns_binary(json, device_tokens[1], notif_id + 1)
|
16
|
+
end
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
it 'caches the payload' do
|
19
|
+
expect(JSON).to receive(:dump).with(data).once.and_return 'dummy string'
|
20
|
+
notification.each_message(notif_id) {}
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'validates the data'
|
23
24
|
|
24
|
-
|
25
|
+
it 'validates the tokens'
|
25
26
|
|
26
|
-
|
27
|
+
it_behaves_like 'a proper results manager' do
|
28
|
+
let(:success_count) { 2 }
|
29
|
+
let(:failures_count) { 1 }
|
30
|
+
let(:individual_results) do
|
31
|
+
[
|
32
|
+
NO_ERROR_STATUS_CODE,
|
33
|
+
PROCESSING_ERROR_STATUS_CODE,
|
34
|
+
NO_ERROR_STATUS_CODE
|
35
|
+
]
|
36
|
+
end
|
37
|
+
let(:results) { APNSResults.new individual_results }
|
27
38
|
end
|
28
39
|
end
|
29
40
|
end
|
@@ -36,10 +36,10 @@ module RubyPushNotifications
|
|
36
36
|
pusher.push [notification]
|
37
37
|
end
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
39
|
+
describe 'results' do
|
40
|
+
before { pusher.push [notification] }
|
41
|
+
|
42
|
+
include_examples 'right results', 1, 0, [NO_ERROR_STATUS_CODE]
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
@@ -55,10 +55,10 @@ module RubyPushNotifications
|
|
55
55
|
pusher.push [notification]
|
56
56
|
end
|
57
57
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
58
|
+
describe 'results' do
|
59
|
+
before { pusher.push [notification] }
|
60
|
+
|
61
|
+
include_examples 'right results', 0, 1, [PROCESSING_ERROR_STATUS_CODE]
|
62
62
|
end
|
63
63
|
end
|
64
64
|
end
|
@@ -82,10 +82,10 @@ module RubyPushNotifications
|
|
82
82
|
pusher.push [notification]
|
83
83
|
end
|
84
84
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
85
|
+
describe 'results' do
|
86
|
+
before { pusher.push [notification] }
|
87
|
+
|
88
|
+
include_examples 'right results', 2, 0, [NO_ERROR_STATUS_CODE] * 2
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
@@ -109,10 +109,10 @@ module RubyPushNotifications
|
|
109
109
|
pusher.push [notification]
|
110
110
|
end
|
111
111
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
112
|
+
describe 'results' do
|
113
|
+
before { pusher.push [notification] }
|
114
|
+
|
115
|
+
include_examples 'right results', 1, 1, [PROCESSING_ERROR_STATUS_CODE, NO_ERROR_STATUS_CODE]
|
116
116
|
end
|
117
117
|
end
|
118
118
|
|
@@ -129,10 +129,10 @@ module RubyPushNotifications
|
|
129
129
|
pusher.push [notification]
|
130
130
|
end
|
131
131
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
132
|
+
describe 'results' do
|
133
|
+
before { pusher.push [notification] }
|
134
|
+
|
135
|
+
include_examples 'right results', 1, 1, [PROCESSING_ERROR_STATUS_CODE, NO_ERROR_STATUS_CODE]
|
136
136
|
end
|
137
137
|
end
|
138
138
|
|
@@ -149,10 +149,10 @@ module RubyPushNotifications
|
|
149
149
|
pusher.push [notification]
|
150
150
|
end
|
151
151
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
152
|
+
describe 'results' do
|
153
|
+
before { pusher.push [notification] }
|
154
|
+
|
155
|
+
include_examples 'right results', 1, 1, [NO_ERROR_STATUS_CODE, PROCESSING_ERROR_STATUS_CODE]
|
156
156
|
end
|
157
157
|
end
|
158
158
|
end
|
@@ -180,9 +180,8 @@ module RubyPushNotifications
|
|
180
180
|
end
|
181
181
|
|
182
182
|
it 'saves results' do
|
183
|
-
|
184
|
-
|
185
|
-
end.to change { notifications.map { |n| n.results } }.from([nil]*10).to([[NO_ERROR_STATUS_CODE]]*10)
|
183
|
+
pusher.push notifications
|
184
|
+
expect(notifications.map(&:individual_results)).to eq [[NO_ERROR_STATUS_CODE]] * 10
|
186
185
|
end
|
187
186
|
end
|
188
187
|
|
@@ -224,9 +223,8 @@ module RubyPushNotifications
|
|
224
223
|
end
|
225
224
|
|
226
225
|
it 'saves the statuses' do
|
227
|
-
|
228
|
-
|
229
|
-
end.to change { notifications.map { |n| n.results } }.from([nil]*10).to [
|
226
|
+
pusher.push notifications
|
227
|
+
expect(notifications.map(&:individual_results)).to eq [
|
230
228
|
[PROCESSING_ERROR_STATUS_CODE],
|
231
229
|
[NO_ERROR_STATUS_CODE],
|
232
230
|
[MISSING_DEVICE_TOKEN_STATUS_CODE],
|
@@ -275,9 +273,8 @@ module RubyPushNotifications
|
|
275
273
|
end
|
276
274
|
|
277
275
|
it 'saves the statuses' do
|
278
|
-
|
279
|
-
|
280
|
-
end.to change { notifications.map { |n| n.results } }.from([nil]*10).to [
|
276
|
+
pusher.push notifications
|
277
|
+
expect(notifications.map(&:individual_results)).to eq [
|
281
278
|
[PROCESSING_ERROR_STATUS_CODE],
|
282
279
|
[NO_ERROR_STATUS_CODE],
|
283
280
|
[MISSING_DEVICE_TOKEN_STATUS_CODE],
|
@@ -19,6 +19,19 @@ module RubyPushNotifications
|
|
19
19
|
# According to https://developer.android.com/google/gcm/server-ref.html#table1
|
20
20
|
it 'validates the data'
|
21
21
|
|
22
|
+
it_behaves_like 'a proper results manager' do
|
23
|
+
let(:success_count) { 2 }
|
24
|
+
let(:failures_count) { 1 }
|
25
|
+
let(:canonical_id) { 'abcd' }
|
26
|
+
let(:individual_results) { [GCMCanonicalIDResult.new(canonical_id)] }
|
27
|
+
let(:results) do
|
28
|
+
GCMResponse.new 200, JSON.dump(
|
29
|
+
success: success_count, failure: failures_count, results: [
|
30
|
+
registration_id: canonical_id
|
31
|
+
]
|
32
|
+
)
|
33
|
+
end
|
34
|
+
end
|
22
35
|
end
|
23
36
|
end
|
24
37
|
end
|
@@ -38,6 +38,16 @@ module RubyPushNotifications
|
|
38
38
|
|
39
39
|
it 'validates the data'
|
40
40
|
|
41
|
+
it_behaves_like 'a proper results manager' do
|
42
|
+
let(:notification) { build :mpns_notification }
|
43
|
+
let(:success_count) { 1 }
|
44
|
+
let(:failures_count) { 0 }
|
45
|
+
let(:device_url) { generate :mpns_device_url }
|
46
|
+
let(:individual_results) { [MPNSResultOK.new(device_url, {})] }
|
47
|
+
let(:results) do
|
48
|
+
MPNSResponse.new [{ code: 200, device_url: device_url, headers: {} }]
|
49
|
+
end
|
50
|
+
end
|
41
51
|
end
|
42
52
|
end
|
43
53
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
shared_examples 'right results' do |success, failed, individual_results|
|
2
|
+
it 'has the expected success value' do
|
3
|
+
expect(notification.success).to eq success
|
4
|
+
end
|
5
|
+
|
6
|
+
it 'has the expected failed value' do
|
7
|
+
expect(notification.failed).to eq failed
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'has the expected individual_results' do
|
11
|
+
expect(notification.individual_results).to eq individual_results
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
shared_examples 'a proper results manager' do
|
16
|
+
describe 'results management' do
|
17
|
+
before { notification.results = results }
|
18
|
+
|
19
|
+
it 'gives the success count' do
|
20
|
+
expect(notification.success).to eq success_count
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'gives the failures count' do
|
24
|
+
expect(notification.failed).to eq failures_count
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'gives the individual results' do
|
28
|
+
expect(notification.individual_results).to eq individual_results
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-push-notifications
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carlos Alonso
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: builder
|
@@ -119,6 +119,7 @@ files:
|
|
119
119
|
- lib/ruby-push-notifications/apns/apns_connection.rb
|
120
120
|
- lib/ruby-push-notifications/apns/apns_notification.rb
|
121
121
|
- lib/ruby-push-notifications/apns/apns_pusher.rb
|
122
|
+
- lib/ruby-push-notifications/apns/apns_results.rb
|
122
123
|
- lib/ruby-push-notifications/gcm.rb
|
123
124
|
- lib/ruby-push-notifications/gcm/gcm_connection.rb
|
124
125
|
- lib/ruby-push-notifications/gcm/gcm_error.rb
|
@@ -132,6 +133,7 @@ files:
|
|
132
133
|
- lib/ruby-push-notifications/mpns/mpns_pusher.rb
|
133
134
|
- lib/ruby-push-notifications/mpns/mpns_response.rb
|
134
135
|
- lib/ruby-push-notifications/mpns/mpns_result.rb
|
136
|
+
- lib/ruby-push-notifications/notification_results_manager.rb
|
135
137
|
- lib/ruby-push-notifications/version.rb
|
136
138
|
- ruby-push-notifications.gemspec
|
137
139
|
- spec/factories.rb
|
@@ -150,6 +152,7 @@ files:
|
|
150
152
|
- spec/spec_helper.rb
|
151
153
|
- spec/support/dummy.pem
|
152
154
|
- spec/support/factory_girl.rb
|
155
|
+
- spec/support/results_shared_examples.rb
|
153
156
|
homepage: https://github.com/calonso/ruby-push-notifications
|
154
157
|
licenses:
|
155
158
|
- MIT
|
@@ -191,4 +194,5 @@ test_files:
|
|
191
194
|
- spec/spec_helper.rb
|
192
195
|
- spec/support/dummy.pem
|
193
196
|
- spec/support/factory_girl.rb
|
197
|
+
- spec/support/results_shared_examples.rb
|
194
198
|
has_rdoc:
|