Class: ApnClient::Connection

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ Connection

Opens an SSL socket for talking to the Apple Push Notification service.

Parameters:

  • host (String)

    the hostname to connect to

  • port (Fixnum)

    the port to connect to

  • certificate (String)

    the APN certificate to use

  • certificate_passphrase (String)

    the passphrase of the certificate, can be empty

  • select_timeout (Float)

    the timeout (seconds) used when doing IO.select on the socket (default 0.1)



15
16
17
18
19
20
21
22
# File 'lib/apn_client/connection.rb', line 15

def initialize(config = {})
  NamedArgs.assert_valid!(config,
    :required => [:host, :port, :certificate, :certificate_passphrase],
    :optional => [:select_timeout])
  self.config = config
  config[:select_timeout] ||= 0.1
  connect_to_socket
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



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

def config
  @config
end

#ssl_socketObject

Returns the value of attribute ssl_socket.



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

def ssl_socket
  @ssl_socket
end

#tcp_socketObject

Returns the value of attribute tcp_socket.



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

def tcp_socket
  @tcp_socket
end

Class Method Details

.open(options = {}) ⇒ Object



43
44
45
46
47
48
# File 'lib/apn_client/connection.rb', line 43

def self.open(options = {})
  connection = Connection.new(options)
  yield connection
ensure
  connection.close if connection
end

Instance Method Details

#closeObject



24
25
26
27
28
29
# File 'lib/apn_client/connection.rb', line 24

def close
  ssl_socket.close
  tcp_socket.close
  self.ssl_socket = nil
  self.tcp_socket = nil
end

#read(*args) ⇒ Object



35
36
37
# File 'lib/apn_client/connection.rb', line 35

def read(*args)
  ssl_socket.read(*args)
end

#selectObject



39
40
41
# File 'lib/apn_client/connection.rb', line 39

def select
  IO.select([ssl_socket], nil, nil, config[:select_timeout])
end

#write(arg) ⇒ Object



31
32
33
# File 'lib/apn_client/connection.rb', line 31

def write(arg)
  ssl_socket.write(arg.to_s)
end