apns_simple 1.0.0 → 1.0.1
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/lib/apns_simple/client.rb +9 -5
- data/lib/apns_simple/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ab64c50e081ffa4e0d9233da507a24c82d7fcd8
|
4
|
+
data.tar.gz: 4984dc7e23541b24026df63d0a4b53991d4637c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a2ab7af1d60ac62b169bced7b57f9d2bb22e4ab5cae64c0d410fb5ea8dd655187094f0b88570ed57a015e828d7528f4d1e3a1b3ea43b6269d646a3b9b1ee4fa
|
7
|
+
data.tar.gz: b03c19f8c22807ab5209b89cbbfd5c224dddd1e5e59ac2f34d41b82ada91d5b7a6f139090cc91cc1bfb7c11a840852e9b213a85c5162ec0c0a87a038299395cd
|
data/lib/apns_simple/client.rb
CHANGED
@@ -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] ||
|
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(
|
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
|
data/lib/apns_simple/version.rb
CHANGED