Class: EventMachine::ApnManager::Connection
- Inherits:
-
EM::Connection
- Object
- EM::Connection
- EventMachine::ApnManager::Connection
- Defined in:
- lib/em_apn_manager/connection.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #connection_completed ⇒ Object
- #disconnected? ⇒ Boolean
-
#initialize(*args) ⇒ Connection
constructor
A new instance of Connection.
- #post_init ⇒ Object
- #receive_data(data) ⇒ Object
- #unbind ⇒ Object
Constructor Details
#initialize(*args) ⇒ Connection
Returns a new instance of Connection.
10 11 12 13 14 |
# File 'lib/em_apn_manager/connection.rb', line 10 def initialize(*args) super @client = args.last @disconnected = false end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
8 9 10 |
# File 'lib/em_apn_manager/connection.rb', line 8 def client @client end |
Instance Method Details
#connection_completed ⇒ Object
36 37 38 39 40 |
# File 'lib/em_apn_manager/connection.rb', line 36 def connection_completed EM::ApnManager.logger.info("Connection completed") client.open_callback.call if client.open_callback end |
#disconnected? ⇒ Boolean
16 17 18 |
# File 'lib/em_apn_manager/connection.rb', line 16 def disconnected? @disconnected end |
#post_init ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/em_apn_manager/connection.rb', line 20 def post_init EM::ApnManager.logger.info("Connecting... #{client.gateway} for #{client.environment}") start_tls( :private_key_file => client.cert, :cert_chain_file => client.cert, :verify_peer => false ) end |
#receive_data(data) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/em_apn_manager/connection.rb', line 29 def receive_data(data) data_array = data.unpack("ccN") error_response = ErrorResponse.new(*data_array) EM::ApnManager.logger.warn(error_response.to_s) client.error_callback.call(error_response) if client.error_callback end |
#unbind ⇒ Object
42 43 44 45 46 47 |
# File 'lib/em_apn_manager/connection.rb', line 42 def unbind EM::ApnManager.logger.info("Connection closed") @disconnected = true client.close_callback.call if client.close_callback end |