Class: ApnClient::Delivery

Inherits:
Object
  • Object
show all
Defined in:
lib/apn_client/delivery.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(messages, options = {}) ⇒ Delivery

Creates a new APN delivery

Parameters:

  • messages (#next)

    should be Enumerator type object that responds to #next. If it’s an Array #shift will be used instead.



10
11
12
13
14
15
16
17
# File 'lib/apn_client/delivery.rb', line 10

def initialize(messages, options = {})
  self.messages = messages
  initialize_options(options)
  self.exception_count = 0
  self.success_count = 0
  self.failure_count = 0
  self.consecutive_failure_count = 0
end

Instance Attribute Details

#callbacksObject

Returns the value of attribute callbacks.



3
4
5
# File 'lib/apn_client/delivery.rb', line 3

def callbacks
  @callbacks
end

#connection_configObject

Returns the value of attribute connection_config.



3
4
5
# File 'lib/apn_client/delivery.rb', line 3

def connection_config
  @connection_config
end

#consecutive_failure_countObject

Returns the value of attribute consecutive_failure_count.



3
4
5
# File 'lib/apn_client/delivery.rb', line 3

def consecutive_failure_count
  @consecutive_failure_count
end

#consecutive_failure_limitObject

Returns the value of attribute consecutive_failure_limit.



3
4
5
# File 'lib/apn_client/delivery.rb', line 3

def consecutive_failure_limit
  @consecutive_failure_limit
end

#exception_countObject

Returns the value of attribute exception_count.



3
4
5
# File 'lib/apn_client/delivery.rb', line 3

def exception_count
  @exception_count
end

#exception_limitObject

Returns the value of attribute exception_limit.



3
4
5
# File 'lib/apn_client/delivery.rb', line 3

def exception_limit
  @exception_limit
end

#failure_countObject

Returns the value of attribute failure_count.



3
4
5
# File 'lib/apn_client/delivery.rb', line 3

def failure_count
  @failure_count
end

#finished_atObject

Returns the value of attribute finished_at.



3
4
5
# File 'lib/apn_client/delivery.rb', line 3

def finished_at
  @finished_at
end

#messagesObject

Returns the value of attribute messages.



3
4
5
# File 'lib/apn_client/delivery.rb', line 3

def messages
  @messages
end

#sleep_on_exceptionObject

Returns the value of attribute sleep_on_exception.



3
4
5
# File 'lib/apn_client/delivery.rb', line 3

def sleep_on_exception
  @sleep_on_exception
end

#started_atObject

Returns the value of attribute started_at.



3
4
5
# File 'lib/apn_client/delivery.rb', line 3

def started_at
  @started_at
end

#success_countObject

Returns the value of attribute success_count.



3
4
5
# File 'lib/apn_client/delivery.rb', line 3

def success_count
  @success_count
end

Instance Method Details

#elapsedObject



28
29
30
31
32
33
34
# File 'lib/apn_client/delivery.rb', line 28

def elapsed
  if started_at
    finished_at ? (finished_at - started_at) : (Time.now - started_at)
  else
    0
  end
end

#process!Object



19
20
21
22
23
24
25
26
# File 'lib/apn_client/delivery.rb', line 19

def process!
  self.started_at = Time.now
  while current_message && consecutive_failure_count < consecutive_failure_limit
    process_one_message!
  end
  close_connection
  self.finished_at = Time.now
end

#total_countObject



36
37
38
# File 'lib/apn_client/delivery.rb', line 36

def total_count
  success_count + failure_count
end