Class: Communify::Controllers::PushNotification

Inherits:
Object
  • Object
show all
Defined in:
lib/communify/controllers/push_notification_controller.rb

Class Method Summary collapse

Class Method Details

.send_push_notification(title, content, recipient, notification_type, custom_data, priority = 0) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/communify/controllers/push_notification_controller.rb', line 5

def self.send_push_notification(title, content, recipient, notification_type, custom_data, priority = 0)
    resource = CommunifyLog.new(title: title, 
                content: content, 
                recipient: recipient.to_s, 
                content_type: 1, 
                priority: priority
            )
    if resource.save
        resource.update(status: "Notification Queued at #{DateTime.now}")
        time = resource.read_attribute_before_type_cast(:priority)
        result = Communify::Workers::PushNotificationWorker.perform_in(time.minutes.from_now, resource.id, notification_type, custom_data)
        return resource.id
    else    
        raise "Error => Resource has not been saved!!"
    end
end