Module: APNS

Defined in:
lib/pushmeup/apns/core.rb,
lib/pushmeup/apns/notification.rb

Defined Under Namespace

Classes: Notification

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.hostObject

Returns the value of attribute host.



21
22
23
# File 'lib/pushmeup/apns/core.rb', line 21

def host
  @host
end

.passObject

Returns the value of attribute pass.



21
22
23
# File 'lib/pushmeup/apns/core.rb', line 21

def pass
  @pass
end

.pemObject

Returns the value of attribute pem.



21
22
23
# File 'lib/pushmeup/apns/core.rb', line 21

def pem
  @pem
end

.portObject

Returns the value of attribute port.



21
22
23
# File 'lib/pushmeup/apns/core.rb', line 21

def port
  @port
end

Class Method Details

.feedbackObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/pushmeup/apns/core.rb', line 50

def self.feedback
  sock, ssl = self.feedback_connection

  apns_feedback = []

  while line = ssl.read(38)   # Read lines from the socket
    line.strip!
    f = line.unpack('N1n1H140')
    apns_feedback << { :timestamp => Time.at(f[0]), :token => f[2] }
  end

  ssl.close
  sock.close

  return apns_feedback
end

.send_notification(device_token, message) ⇒ Object



35
36
37
38
# File 'lib/pushmeup/apns/core.rb', line 35

def self.send_notification(device_token, message)
  n = APNS::Notification.new(device_token, message)
  self.send_notifications([n])
end

.send_notifications(notifications) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/pushmeup/apns/core.rb', line 40

def self.send_notifications(notifications)
  @mutex.synchronize do
    self.with_connection do
      notifications.each do |n|
        @ssl.write(n.packaged_notification)
      end
    end
  end
end

.start_persistenceObject



24
25
26
# File 'lib/pushmeup/apns/core.rb', line 24

def self.start_persistence
  @persistent = true
end

.stop_persistenceObject



28
29
30
31
32
33
# File 'lib/pushmeup/apns/core.rb', line 28

def self.stop_persistence
  @persistent = false
  
  @ssl.close
  @sock.close
end