Class: ApnClient::Connection
- Inherits:
-
Object
- Object
- ApnClient::Connection
- Defined in:
- lib/apn_client/connection.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#ssl_socket ⇒ Object
Returns the value of attribute ssl_socket.
-
#tcp_socket ⇒ Object
Returns the value of attribute tcp_socket.
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(config = {}) ⇒ Connection
constructor
Opens an SSL socket for talking to the Apple Push Notification service.
- #read(*args) ⇒ Object
- #select ⇒ Object
- #write(arg) ⇒ Object
Constructor Details
#initialize(config = {}) ⇒ Connection
Opens an SSL socket for talking to the Apple Push Notification service.
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
#config ⇒ Object
Returns the value of attribute config.
6 7 8 |
# File 'lib/apn_client/connection.rb', line 6 def config @config end |
#ssl_socket ⇒ Object
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_socket ⇒ Object
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( = {}) connection = Connection.new() yield connection ensure connection.close if connection end |
Instance Method Details
#close ⇒ Object
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 |
#select ⇒ Object
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 |