Class: Racoon::APNS::Connection
- Inherits:
-
Object
- Object
- Racoon::APNS::Connection
- Defined in:
- lib/racoon/apns/connection.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#password ⇒ Object
Returns the value of attribute password.
-
#pem ⇒ Object
Returns the value of attribute pem.
-
#port ⇒ Object
Returns the value of attribute port.
Instance Method Summary collapse
- #connect! ⇒ Object
- #connected? ⇒ Boolean
- #disconnect! ⇒ Object
-
#initialize(pem, host = 'gateway.push.apple.com', port = 2195, pass = nil) ⇒ Connection
constructor
A new instance of Connection.
- #read ⇒ Object
- #write(bytes) ⇒ Object
Constructor Details
#initialize(pem, host = 'gateway.push.apple.com', port = 2195, pass = nil) ⇒ Connection
Returns a new instance of Connection.
14 15 16 |
# File 'lib/racoon/apns/connection.rb', line 14 def initialize(pem, host = 'gateway.push.apple.com', port = 2195, pass = nil) @pem, @host, @port, @password = pem, host, port, pass end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
12 13 14 |
# File 'lib/racoon/apns/connection.rb', line 12 def host @host end |
#password ⇒ Object
Returns the value of attribute password.
12 13 14 |
# File 'lib/racoon/apns/connection.rb', line 12 def password @password end |
#pem ⇒ Object
Returns the value of attribute pem.
12 13 14 |
# File 'lib/racoon/apns/connection.rb', line 12 def pem @pem end |
#port ⇒ Object
Returns the value of attribute port.
12 13 14 |
# File 'lib/racoon/apns/connection.rb', line 12 def port @port end |
Instance Method Details
#connect! ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/racoon/apns/connection.rb', line 18 def connect! raise "Your certificate is not set." unless self.pem @context = OpenSSL::SSL::SSLContext.new @context.cert = OpenSSL::X509::Certificate.new(self.pem) @context.key = OpenSSL::PKey::RSA.new(self.pem, self.password) @sock = TCPSocket.new(self.host, self.port.to_i) @ssl = OpenSSL::SSL::SSLSocket.new(@sock, @context) @ssl.connect return @sock, @ssl end |
#connected? ⇒ Boolean
55 56 57 |
# File 'lib/racoon/apns/connection.rb', line 55 def connected? @ssl end |
#disconnect! ⇒ Object
32 33 34 35 36 37 |
# File 'lib/racoon/apns/connection.rb', line 32 def disconnect! @ssl.close @sock.close @ssl = nil @sock = nil end |
#read ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/racoon/apns/connection.rb', line 39 def read errors ||= [] while error = @ssl.read(6) errors << parse_tuple(error) end errors end |
#write(bytes) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/racoon/apns/connection.rb', line 47 def write(bytes) if host.include? "sandbox" notification = Notification.parse(bytes) Config.logger.debug "#{Time.now} [#{host}:#{port}] Device: #{notification.device_token.unpack('H*')} sending #{notification.json_payload}" end @ssl.write(notification.to_bytes) end |