apns_simple 0.7.0 → 0.8.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 13495bdc2326149e669f53bf4e903bc60dc21884
4
- data.tar.gz: 6b843d787e0db08bf2f7926ec5861d6367ffbdbb
3
+ metadata.gz: 458059ecb443c898d82d6f7bce8f9d6c1cd79386
4
+ data.tar.gz: e90411dc5d34a7891c2541c37314ebf243f3dbb0
5
5
  SHA512:
6
- metadata.gz: 89e66bc31760f4f109408eb2e838042ced0395483ac3293e8abe466eaa8940bca14b11693b43ac48db35811537291123f4631cdfb01d778850800954a621f675
7
- data.tar.gz: 88d9af28a6059906f4afa40ff4d8794990e62ba008127b53e8a8019ee7eb76d501c6bd5783385ad1cbd7286f006bf7e0bd4e8b60f131bc498a1c80dca0b621ae
6
+ metadata.gz: fdd5ab6692345cd1c317073120775e4d250228d8795b27b7fec998fbb465d3f42fa0496ee8bf19c430a13224f9379edcb73977ed15582c3afb32f2a05798a28d
7
+ data.tar.gz: 2740ceaf52a4e12934ab9e1e36ab687e2c17967e4047b4e18dfa2c817eadfd5bd199ad09e4d27ef37ef6ba72403c3df273e43e41e609d033d8e6fd82d88f1fa4
data/lib/apns_simple.rb CHANGED
@@ -3,5 +3,4 @@ require_relative 'apns_simple/notification'
3
3
  require_relative 'apns_simple/version'
4
4
 
5
5
  module ApnsSimple
6
- class CertificateActivenessTimeError < StandardError; end
7
6
  end
@@ -4,7 +4,9 @@ require 'socket'
4
4
  module ApnsSimple
5
5
  class Client
6
6
 
7
- attr_reader :certificate, :ssl_context, :host, :port
7
+ class CertificateActivenessTimeError < StandardError; end
8
+
9
+ attr_reader :ssl_context, :host, :port
8
10
 
9
11
  COMMAND = 8
10
12
  CODES = {
@@ -22,10 +24,18 @@ module ApnsSimple
22
24
  }
23
25
 
24
26
  def initialize(options)
25
- @certificate = options.fetch(:certificate)
26
- passphrase = options[:passphrase] || ''
27
+ certificate = options.fetch(:certificate)
28
+ current_time = Time.now.utc
29
+ cert = OpenSSL::X509::Certificate.new(certificate)
30
+ if current_time < cert.not_before || current_time > cert.not_after
31
+ raise CertificateActivenessTimeError, "CURRENT_TIME: #{current_time}, NOT_BEFORE: #{cert.not_before}, NOT_AFTER: #{cert.not_after}"
32
+ end
33
+
27
34
  @ssl_context = OpenSSL::SSL::SSLContext.new
28
- @ssl_context.key = OpenSSL::PKey::RSA.new(certificate, passphrase)
35
+ ssl_context.cert = cert
36
+
37
+ passphrase = options[:passphrase] || ''
38
+ ssl_context.key = OpenSSL::PKey::RSA.new(certificate, passphrase)
29
39
 
30
40
  gateway_uri = options[:gateway_uri] || 'apn://gateway.push.apple.com:2195'
31
41
  @host, @port = parse_gateway_uri(gateway_uri)
@@ -33,12 +43,6 @@ module ApnsSimple
33
43
 
34
44
  def push(notification)
35
45
  begin
36
- current_time = Time.now.utc
37
- cert = OpenSSL::X509::Certificate.new(certificate)
38
- if current_time < cert.not_before || current_time > cert.not_after
39
- raise CertificateActivenessTimeError, "CURRENT_TIME: #{current_time}, NOT_BEFORE: #{cert.not_before}, NOT_AFTER: #{cert.not_after}"
40
- end
41
- ssl_context.cert = cert
42
46
  sock = TCPSocket.new(host, port)
43
47
  ssl = OpenSSL::SSL::SSLSocket.new(sock, ssl_context)
44
48
  ssl.connect
@@ -1,3 +1,3 @@
1
1
  module ApnsSimple
2
- VERSION = '0.7.0'
2
+ VERSION = '0.8.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apns_simple
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey Voronkov