Class: BMO::APNS::Connection

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

Overview

Handle the connection state SSL or Pure TCP

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port, cert_path = nil, cert_pass = nil) ⇒ Connection

Returns a new instance of Connection.



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

def initialize(host, port, cert_path = nil, cert_pass = nil)
  @host      = host
  @port      = port
  @cert_path = cert_path
  @cert_pass = cert_pass
end

Instance Attribute Details

#cert_passObject (readonly)

Returns the value of attribute cert_pass.



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

def cert_pass
  @cert_pass
end

#cert_pathObject (readonly)

Returns the value of attribute cert_path.



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

def cert_path
  @cert_path
end

#hostObject (readonly)

Returns the value of attribute host.



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

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



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

def port
  @port
end

Instance Method Details

#connectObject

Create a connection to Apple. If a cert_path exists it uses SSL else

a pure TCPSocket. It then yields the socket and handles the closing

Returns:

  • The yielded return



18
19
20
21
22
23
24
25
# File 'lib/bmo/apns/connection.rb', line 18

def connect
  socket = cert_path ? ssl_socket : tcp_socket

  yielded = yield socket

  socket.close
  yielded
end