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, other_details, priority = 0) ⇒ Object



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

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