Class: PushNotifier::APNS::Connection

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, certificate, passphrase) ⇒ Connection

Returns a new instance of Connection.



10
11
12
13
14
# File 'lib/push_notifier/apns/connection.rb', line 10

def initialize(uri, certificate, passphrase)
  @uri = uri
  @certificate = File.read(certificate)
  @passphrase = passphrase
end

Instance Attribute Details

#certificateObject (readonly)

Returns the value of attribute certificate.



8
9
10
# File 'lib/push_notifier/apns/connection.rb', line 8

def certificate
  @certificate
end

#passphraseObject (readonly)

Returns the value of attribute passphrase.



8
9
10
# File 'lib/push_notifier/apns/connection.rb', line 8

def passphrase
  @passphrase
end

#socketObject (readonly)

Returns the value of attribute socket.



8
9
10
# File 'lib/push_notifier/apns/connection.rb', line 8

def socket
  @socket
end

#sslObject (readonly)

Returns the value of attribute ssl.



8
9
10
# File 'lib/push_notifier/apns/connection.rb', line 8

def ssl
  @ssl
end

#uriObject (readonly)

Returns the value of attribute uri.



8
9
10
# File 'lib/push_notifier/apns/connection.rb', line 8

def uri
  @uri
end

Instance Method Details

#closeObject



32
33
34
35
36
# File 'lib/push_notifier/apns/connection.rb', line 32

def close
  @ssl.close
  @socket.close
  @ssl, @socket = nil, nil
end

#openObject



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/push_notifier/apns/connection.rb', line 16

def open
  @socket = TCPSocket.new(@uri.host, @uri.port)

  ssl_context = OpenSSL::SSL::SSLContext.new

  ssl_context.cert = OpenSSL::X509::Certificate.new @certificate
  ssl_context.key = OpenSSL::PKey::RSA.new @certificate, @passphrase

  @ssl = OpenSSL::SSL::SSLSocket.new @socket,ssl_context

  @ssl.connect

end

#write(data) ⇒ Object



29
30
31
# File 'lib/push_notifier/apns/connection.rb', line 29

def write(data)
  @ssl.write(data)
end