Unagi Notifications
Unagi Notifications is a gem developed by Unagi for Ruby on Rails applications. It integrates a simple real-time notifications system based on Google's Firebase platform.
The gem allows Rails applications to upload notifications on server-side and get them on client-sife using simple and customizable view helpers.
Installation
Add this line to your application's Gemfile:
gem 'notifications'
And then execute:
$ bundle
Or install it yourself as:
$ gem install notifications
Configuration
Add the following code in order to configure the gem:
Notifications.configure do |config|
config.firebase_project_id = '' # You must set the Firebase project ID here
config.firebase_api_key = '' # You must set the Firebase API key here
end
Usage
Notification creation
Notification::Uploader.call(
origin: 'your_origin',
destination: 'your_destination',
text: 'This is an awesome notification text!',
link: 'your.awesome.website.com/posts/1',
created_at: Time.now
)
Notifications reading
We provide two helpers that can be used on Rails views for users' unread notifications with HTML customization:
Notifications list
<%= notifications_for current_user.id,
container: :ul, # The notifications wrapper tag
container_class: 'dropdown-menu', # The notifications wrapper class
notification_container: :li, # The wrapper tag of a notification
notification_container_class: 'dropdown-item', # The wrapper class of a notification
notification_class: 'text-bold' # The notification link class
%>
Notifications counter
<%= notifications_count_for current_user.id,
container: :span, # The counter wrapper tag
container_class: 'u-bold' # The counter wrapper class
%>
Development
After checking out the repo, run bundle install
to install dependencies. Then, run rake test
to run the tests. You can also run bundle console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/lucashour/notifications.
License
The gem is available as open source under the terms of the MIT License.