Class: ApnMachine::Server::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/apnmachine/server/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pem, password = nil, apn_host = 'gateway.push.apple.com', apn_port = 2195) ⇒ Client

Returns a new instance of Client.



6
7
8
# File 'lib/apnmachine/server/client.rb', line 6

def initialize(pem, password = nil, apn_host = 'gateway.push.apple.com', apn_port = 2195)
  @pem, @pasword, @apn_host, @apn_port = pem, password, apn_host, apn_port
end

Instance Attribute Details

#apn_hostObject

Returns the value of attribute apn_host.



4
5
6
# File 'lib/apnmachine/server/client.rb', line 4

def apn_host
  @apn_host
end

#apn_portObject

Returns the value of attribute apn_port.



4
5
6
# File 'lib/apnmachine/server/client.rb', line 4

def apn_port
  @apn_port
end

#certObject

Returns the value of attribute cert.



4
5
6
# File 'lib/apnmachine/server/client.rb', line 4

def cert
  @cert
end

#close_callbackObject

Returns the value of attribute close_callback.



4
5
6
# File 'lib/apnmachine/server/client.rb', line 4

def close_callback
  @close_callback
end

#keyObject

Returns the value of attribute key.



4
5
6
# File 'lib/apnmachine/server/client.rb', line 4

def key
  @key
end

#passwordObject

Returns the value of attribute password.



4
5
6
# File 'lib/apnmachine/server/client.rb', line 4

def password
  @password
end

#pemObject

Returns the value of attribute pem.



4
5
6
# File 'lib/apnmachine/server/client.rb', line 4

def pem
  @pem
end

Instance Method Details

#connect!Object



10
11
12
13
14
15
# File 'lib/apnmachine/server/client.rb', line 10

def connect!
  raise "The path to your pem file is not set." unless @pem
  raise "The path to your pem file does not exist!" unless File.exist?(@pem)
  @key, @cert = @pem, @pem
  @connection = EM.connect(apn_host, apn_port, ApnMachine::Server::ServerConnection, self)
end

#connected?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/apnmachine/server/client.rb', line 26

def connected?
  @connection.connected?
end

#disconnect!Object



17
18
19
# File 'lib/apnmachine/server/client.rb', line 17

def disconnect!
  @connection.close_connection
end

#on_close(&block) ⇒ Object



34
35
36
# File 'lib/apnmachine/server/client.rb', line 34

def on_close(&block)
  @close_callback = block
end

#on_error(&block) ⇒ Object



30
31
32
# File 'lib/apnmachine/server/client.rb', line 30

def on_error(&block)
  @error_callback = block
end

#write(notif_bin) ⇒ Object



21
22
23
24
# File 'lib/apnmachine/server/client.rb', line 21

def write(notif_bin)
  Config.logger.debug "#{Time.now} [#{host}:#{port}] New notif"
  @connection.send_data(notif_bin)
end