Class: AaGlobalNotifications::PushNotification
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- AaGlobalNotifications::PushNotification
- Includes:
- AASM
- Defined in:
- app/models/aa_global_notifications/push_notification.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.send_notification(id) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/models/aa_global_notifications/push_notification.rb', line 47 def self.send_notification(id) push_notification = PushNotification.find(id) response = push_notification.deliver if response.success? push_notification.mark_as_sent puts "Push notification sent successfully" return true else push_notification.mark_as_failed puts "Push notification failed" push_notification.errors[:base] << "Couldn't contact Urban Airship to send push notification" return false end end |
Instance Method Details
#deliver ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'app/models/aa_global_notifications/push_notification.rb', line 63 def deliver notification = { :aps => { :alert => self., :badge => 1 } } Urbanairship.broadcast_push(notification) end |
#retry! ⇒ Object
37 38 39 40 |
# File 'app/models/aa_global_notifications/push_notification.rb', line 37 def retry! resend_notification! self.class.delay.send_notification(self.id) end |
#send_notification ⇒ Object
42 43 44 45 |
# File 'app/models/aa_global_notifications/push_notification.rb', line 42 def send_notification #schedule push notification self.class.delay.send_notification(self.id) end |