Class: AaGlobalNotifications::PushNotification

Inherits:
ActiveRecord::Base
  • Object
show all
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



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/models/aa_global_notifications/push_notification.rb', line 46

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

#deliverObject



62
63
64
65
66
67
68
69
70
# File 'app/models/aa_global_notifications/push_notification.rb', line 62

def deliver
	notification = {
		:aps => {
		:alert => self.message,
		:badge => 1
		}
	}
	Urbanairship.broadcast_push(notification)
end

#retry!Object



36
37
38
39
# File 'app/models/aa_global_notifications/push_notification.rb', line 36

def retry!
	resend_notification!
	self.class.delay.send_notification(self.id)
end

#send_notificationObject



41
42
43
44
# File 'app/models/aa_global_notifications/push_notification.rb', line 41

def send_notification
	#schedule push notification
	self.class.delay.send_notification(self.id)
end