lib/racoon/notification.rb in racoon-0.4.0 vs lib/racoon/notification.rb in racoon-0.5.0
- old
+ new
@@ -1,18 +1,22 @@
+# Racoon - A distributed APNs provider
+# Copyright (c) 2011, Jeremy Tregunna, All Rights Reserved.
+#
+# This module contains the class that represents notifications and all their details.
+
require 'racoon/payload'
require 'base64'
require 'yajl'
module Racoon
class Notification
include Racoon::Payload
- attr_accessor :identifier, :expiry, :device_token, :alert, :badge, :sound, :custom, :send_at, :expiry
+ attr_accessor :identifier, :expiry, :device_token, :alert, :badge, :sound, :custom, :expiry
def initialize
@expiry = 0
- @send_at = Time.now
end
def payload
p = Hash.new
[:badge, :alert, :sound, :custom].each do |k|
@@ -70,9 +74,24 @@
['alert', 'badge', 'sound'].each do |k|
notification.send("#{k}=", result['aps'][k]) if result['aps'] && result['aps'][k]
end
result.delete("aps")
notification.custom = result
+
+ notification
+ end
+
+ def self.create_from_packet(packet)
+ aps = packet[:notification][:aps]
+
+ notification = Notification.new
+ notification.identifier = packet[:identifier]
+ notification.expiry = packet[:expiry] || 0
+ notification.device_token = packet[:device_token]
+ notification.badge = aps[:badge] if aps.has_key? :badge
+ notification.alert = aps[:alert] if aps.has_key? :alert
+ notification.sound = aps[:sound] if aps.has_key? :sound
+ notification.custom = aps[:custom] if aps.has_key? :custom
notification
end
end
end