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.



7
8
9
10
11
# File 'lib/mercurius/apns/connection.rb', line 7

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

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



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

def host
  @host
end

#pemObject (readonly)

Returns the value of attribute pem.



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

def pem
  @pem
end

#portObject (readonly)

Returns the value of attribute port.



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

def port
  @port
end

Instance Method Details

#closeObject



19
20
21
22
# File 'lib/mercurius/apns/connection.rb', line 19

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

#closed?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/mercurius/apns/connection.rb', line 24

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

#openObject



13
14
15
16
17
# File 'lib/mercurius/apns/connection.rb', line 13

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

#readObject



32
33
34
# File 'lib/mercurius/apns/connection.rb', line 32

def read
  @ssl.read
end

#write(data) ⇒ Object



28
29
30
# File 'lib/mercurius/apns/connection.rb', line 28

def write(data)
  @ssl.write data
end