Action Pusher
ActionPusher is an ActionMailer inspired gem to make sending push notifications from Rails as easy as sending emails.
To use, require the gem inside your Gemfile
:
gem 'actionpusher', require: 'action_pusher'
Make sure your .pem
files are under config/certificates
. Then create a config/certificates.yml
file and a setup for each environment. Here's an example with a development
and production
configuration:
development:
name: 'push-notification-development.pem'
production:
name: 'push-notification-production.pem'
Then you can define a push sender. We define our pushers inside of app/pushers
like so:
# app/pushers/my_pusher.rb
class MyPusher < ActionPusher::Base
def send_a_push_notification
push(tokens: ['an', 'array', 'of', 'device', 'tokens'],
message: 'message being sent',
data: 'extra data sent with the push notification')
end
end
Your push notifications can then be called like a standard Rails mailer:
MyPusher.send_a_push_notification.deliver
In the event that you're using Delayed::Job
for your background processing, you can work with it in the same way that
ActionMailer would:
MyPusher.delay.send_a_push_notification
TODO
- Implement interceptor pattern
YAML based configuration for pem filesGet working with DelayedJob:MyPusher.delay.send_a_push_notification
Copyright
Copyright (c) 2014 PetroFeed. See LICENSE for further details.
Proudly brought to you by PetroFeed.