Module: APNS

Defined in:
lib/apns/core.rb

Overview

Copyright © 2009 James Pozdena, 2010 Justin.tv

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.cache_connectionsObject

Returns the value of attribute cache_connections.



49
50
51
# File 'lib/apns/core.rb', line 49

def cache_connections
  @cache_connections
end

.feedback_hostObject

Returns the value of attribute feedback_host.



49
50
51
# File 'lib/apns/core.rb', line 49

def feedback_host
  @feedback_host
end

.feedback_portObject

Returns the value of attribute feedback_port.



49
50
51
# File 'lib/apns/core.rb', line 49

def feedback_port
  @feedback_port
end

.hostObject

Returns the value of attribute host.



49
50
51
# File 'lib/apns/core.rb', line 49

def host
  @host
end

.passObject

Returns the value of attribute pass.



49
50
51
# File 'lib/apns/core.rb', line 49

def pass
  @pass
end

.pemObject

Returns the value of attribute pem.



49
50
51
# File 'lib/apns/core.rb', line 49

def pem
  @pem
end

.portObject

Returns the value of attribute port.



49
50
51
# File 'lib/apns/core.rb', line 49

def port
  @port
end

Class Method Details

.establish_notification_connectionObject



52
53
54
55
56
57
58
59
60
61
# File 'lib/apns/core.rb', line 52

def self.establish_notification_connection
  if @cache_connections
    begin
      self.get_connection(self.host, self.port)
      return true
    rescue
    end
  end
  return false
end

.feedbackObject



83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/apns/core.rb', line 83

def self.feedback
  apns_feedback = []
  self.with_feedback_connection do |conn|
    # Read buffers data from the OS, so it's probably not
    # too inefficient to do the small reads
    while data = conn.read(38)
      apns_feedback << self.parse_feedback_tuple(data)
    end
  end
  
  return apns_feedback
end

.has_notification_connection?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/apns/core.rb', line 63

def self.has_notification_connection?
  return self.has_connection?(self.host, self.port)
end

.send_notification(device_token, message) ⇒ Object



67
68
69
70
71
72
# File 'lib/apns/core.rb', line 67

def self.send_notification(device_token, message)
  self.with_notification_connection do |conn|
    conn.write(self.packaged_notification(device_token, message))
    conn.flush
  end
end

.send_notifications(notifications) ⇒ Object



74
75
76
77
78
79
80
81
# File 'lib/apns/core.rb', line 74

def self.send_notifications(notifications)
  self.with_notification_connection do |conn|
    notifications.each do |n|
      conn.write(self.packaged_notification(n[0], n[1]))
    end
    conn.flush
  end
end