Class: PushNotifier::APNS

Inherits:
Object
  • Object
show all
Defined in:
lib/push_notifier/apns/apns.rb,
lib/push_notifier/apns/connection.rb,
lib/push_notifier/apns/notification.rb

Defined Under Namespace

Classes: Connection, Notification

Constant Summary collapse

DEVELOPMENT_URI =
'tcp://gateway.sandbox.push.apple.com:2195'
PRODUCTION_URI =
'tcp://gateway.push.apple.com:2195'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(push_uri) ⇒ APNS

Returns a new instance of APNS.



22
23
24
# File 'lib/push_notifier/apns/apns.rb', line 22

def initialize(push_uri)
  @push_uri = URI(push_uri)
end

Instance Attribute Details

#certificateObject

Returns the value of attribute certificate.



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

def certificate
  @certificate
end

#passphraseObject

Returns the value of attribute passphrase.



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

def passphrase
  @passphrase
end

#push_uriObject (readonly)

Returns the value of attribute push_uri.



5
6
7
# File 'lib/push_notifier/apns/apns.rb', line 5

def push_uri
  @push_uri
end

Class Method Details

.set_mode(environment) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/push_notifier/apns/apns.rb', line 12

def self.set_mode(environment)
  case environment
    when :production
      uri = PRODUCTION_URI
    else
      uri = DEVELOPMENT_URI
  end
  @apns = self.new(uri)
end

Instance Method Details

#send_notification(notification) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/push_notifier/apns/apns.rb', line 26

def send_notification(notification)
  bytes = ''
  self.setup_connection do
    payload = notification.payload
    @connection.write(payload)
  end
end

#setup_connectionObject



34
35
36
37
38
39
# File 'lib/push_notifier/apns/apns.rb', line 34

def setup_connection
  @connection = Connection.new(@push_uri, @certificate, @passphrase)
  @connection.open
  yield if block_given?
  @connection.close
end