apns_simple 1.0.0 → 1.0.1

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: b21f5930a8df2406544a6c54a4c054356466034b
4
- data.tar.gz: 4da2296c3c44a45f5aa639e576f918d98d688381
3
+ metadata.gz: 8ab64c50e081ffa4e0d9233da507a24c82d7fcd8
4
+ data.tar.gz: 4984dc7e23541b24026df63d0a4b53991d4637c4
5
5
  SHA512:
6
- metadata.gz: 86434817e68afae4e816270284168fcd98364bd0181aa37e2e9722e6e5a50f383d7997244a9f1eeb768fc81b27894350206d75473b813dff1c76564f95c22fba
7
- data.tar.gz: 5a2111b22dc30fd13d39f95b1de1a5b8429cc5382c13d100492c918d3b3715a7040c670d913888d0a7dcf5d6208e741dde209324bfa75ac1477d1e7fa34d7334
6
+ metadata.gz: 4a2ab7af1d60ac62b169bced7b57f9d2bb22e4ab5cae64c0d410fb5ea8dd655187094f0b88570ed57a015e828d7528f4d1e3a1b3ea43b6269d646a3b9b1ee4fa
7
+ data.tar.gz: b03c19f8c22807ab5209b89cbbfd5c224dddd1e5e59ac2f34d41b82ada91d5b7a6f139090cc91cc1bfb7c11a840852e9b213a85c5162ec0c0a87a038299395cd
@@ -8,6 +8,9 @@ module ApnsSimple
8
8
 
9
9
  attr_reader :ssl_context, :host, :port
10
10
 
11
+ DEFAULT_CERTIFICATE_PASSWORD = ''
12
+ DEFAULT_GATEWAY_URI = 'apn://gateway.push.apple.com:2195'
13
+ ERROR_BYTES_COUNT = 6
11
14
  COMMAND = 8
12
15
  CODES = {
13
16
  0 => 'No errors encountered',
@@ -35,15 +38,16 @@ module ApnsSimple
35
38
  @ssl_context = OpenSSL::SSL::SSLContext.new
36
39
  ssl_context.cert = cert
37
40
 
38
- passphrase = options[:passphrase] || ''
41
+ passphrase = options[:passphrase] || DEFAULT_CERTIFICATE_PASSWORD
39
42
  ssl_context.key = OpenSSL::PKey::RSA.new(certificate, passphrase)
40
43
 
41
- gateway_uri = options[:gateway_uri] || 'apn://gateway.push.apple.com:2195'
44
+ gateway_uri = options[:gateway_uri] || DEFAULT_GATEWAY_URI
42
45
  @host, @port = parse_gateway_uri(gateway_uri)
43
46
  end
44
47
 
45
48
  def push(notification)
46
49
  begin
50
+ notification.error = true
47
51
  sock = TCPSocket.new(host, port)
48
52
  ssl = OpenSSL::SSL::SSLSocket.new(sock, ssl_context)
49
53
  ssl.sync = true
@@ -53,15 +57,13 @@ module ApnsSimple
53
57
  ready = IO.select([ssl], [], [], TIMEOUT)
54
58
 
55
59
  unless ready
56
- notification.error = true
57
60
  notification.error_message = "No response from APNS server received in #{TIMEOUT} seconds. Exit by timeout."
58
61
  return
59
62
  end
60
63
 
61
64
  readable_ssl_socket = ready.first.first
62
65
 
63
- if (error = readable_ssl_socket.read(6))
64
- notification.error = true
66
+ if (error = readable_ssl_socket.read(ERROR_BYTES_COUNT))
65
67
  command, code, _index = error.unpack('ccN')
66
68
  if command == COMMAND
67
69
  notification.error_code = code
@@ -69,6 +71,8 @@ module ApnsSimple
69
71
  else
70
72
  notification.error_message = "Unknown command received from APNS server: #{command}"
71
73
  end
74
+ else
75
+ notification.error = false
72
76
  end
73
77
  ensure
74
78
  ssl.close if ssl
@@ -1,3 +1,3 @@
1
1
  module ApnsSimple
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.1'
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: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey Voronkov