Push0r 0.3.1 → 0.4.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/lib/push0r/APNS/ApnsService.rb +52 -11
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce91f193ec033c63cc346d17b0f33d5cb88eb07c
|
4
|
+
data.tar.gz: 2ebcec3b1f598c26bde48ed7bbad1cd415bcc8bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c3cf872531d79e1390bd24deda798665139e9d0b877c8b93c7b22e5ab918fe8e7c96bb805b6f8ccbcadba7705d2b215d304fcbadd885a232e54ea4134f83778
|
7
|
+
data.tar.gz: 896726f6c6a06cf920edc2b9ebce22e090eee8e82f029a718545420f6564443c49bca4452f8136df93702dffe11ab52f47888edd4cfdc8d1215377eca6041323
|
@@ -51,8 +51,14 @@ module Push0r
|
|
51
51
|
# @see Service#end_push
|
52
52
|
def end_push
|
53
53
|
failed_messages = []
|
54
|
+
result = false
|
54
55
|
begin
|
55
|
-
|
56
|
+
begin
|
57
|
+
setup_ssl(true)
|
58
|
+
rescue SocketError => e
|
59
|
+
puts "Error: #{e}"
|
60
|
+
break
|
61
|
+
end
|
56
62
|
(result, error_message, error_code) = transmit_messages
|
57
63
|
if result == false
|
58
64
|
failed_messages << FailedMessage.new(error_code, error_message.receiver_token, error_message)
|
@@ -61,28 +67,63 @@ module Push0r
|
|
61
67
|
end
|
62
68
|
end while result != true
|
63
69
|
|
64
|
-
|
65
|
-
@ssl.close
|
66
|
-
end
|
67
|
-
unless @sock.nil?
|
68
|
-
@sock.close
|
69
|
-
end
|
70
|
+
close_ssl
|
70
71
|
|
71
72
|
@messages = [] ## reset
|
72
73
|
return [failed_messages, []]
|
73
74
|
end
|
74
75
|
|
76
|
+
# Calls the APNS feedback service and returns an array of expired push tokens
|
77
|
+
# @return [Array<String>] an array of expired push tokens
|
78
|
+
def get_feedback
|
79
|
+
tokens = []
|
80
|
+
|
81
|
+
begin
|
82
|
+
setup_ssl(true)
|
83
|
+
rescue SocketError => e
|
84
|
+
puts "Error: #{e}"
|
85
|
+
return tokens
|
86
|
+
end
|
87
|
+
|
88
|
+
if IO.select([@ssl], nil, nil, 0.5)
|
89
|
+
while line = @ssl.read(38)
|
90
|
+
f = line.unpack('N1n1H64')
|
91
|
+
time = Time.at(f[0])
|
92
|
+
token = f[2].scan(/.{8}/).join(" ")
|
93
|
+
tokens << token
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
close_ssl
|
98
|
+
|
99
|
+
return tokens
|
100
|
+
end
|
101
|
+
|
75
102
|
private
|
76
|
-
def setup_ssl
|
103
|
+
def setup_ssl(for_feedback = false)
|
104
|
+
close_ssl
|
77
105
|
ctx = OpenSSL::SSL::SSLContext.new
|
78
106
|
|
79
107
|
ctx.key = OpenSSL::PKey::RSA.new(@certificate_data, '')
|
80
108
|
ctx.cert = OpenSSL::X509::Certificate.new(@certificate_data)
|
81
|
-
|
82
|
-
|
109
|
+
|
110
|
+
unless for_feedback
|
111
|
+
@sock = TCPSocket.new(@sandbox_environment ? "gateway.sandbox.push.apple.com" : "gateway.push.apple.com", 2195)
|
112
|
+
else
|
113
|
+
@sock = TCPSocket.new(@sandbox_environment ? "feedback.sandbox.push.apple.com" : "feedback.push.apple.com", 2195)
|
114
|
+
end
|
83
115
|
@ssl = OpenSSL::SSL::SSLSocket.new(@sock, ctx)
|
84
116
|
@ssl.connect
|
85
117
|
end
|
118
|
+
|
119
|
+
def close_ssl
|
120
|
+
unless @ssl.nil?
|
121
|
+
@ssl.close
|
122
|
+
end
|
123
|
+
unless @sock.nil?
|
124
|
+
@sock.close
|
125
|
+
end
|
126
|
+
end
|
86
127
|
|
87
128
|
def reset_message(error_identifier)
|
88
129
|
index = @messages.find_index {|o| o.identifier == error_identifier}
|
@@ -150,7 +191,7 @@ module Push0r
|
|
150
191
|
|
151
192
|
@ssl.write(pushdata)
|
152
193
|
|
153
|
-
if IO.select([@ssl], nil, nil,
|
194
|
+
if IO.select([@ssl], nil, nil, 0.5)
|
154
195
|
begin
|
155
196
|
read_buffer = @ssl.read(6)
|
156
197
|
rescue Exception
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Push0r
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kai Straßmann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|