lib/apn_client/delivery.rb in apn_client-0.0.1 vs lib/apn_client/delivery.rb in apn_client-0.0.2
- old
+ new
@@ -2,11 +2,11 @@
require 'apn_client/message'
require 'apn_client/connection'
module ApnClient
class Delivery
- attr_accessor :messages, :callbacks, :consecutive_failure_limit, :exception_limit, :sleep_on_exception,
+ attr_accessor :messages, :callbacks, :consecutive_failure_limit, :exception_limit, :sleep_on_exception, :connection_config,
:exception_count, :success_count, :failure_count, :consecutive_failure_count,
:started_at, :finished_at
# Creates a new APN delivery
#
@@ -42,16 +42,19 @@
end
private
def initialize_options(options)
- NamedArgs.assert_valid!(options, :optional => [:callbacks, :consecutive_failure_limit, :exception_limit, :sleep_on_exception])
+ NamedArgs.assert_valid!(options,
+ :optional => [:callbacks, :consecutive_failure_limit, :exception_limit, :sleep_on_exception],
+ :required => [:connection])
NamedArgs.assert_valid!(options[:callbacks], :optional => [:on_write, :on_error, :on_nil_select, :on_read_exception, :on_exception, :on_failure])
self.callbacks = options[:callbacks]
self.consecutive_failure_limit = options[:consecutive_failure_limit] || 10
self.exception_limit = options[:exception_limit] || 3
- self.sleep_on_exception = options[:sleep_on_exception] || 1
+ self.sleep_on_exception = options[:sleep_on_exception] || 1
+ self.connection_config = options[:connection]
end
def current_message
return @current_message if @current_message
next_message!
@@ -73,10 +76,10 @@
close_connection
end
end
def connection
- @connection ||= Connection.new(self.class.connection_config)
+ @connection ||= Connection.new(connection_config)
end
def close_connection
@connection.close if @connection
@connection = nil