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.



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

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.



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

def cert_pass
  @cert_pass
end

#cert_pathObject (readonly)

Returns the value of attribute cert_path.



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

def cert_path
  @cert_path
end

#hostObject (readonly)

Returns the value of attribute host.



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

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



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

def port
  @port
end

Instance Method Details

#connect(&block) ⇒ Object

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



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

def connect(&block)
  socket = cert_path ? ssl_socket : tcp_socket

  yielded = yield socket

  socket.close
  yielded
end