Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Ruby HTML Other
Failed to load latest commit information.
app/controllers/notifiable
config
db/migrate
lib
spec
.gitignore
.ruby-gemset
.ruby-version
Gemfile
Gemfile.lock
LICENSE
README.md
Rakefile
notifiable-rails.gemspec

README.md

Notifiable Rails

Notifiable-Rails is a Rails engine which handles push notifications. It is:

  • Stable
  • Production Tested
  • Performant
  • Actively Maintained

Services

Services supported by official plugins:

Service Server Plugin Client Plugin Throughput
APNS notifiable-apns-grocer Notifiable-iOS 2000 p/s
GCM notifiable-gcm-spacialdb

Limitations

  • Only text alerts are supported at this time.

USAGE

Registering device tokens

Registering a new device token is done by POSTing to /device_tokens endpoint.

Supported fields:

  • token - device token (i.e. the token retrieved from APNS or GCM)
  • provider - lowercase service name (i.e. apns or gcm)

Sample request:

// POST /device_tokens
// Content-Type: application/json
{
    "token" : "SADFD234GFSD7982321321",
    "provider" : "apns"
}

Inactive device tokens

Invalid and inactive token registrations are handled automatically based on feedback from APNS and GCM. It is however important to note that mixing sandbox and production APNS tokens is not currently supported.

Releasing a device token

To release device token from the user (e.g. after logout), the following request needs to be made:

DELETE /device_tokens/:token

Notifying a single user

    n = Notifiable::Notification.create(:message => 'Hi there!')
    u = User.find_by_email("kamil@futureworkshops.com")
    u.send_notification(n)

Push notifications will be sent to all active devices of the user using appropriate providers.

Notifying multiple users

    n = Notifiable::Notification.create(:message => 'Hi all!')
    users = User.all
    Notifiable.batch do |batch|
        users.each do |u|
            batch.add(n, u)    
        end
    end

This transactional method minimises the amount of connections. This is preferred way of sending large amounts of notifications.

Security

To prevent token forgery base controller class for Notifiable is expected to handle authentication provide the current user (if any) via the current_notifiable_user method.

Example implementation allowing only modifications of tokens belonging to currently authenticaticated user:

def current_notifiable_user
    current_user
end

INSTALLATION

  1. Add the gem to your bundle
gem 'notifiable-rails'
  1. Mount engine routes in routes.rb
mount Notifiable::Engine => "/"
  1. Run the install generator
rails g notifiable:install
  1. Customise settings in config/initializers/notifiable.rb.

LICENSE

Apache License Version 2.0

Something went wrong with that request. Please try again.