Class: Mameapns::Session::Deliver
- Inherits:
-
Mameapns::Session
- Object
- Mameapns::Session
- Mameapns::Session::Deliver
- Defined in:
- lib/mameapns/session/deliver.rb
Constant Summary collapse
- SELECT_TIMEOUT =
0.5
- 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 Attribute Summary
Attributes inherited from Mameapns::Session
#connection, #host, #interruptible_sleep, #port, #queue, #ssl_cert, #ssl_cert_key, #ssl_cert_pass
Instance Method Summary collapse
Methods inherited from Mameapns::Session
#close, #connect, #end_session, #handle_error, #handle_sent, #initialize, #on_error, #on_exception, #on_sent, #push, #read, #reconnect, #running?, #select, #start, #stop, #wait_stop, #write
Constructor Details
This class inherits a constructor from Mameapns::Session
Instance Method Details
#check_for_error(notification) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/mameapns/session/deliver.rb', line 42 def check_for_error(notification) if select(SELECT_TIMEOUT) if tuple = read(ERROR_TUPLE_BYTES) cmd, code, notification_id = tuple.unpack("ccN") description = APN_ERRORS[code.to_i] || "Unknown error." handle_error(notification, Mameapns::DeliveryError.new(code, description)) else handle_error(notification, Mameapns::DisconnectionError.new) end begin # エラーをうけとったらreconnectする。 reconnect end end end |
#deliver(notification) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/mameapns/session/deliver.rb', line 34 def deliver(notification) write(notification.to_binary) check_for_error(notification) handle_sent(notification) end |
#start_session ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/mameapns/session/deliver.rb', line 20 def start_session connect while notification = queue.pop begin deliver(notification) rescue ConnectionError => e handle_error(notification, e) end end close end |