Class: EventMachine::APN::Connection

Inherits:
EM::Connection
  • Object
show all
Defined in:
lib/em-apn/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Connection

Returns a new instance of Connection.



6
7
8
9
10
# File 'lib/em-apn/connection.rb', line 6

def initialize(*args)
  super
  @client = args.last
  @disconnected = false
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



4
5
6
# File 'lib/em-apn/connection.rb', line 4

def client
  @client
end

Instance Method Details

#connection_completedObject



24
25
26
# File 'lib/em-apn/connection.rb', line 24

def connection_completed
  EM::APN.logger.info("Connection completed")
end

#disconnected?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/em-apn/connection.rb', line 12

def disconnected?
  @disconnected
end

#post_initObject



16
17
18
19
20
21
22
# File 'lib/em-apn/connection.rb', line 16

def post_init
  start_tls(
    :private_key_file => client.key,
    :cert_chain_file  => client.cert,
    :verify_peer      => false
  )
end

#receive_data(data) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/em-apn/connection.rb', line 28

def receive_data(data)
  data_array = data.unpack("ccN")
  error_response = ErrorResponse.new(*data_array)
  EM::APN.logger.warn(error_response.to_s)

  if client.error_callback
    client.error_callback.call(error_response)
  end
end

#unbindObject



38
39
40
41
42
43
# File 'lib/em-apn/connection.rb', line 38

def unbind
  @disconnected = true

  EM::APN.logger.info("Connection closed")
  client.close_callback.call if client.close_callback
end