ruby-push-notifications 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b5f52999ec595b97b1c2dc8628c666d9d16e2cc7
4
- data.tar.gz: c93580db1db0e4a7704f2c7b3f0661482d03b27c
3
+ metadata.gz: 46af4db49981e818c075e9eb41dd4c2638851dd4
4
+ data.tar.gz: cfa87e1a6d3611d44abf9164cf8283b6f7117039
5
5
  SHA512:
6
- metadata.gz: 3373347fd40e9b6c79e216b141d7a4457a2a7a42287c0fd53a339e3f83433165600434d3e937db72210e4faa355a4d7fbdcaa55fcbfa34dad5c227731897c5f5
7
- data.tar.gz: 411b301afbe3db77736f5942ffd7dfbd4a8eb7348df6f3915976f92b540f3ec97d364ff1660198b5e49ad06b7271f91a5853648cecb2b23def8f1b365c0d9194
6
+ metadata.gz: 0237b54486f4c8186553fa31ed4d29bc1dc1ff20183371a759a3232b8c767a506ae3a22f561afb89f5e792ce5936fd7f35cc1ea2e6a2ac3f557fd9c16147f751
7
+ data.tar.gz: 591583bcb8d928476bd47272993739c5b597cf2d8002bb4ddc39f9557fb363fccd58ff9368c455b1a712dd0d8fcccca5c3f0bfdf3fdf4df09a9e686a1e1d38e0
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby-push-notifications (0.3.1)
4
+ ruby-push-notifications (0.4.0)
5
5
  builder (~> 3.0)
6
6
 
7
7
  GEM
@@ -64,3 +64,6 @@ DEPENDENCIES
64
64
  rspec (~> 3.2)
65
65
  ruby-push-notifications!
66
66
  webmock (~> 1.20)
67
+
68
+ BUNDLED WITH
69
+ 1.11.2
@@ -8,10 +8,11 @@ tokens = [
8
8
  'First token here',
9
9
  'Second token here'
10
10
  ]
11
+ password = nil # optional password for .pem file
11
12
 
12
13
  notification = RubyPushNotifications::APNS::APNSNotification.new tokens, { aps: { alert: 'Hello APNS World!', sound: 'true', badge: 1 } }
13
14
 
14
- pusher = RubyPushNotifications::APNS::APNSPusher.new(File.read('/path/to/your/apps/certificate.pem'), true)
15
+ pusher = RubyPushNotifications::APNS::APNSPusher.new(File.read('/path/to/your/apps/certificate.pem'), true, password) # enter the password if present
15
16
  pusher.push [notification]
16
17
  p 'Notification sending results:'
17
18
  p "Success: #{notification.success}, Failed: #{notification.failed}"
@@ -27,9 +27,9 @@ module RubyPushNotifications
27
27
  # @param cert [String]. Contents of the PEM encoded certificate
28
28
  # @param sandbox [Boolean]. Whether to use the sandbox environment or not.
29
29
  # @return [APNSConnection]. The recently stablished connection.
30
- def self.open(cert, sandbox)
30
+ def self.open(cert, sandbox, pass = nil)
31
31
  ctx = OpenSSL::SSL::SSLContext.new
32
- ctx.key = OpenSSL::PKey::RSA.new cert
32
+ ctx.key = OpenSSL::PKey::RSA.new cert, pass
33
33
  ctx.cert = OpenSSL::X509::Certificate.new cert
34
34
 
35
35
  h = host sandbox
@@ -67,7 +67,7 @@ module RubyPushNotifications
67
67
  # @return [String]. Binary representation of the notification's payload.
68
68
  def payload
69
69
  @encoded_payload ||= -> {
70
- json = JSON.dump(@data).force_encoding 'ascii-8bit'
70
+ json = (@data.respond_to?(:to_json) ? @data.to_json : JSON.dump(@data)).force_encoding 'ascii-8bit'
71
71
  [2, json.bytesize, json].pack 'cna*'
72
72
  }.call
73
73
  end
@@ -15,8 +15,9 @@ module RubyPushNotifications
15
15
 
16
16
  # @param certificate [String]. The PEM encoded APNS certificate.
17
17
  # @param sandbox [Boolean]. Whether the certificate is an APNS sandbox or not.
18
- def initialize(certificate, sandbox)
18
+ def initialize(certificate, sandbox, password = nil)
19
19
  @certificate = certificate
20
+ @pass = password
20
21
  @sandbox = sandbox
21
22
  end
22
23
 
@@ -30,7 +31,7 @@ module RubyPushNotifications
30
31
  #
31
32
  # @param notifications [Array]. All the APNSNotifications to be sent.
32
33
  def push(notifications)
33
- conn = APNSConnection.open @certificate, @sandbox
34
+ conn = APNSConnection.open @certificate, @sandbox, @pass
34
35
 
