Class: APNS::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/mercurius/apns/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port, pem) ⇒ Connection

Returns a new instance of Connection.



5
6
7
8
9
# File 'lib/mercurius/apns/connection.rb', line 5

def initialize(host, port, pem)
  @host = host
  @port = port
  @pem = pem
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



3
4
5
# File 'lib/mercurius/apns/connection.rb', line 3

def host
  @host
end

#pemObject (readonly)

Returns the value of attribute pem.



3
4
5
# File 'lib/mercurius/apns/connection.rb', line 3

def pem
  @pem
end

#portObject (readonly)

Returns the value of attribute port.



3
4
5
# File 'lib/mercurius/apns/connection.rb', line 3

def port
  @port
end

Instance Method Details

#closeObject



17
18
19
20
# File 'lib/mercurius/apns/connection.rb', line 17

def close
  @ssl.close if @ssl
  @socket.close if @socket
end

#closed?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/mercurius/apns/connection.rb', line 22

def closed?
  (@ssl.nil? || @ssl.closed?) ||  (@socket.nil? || @socket.closed?)
end

#openObject



11
12
13
14
15
# File 'lib/mercurius/apns/connection.rb', line 11

def open
  @socket ||= TCPSocket.new host, port
  @ssl ||= OpenSSL::SSL::SSLSocket.new @socket, ssl_context_for_pem(pem)
  @ssl.connect
end

#write(data) ⇒ Object



26
27
28
# File 'lib/mercurius/apns/connection.rb', line 26

def write(data)
  @ssl.write data
end