Class: ApnsDispatch::ApnsConnection

Inherits:
Object
  • Object
show all
Defined in:
lib/apns_dispatch/apns_connection.rb

Overview

Handles communication with the Apple Push Notification service (APNs). Based on code from github.com/itspriddle/apnd.

Constant Summary collapse

FEEDBACK_PORT =

Constants

2196
GATEWAY_PORT =
2195
PRODUCTION_FEEDBACK_HOST =
'feedback.push.apple.com'
PRODUCTION_GATEWAY_HOST =
'gateway.push.apple.com'
RETRYABLE_ERRORS =
[Errno::EPIPE, Errno::ETIMEDOUT, OpenSSL::SSL::SSLError]
SANDBOX_FEEDBACK_HOST =
'feedback.sandbox.push.apple.com'
SANDBOX_GATEWAY_HOST =
'gateway.sandbox.push.apple.com'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(certificate, options = {}) ⇒ ApnsConnection

Returns a new instance of ApnsConnection.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/apns_dispatch/apns_connection.rb', line 22

def initialize(certificate, options={})
  if options[:feedback]
    @port = FEEDBACK_PORT

    if options[:production]
      @host = PRODUCTION_FEEDBACK_HOST
    else
      @host = SANDBOX_FEEDBACK_HOST
    end
  else
    @port = GATEWAY_PORT

    if options[:production]
      @host = PRODUCTION_GATEWAY_HOST
    else
      @host = SANDBOX_GATEWAY_HOST
    end
  end

  @certificate = certificate
  @options = options
  @mutex = Mutex.new
end

Instance Attribute Details

#certificateObject (readonly)

Attributes



20
21
22
# File 'lib/apns_dispatch/apns_connection.rb', line 20

def certificate
  @certificate
end

#hostObject (readonly)

Attributes



20
21
22
# File 'lib/apns_dispatch/apns_connection.rb', line 20

def host
  @host
end

#optionsObject (readonly)

Attributes



20
21
22
# File 'lib/apns_dispatch/apns_connection.rb', line 20

def options
  @options
end

#portObject (readonly)

Attributes



20
21
22
# File 'lib/apns_dispatch/apns_connection.rb', line 20

def port
  @port
end

Instance Method Details

#read(length) ⇒ Object



46
47
48
# File 'lib/apns_dispatch/apns_connection.rb', line 46

def read(length)
  with_connection { @ssl.read(length) }
end

#write(message) ⇒ Object



50
51
52
# File 'lib/apns_dispatch/apns_connection.rb', line 50

def write(message)
  with_connection { @ssl.write(message) }
end