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, host = 'gateway.push.apple.com', port = 2195, pass = nil) ⇒ Client

Returns a new instance of Client.



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

def initialize(pem, host = 'gateway.push.apple.com', port = 2195, pass = nil)
  @pem, @host, @port, @password = pem, host, port, pass
end

Instance Attribute Details

#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

#hostObject

Returns the value of attribute host.



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

def host
  @host
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

#portObject

Returns the value of attribute port.



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

def port
  @port
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(host, 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