I want to automatically send a push notification when ever the database record is updated. The push notifaction is for an android device. The records are from a Ruby on Rails application.
Any help will be appreciable .Thanks in advance.
I want to automatically send a push notification when ever the database record is updated. The push notifaction is for an android device. The records are from a Ruby on Rails application.
Any help will be appreciable .Thanks in advance.
Well what you are trying to do is send a push notification to a mobile device when a record in a table gets updated. I would suggest you have to design the tables and everything else in such a way that you can trigger the push notification. Please check the following scenario. In order to send a push notification to an Android device when the record in the customers table gets updated.
Model
customer.rb
class Customer < ActiveRecord::Base
after_save :send_push_notification
def send_push_notification
PushWorker.perform_async({id: self.id})
end
def send_push
require 'gcm'
gcm = GCM.new(ENV['API_KEY'])
registration_ids= Device.android.map(&:registration_id)
options = {
data: data,
collapse_key: collapse_key || 'my_app'
}
response = gcm.send(registration_ids, options)
end
end
Async Worker
push_worker.rb
class PushWorker
include Sidekiq::Worker
include Sidetiq::Schedulable
def perform(params)
customer = Customer.find(params[:id])
customer.send_push
end
end
Try (firebase cloud messaging)[https://firebase.google.com/docs/cloud-messaging/] service through google which is the newer GCM.
Basically on update/insert you could push to the messaging service to notify the device.
Check out this (question)[https://stackoverflow.com/a/22242606/3366016]