lib/apns_simple/client.rb in apns_simple-1.0.1 vs lib/apns_simple/client.rb in apns_simple-1.1.0
- old
+ new
@@ -44,41 +44,39 @@
gateway_uri = options[:gateway_uri] || DEFAULT_GATEWAY_URI
@host, @port = parse_gateway_uri(gateway_uri)
end
def push(notification)
- begin
- notification.error = true
- sock = TCPSocket.new(host, port)
- ssl = OpenSSL::SSL::SSLSocket.new(sock, ssl_context)
- ssl.sync = true
- ssl.connect
- ssl.write(notification.payload)
+ notification.error = true
+ sock = TCPSocket.new(host, port)
+ ssl = OpenSSL::SSL::SSLSocket.new(sock, ssl_context)
+ ssl.connect
+ ssl.write(notification.payload)
+ ssl.flush
- ready = IO.select([ssl], [], [], TIMEOUT)
+ ready = IO.select([ssl], [], [], TIMEOUT)
- unless ready
- notification.error_message = "No response from APNS server received in #{TIMEOUT} seconds. Exit by timeout."
- return
- end
+ unless ready
+ notification.error_message = "No response from APNS server received in #{TIMEOUT} seconds. Exit by timeout."
+ return
+ end
- readable_ssl_socket = ready.first.first
+ readable_ssl_socket = ready.first.first
- if (error = readable_ssl_socket.read(ERROR_BYTES_COUNT))
- command, code, _index = error.unpack('ccN')
- if command == COMMAND
- notification.error_code = code
- notification.error_message = "CODE: #{code}, DESCRIPTION: #{CODES[code]}"
- else
- notification.error_message = "Unknown command received from APNS server: #{command}"
- end
+ if (error = readable_ssl_socket.read(ERROR_BYTES_COUNT))
+ command, code, _index = error.unpack('ccN')
+ if command == COMMAND
+ notification.error_code = code
+ notification.error_message = "CODE: #{code}, DESCRIPTION: #{CODES[code]}"
else
- notification.error = false
+ notification.error_message = "Unknown command received from APNS server: #{command}"
end
- ensure
- ssl.close if ssl
- sock.close if sock
+ else
+ notification.error = false
end
+ ensure
+ ssl.close if ssl
+ sock.close if sock
end
private
def parse_gateway_uri(uri)
\ No newline at end of file