Class: Rapns::Daemon::Apns::Delivery

Inherits:
Delivery
  • Object
show all
Defined in:
lib/rapns/daemon/apns/delivery.rb

Constant Summary collapse

SELECT_TIMEOUT =
0.2
ERROR_TUPLE_BYTES =
6
APN_ERRORS =
{
  1 => "Processing error",
  2 => "Missing device token",
  3 => "Missing topic",
  4 => "Missing payload",
  5 => "Missing token size",
  6 => "Missing topic size",
  7 => "Missing payload size",
  8 => "Invalid token",
  255 => "None (unknown error)"
}

Instance Method Summary collapse

Methods inherited from Delivery

#mark_delivered, #mark_failed, perform, #retry_after, #retry_exponentially

Methods included from Reflectable

#reflect

Constructor Details

#initialize(app, conneciton, notification) ⇒ Delivery

Returns a new instance of Delivery.



19
20
21
22
23
# File 'lib/rapns/daemon/apns/delivery.rb', line 19

def initialize(app, conneciton, notification)
  @app = app
  @connection = conneciton
  @notification = notification
end

Instance Method Details

#performObject



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rapns/daemon/apns/delivery.rb', line 25

def perform
  begin
    @connection.write(@notification.to_binary)
    check_for_error if Rapns.config.check_for_errors
    mark_delivered
    Rapns.logger.info("[#{@app.name}] #{@notification.id} sent to #{@notification.device_token}")
  rescue Rapns::DeliveryError, Rapns::Apns::DisconnectionError => error
    mark_failed(error.code, error.description)
    raise
  end
end