Class: ApnServer::Client
- Inherits:
-
Object
- Object
- ApnServer::Client
- Defined in:
- lib/apnserver/client.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#password ⇒ Object
Returns the value of attribute password.
-
#pem ⇒ Object
Returns the value of attribute pem.
-
#port ⇒ Object
Returns the value of attribute port.
Instance Method Summary collapse
- #connect! ⇒ Object
- #connected? ⇒ Boolean
- #disconnect! ⇒ Object
-
#initialize(pem, host = 'gateway.push.apple.com', port = 2195, pass = nil) ⇒ Client
constructor
A new instance of Client.
- #write(notification) ⇒ Object
Constructor Details
#initialize(pem, host = 'gateway.push.apple.com', port = 2195, pass = nil) ⇒ Client
Returns a new instance of Client.
8 9 10 |
# File 'lib/apnserver/client.rb', line 8 def initialize(pem, host = 'gateway.push.apple.com', port = 2195, pass = nil) @pem, @host, @port, @password = pem, host, port, pass end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
6 7 8 |
# File 'lib/apnserver/client.rb', line 6 def host @host end |
#password ⇒ Object
Returns the value of attribute password.
6 7 8 |
# File 'lib/apnserver/client.rb', line 6 def password @password end |
#pem ⇒ Object
Returns the value of attribute pem.
6 7 8 |
# File 'lib/apnserver/client.rb', line 6 def pem @pem end |
#port ⇒ Object
Returns the value of attribute port.
6 7 8 |
# File 'lib/apnserver/client.rb', line 6 def port @port end |
Instance Method Details
#connect! ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/apnserver/client.rb', line 12 def connect! raise "The path to your pem file is not set." unless self.pem raise "The path to your pem file does not exist!" unless File.exist?(self.pem) @context = OpenSSL::SSL::SSLContext.new @context.cert = OpenSSL::X509::Certificate.new(File.read(self.pem)) @context.key = OpenSSL::PKey::RSA.new(File.read(self.pem), self.password) @sock = TCPSocket.new(self.host, self.port.to_i) @ssl = OpenSSL::SSL::SSLSocket.new(@sock, @context) @ssl.connect return @sock, @ssl end |
#connected? ⇒ Boolean
39 40 41 |
# File 'lib/apnserver/client.rb', line 39 def connected? @ssl end |
#disconnect! ⇒ Object
27 28 29 30 31 32 |
# File 'lib/apnserver/client.rb', line 27 def disconnect! @ssl.close @sock.close @ssl = nil @sock = nil end |