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
-
.cache_connections ⇒ Object
Returns the value of attribute cache_connections.
-
.feedback_host ⇒ Object
Returns the value of attribute feedback_host.
-
.feedback_port ⇒ Object
Returns the value of attribute feedback_port.
-
.host ⇒ Object
Returns the value of attribute host.
-
.max_connection_age ⇒ Object
Returns the value of attribute max_connection_age.
-
.pass ⇒ Object
Returns the value of attribute pass.
-
.pem ⇒ Object
Returns the value of attribute pem.
-
.port ⇒ Object
Returns the value of attribute port.
Class Method Summary collapse
- .establish_notification_connection ⇒ Object
- .feedback ⇒ Object
- .has_notification_connection? ⇒ Boolean
- .send_notification(device_token, message) ⇒ Object
- .send_notifications(notifications) ⇒ Object
Class Attribute Details
.cache_connections ⇒ Object
Returns the value of attribute cache_connections.
52 53 54 |
# File 'lib/apns/core.rb', line 52 def cache_connections @cache_connections end |
.feedback_host ⇒ Object
Returns the value of attribute feedback_host.
52 53 54 |
# File 'lib/apns/core.rb', line 52 def feedback_host @feedback_host end |
.feedback_port ⇒ Object
Returns the value of attribute feedback_port.
52 53 54 |
# File 'lib/apns/core.rb', line 52 def feedback_port @feedback_port end |
.host ⇒ Object
Returns the value of attribute host.
52 53 54 |
# File 'lib/apns/core.rb', line 52 def host @host end |
.max_connection_age ⇒ Object
Returns the value of attribute max_connection_age.
52 53 54 |
# File 'lib/apns/core.rb', line 52 def max_connection_age @max_connection_age end |
.pass ⇒ Object
Returns the value of attribute pass.
52 53 54 |
# File 'lib/apns/core.rb', line 52 def pass @pass end |
.pem ⇒ Object
Returns the value of attribute pem.
52 53 54 |
# File 'lib/apns/core.rb', line 52 def pem @pem end |
.port ⇒ Object
Returns the value of attribute port.
52 53 54 |
# File 'lib/apns/core.rb', line 52 def port @port end |
Class Method Details
.establish_notification_connection ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/apns/core.rb', line 55 def self.establish_notification_connection if @cache_connections begin self.get_connection(self.host, self.port, self.pem) return true rescue end end return false end |
.feedback ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/apns/core.rb', line 86 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
66 67 68 |
# File 'lib/apns/core.rb', line 66 def self.has_notification_connection? return self.has_connection?(self.host, self.port, self.pem) end |
.send_notification(device_token, message) ⇒ Object
70 71 72 73 74 75 |
# File 'lib/apns/core.rb', line 70 def self.send_notification(device_token, ) self.with_notification_connection do |conn| conn.write(self.packaged_notification(device_token, )) conn.flush end end |
.send_notifications(notifications) ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/apns/core.rb', line 77 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 |