class ApnMachine::Server::Client

Attributes

apn_host[RW]
apn_port[RW]
cert[RW]
close_callback[RW]
key[RW]
password[RW]
pem[RW]

Public Class Methods

new(pem, password = nil, apn_host = 'gateway.push.apple.com', apn_port = 2195) click to toggle source
# 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

Public Instance Methods

connect!() click to toggle source
# 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?() click to toggle source
# File lib/apnmachine/server/client.rb, line 26
def connected?
  @connection.connected?
end
disconnect!() click to toggle source
# File lib/apnmachine/server/client.rb, line 17
def disconnect!
  @connection.close_connection
end
on_close(&block) click to toggle source
# File lib/apnmachine/server/client.rb, line 34
def on_close(&block)
  @close_callback = block
end
on_error(&block) click to toggle source
# File lib/apnmachine/server/client.rb, line 30
def on_error(&block)
  @error_callback = block
end
write(notif_bin) click to toggle source
# 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