lib/lead_zeppelin/apns/application.rb in lead_zeppelin-0.1.3 vs lib/lead_zeppelin/apns/application.rb in lead_zeppelin-0.1.4
- old
+ new
@@ -2,14 +2,14 @@
module APNS
class Application
CONNECTION_POOL_SIZE = 5
CONNECTION_POOL_TIMEOUT = 5
- attr_reader :name
+ attr_reader :identifier
- def initialize(name, opts={})
- @name = name
+ def initialize(identifier, opts={})
+ @identifier = identifier
@opts = opts
@ssl_context = OpenSSL::SSL::SSLContext.new
if opts[:p12]
@@ -26,11 +26,27 @@
def connect
cp_args = {size: (@opts[:connection_pool_size] || CONNECTION_POOL_SIZE),
timeout: (@opts[:connection_pool_timeout] || CONNECTION_POOL_TIMEOUT)}
- @gateway_connection_pool = ConnectionPool.new(cp_args) do
- Gateway.new @ssl_context, (@opts[:gateway_opts] || {}).merge(error_block: @opts[:error_block], application_name: @name)
+ begin
+ @gateway_connection_pool = ConnectionPool.new(cp_args) do
+ Gateway.new @ssl_context, (@opts[:gateway_opts] || {}).merge(notification_error_block: @opts[:notification_error_block],
+ certificate_error_block: @opts[:certificate_error_block],
+ application_identifier: @identifier)
+ end
+
+ rescue OpenSSL::SSL::SSLError => e
+ if e.message =~ /alert certificate unknown/
+ Logger.warn "bad certificate for #{@identifier}, failed to connect"
+
+ if @opts[:certificate_error_block].nil?
+ Logger.warn "removing application #{@identifier} from the client due to bad certificate"
+ APNS.client.remove_application @identifier
+ else
+ @opts[:certificate_error_block].call @identifier
+ end
+ end
end
end
def message(device_id, message, opts={})
connect if @gateway_connection_pool.nil?
\ No newline at end of file