35
36
  binaries = notifications.each_with_object([]) do |notif, binaries|
36
37
  notif.each_message(binaries.count) do |msg|
@@ -60,7 +61,7 @@ module RubyPushNotifications
60
61
  results.slice! err[2]..-1
61
62
  results << err[1]
62
63
  i = err[2]
63
- conn = APNSConnection.open @certificate, @sandbox
64
+ conn = APNSConnection.open @certificate, @sandbox, @pass
64
65
  end
65
66
  else
66
67
  results << NO_ERROR_STATUS_CODE
@@ -1,3 +1,3 @@
1
1
  module RubyPushNotifications
2
- VERSION = '0.3.1'
2
+ VERSION = '0.4.0'
3
3
  end
@@ -20,7 +20,13 @@ module RubyPushNotifications
20
20
  end
21
21
 
22
22
  it 'returns an instance of APNSConnection' do
23
- expect(APNSConnection.open cert, true).to be_a APNSConnection
23
+ expect(APNSConnection.open(cert, true)).to be_a APNSConnection
24
+ end
25
+
26
+ it 'sets the password for pem file' do
27
+ expect(OpenSSL::SSL::SSLSocket).to receive(:new).with(tcp_socket, an_instance_of(OpenSSL::SSL::SSLContext)).and_return ssl_socket
28
+ expect(OpenSSL::PKey::RSA).to receive(:new).with(cert, 'password')
29
+ expect(APNSConnection.open(cert, true, 'password')).to be_a APNSConnection
24
30
  end
25
31
  end
26
32
 
@@ -17,6 +17,7 @@ module RubyPushNotifications
17
17
 
18
18
  it 'caches the payload' do
19
19
  expect(JSON).to receive(:dump).with(data).once.and_return 'dummy string'
20
+ allow(data).to receive(:respond_to?).with(:to_json).and_return(false)
20
21
  notification.each_message(notif_id) {}
21
22
  end
22
23
 
@@ -1,4 +1,3 @@
1
-
2
1
  module RubyPushNotifications
3
2
  module APNS
4
3
  describe APNSPusher do
@@ -10,7 +9,7 @@ module RubyPushNotifications
10
9
  let(:data) { { a: 1 } }
11
10
 
12
11
  before do
13
- allow(APNSConnection).to receive(:open).with(certificate, sandbox).and_return connection
12
+ allow(APNSConnection).to receive(:open).with(certificate, sandbox, nil).and_return connection
14
13
  end
15
14
 
16
15
  describe '#push' do
@@ -94,7 +93,7 @@ module RubyPushNotifications
94
93
  let(:connection2) { instance_double(APNSConnection).as_null_object }
95
94
 
96
95
  before do
97
- allow(APNSConnection).to receive(:open).with(certificate, sandbox).and_return connection, connection2
96
+ allow(APNSConnection).to receive(:open).with(certificate, sandbox, nil).and_return connection, connection2
98
97
  end
99
98
 
100
99
  context 'failing first' do
@@ -198,7 +197,7 @@ module RubyPushNotifications
198
197
  allow(connection).to receive(:read).with(6).and_return [8, PROCESSING_ERROR_STATUS_CODE, 0].pack('ccN')
199
198
  allow(connection2).to receive(:read).with(6).and_return [8, MISSING_DEVICE_TOKEN_STATUS_CODE, 2].pack('ccN')
200
199
  allow(connection3).to receive(:read).with(6).and_return [8, INVALID_TOPIC_SIZE_STATUS_CODE, 9].pack('ccN')
201
- allow(APNSConnection).to receive(:open).with(certificate, sandbox).and_return connection, connection2, connection3, connection4
200
+ allow(APNSConnection).to receive(:open).with(certificate, sandbox, nil).and_return connection, connection2, connection3, connection4
202
201
  end
203
202
 
204
203
  it 'repones the connection' do
@@ -250,7 +249,7 @@ module RubyPushNotifications
250
249
  allow(connection).to receive(:read).with(6).and_return [8, PROCESSING_ERROR_STATUS_CODE, 0].pack('ccN')
251
250
  allow(connection2).to receive(:read).with(6).and_return [8, MISSING_DEVICE_TOKEN_STATUS_CODE, 2].pack('ccN')
252
251
  allow(connection3).to receive(:read).with(6).and_return [8, INVALID_TOPIC_SIZE_STATUS_CODE, 9].pack('ccN')
253
- allow(APNSConnection).to receive(:open).with(certificate, sandbox).and_return connection, connection2, connection3, connection4
252
+ allow(APNSConnection).to receive(:open).with(certificate, sandbox, nil).and_return connection, connection2, connection3, connection4
254
253
  end
255
254
 
256
255
  it 'repones the connection' do
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.3.1
4
+ version: 0.4.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-05-26 00:00:00.000000000 Z
11
+ date: 2016-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: builder