- Notifications
You must be signed in to change notification settings - Fork80
Integrated user activity notifications for Ruby on Rails
License
simukappu/activity_notification
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
activity_notification provides integrated user activity notifications forRuby on Rails. You can easily use it to configure multiple notification targets and make activity notifications with notifiable models, like adding comments, responding etc.
activity_notification supports Rails 5.0+ withActiveRecord,Mongoid andDynamoid ORM. It is tested forMySQL,PostgreSQL,SQLite3 with ActiveRecord,MongoDB with Mongoid andAmazon DynamoDB with Dynamoid. If you are using Rails 4.2, usev2.1.4 or older version ofactivity_notification.
activity_notification provides following functions:
- Notification API for your Rails application (creating and managing notifications, query for notifications)
- Notification models (stored with ActiveRecord, Mongoid or Dynamoid ORM)
- Notification controllers (managing open/unopen of notifications, providing link to notifiable activity page)
- Notification views (presentation of notifications)
- Automatic tracked notifications (generating notifications along with the lifecycle of notifiable models)
- Grouping notifications (grouping like"Kevin and 7 other users posted comments to this article")
- Email notification
- Batch email notification (event driven or periodical email notification, daily or weekly etc)
- Push notification withAction Cable
- Subscription management (subscribing and unsubscribing for each target and notification type)
- REST API backend andOpenAPI Specification
- Integration withDevise authentication
- Activity notifications stream integrated into cloud computing usingAmazon DynamoDB Streams
- Optional notification targets (Configurable optional notification targets likeAmazon SNS,Slack, SMS and so on)
You can see an actual application using this gem here:
Login as the following test users to experience user activity notifications:
Password | Admin? | |
---|---|---|
ichiro@example.com | changeit | Yes |
stephen@example.com | changeit | |
klay@example.com | changeit | |
kevin@example.com | changeit |
The deployed demo application is included in this gem's source code as a test application here:/spec/rails_app
activity_notification deeply usesPublicActivity as reference in presentation layer.
REST API reference as OpenAPI Specification is published in SwaggerHub here:
You can see sample single page application usingVue.js as a part of example Rails application here:
This sample application works withactivity_notification REST API backend.
- About
- Getting Started
- Setup
- Functions
- Testing
- Documentation
- Common Examples
- Contributing
- License
This getting started shows easy setup description ofactivity_notification. SeeSetup for more details.
You can installactivity_notification as you would any other gem:
$gem install activity_notification
or in your Gemfile:
gem'activity_notification'
After you installactivity_notification and add it to your Gemfile, you need to run the generator:
$bin/rails generate activity_notification:install
The generator will install an initializer which describes all configuration options ofactivity_notification.
When you useactivity_notification with ActiveRecord ORM as default configuration,create migration for notifications and migrate the database in your Rails project:
$bin/rails generate activity_notification:migration$bin/rake db:migrate
SeeDatabase setup for other ORMs.
Configure your target model (e.g.app/models/user.rb).Addacts_as_target configuration to your target model to get notifications.
classUser <ActiveRecord::Baseacts_as_targetend
Then, configure your notifiable model (e.g.app/models/comment.rb).Addacts_as_notifiable configuration to your notifiable model representing activity to notify for each of your target model.You have to define notification targets for all notifications from this notifiable model by:targets option. Other configurations are optional.:notifiable_path option is a path to move when the notification is opened by the target user.
classArticle <ActiveRecord::Basebelongs_to:userhas_many:comments,dependent::destroyhas_many:commented_users,through::comments,source::userendclassComment <ActiveRecord::Basebelongs_to:articlebelongs_to:useracts_as_notifiable:users,targets:->(comment,key){([comment.article.user] +comment.article.reload.commented_users.to_a -[comment.user]).uniq},notifiable_path::article_notifiable_pathdefarticle_notifiable_patharticle_path(article)endend
SeeConfiguring models for more details.
activity_notification provides view templates to customize your notification views.SeeConfiguring views for more details.
activity_notification also provides routing helper for notifications. Addnotify_to method toconfig/routes.rb for the target (e.g.:users):
Rails.application.routes.drawdonotify_to:usersend
SeeConfiguring routes for more details.
You can also configureactivity_notification routes as REST API backend withapi_mode option like this:
Rails.application.routes.drawdoscope:apidoscope:"v2"donotify_to:users,api_mode:trueendendend
SeeRoutes as REST API backend andREST API backend for more details.
You can trigger notifications by setting all your required parameters and triggeringnotify on the notifiable model, like this:
@comment.notify:users,key:"comment.reply"
The first argument is the plural symbol name of your target model, which is configured in notifiable model byacts_as_notifiable.The new instances ofActivityNotification::Notification model will be generated for the specified targets.
SeeCreating notifications for more details.
activity_notification also provides notification views. You can prepare target notifications, render them in your controller, and show them provided or custom notification views.
SeeDisplaying notifications for more details.
Test module includes example Rails application inspec/rails_app.Pull git repository and you can run the example application as common Rails application.
$git pull https://github.com/simukappu/activity_notification.git$cd activity_notification$bundle install —path vendor/bundle$cd spec/rails_app$bin/rake db:migrate$bin/rake db:seed$bin/rails server
Then, you can accesshttp://localhost:3000 for the example application.
SeeSetup.
SeeFunctions.
SeeTesting.
SeeAPI Reference for more details.
RubyDoc.info does not support parsing methods inincluded andclass_methods ofActiveSupport::Concern currently.To read complete documents, please generate YARD documents on your local environment:
$git pull https://github.com/simukappu/activity_notification.git$cd activity_notification$bundle install —path vendor/bundle$bundleexec yard doc$bundleexec yard server
Then you can see the documents athttp://localhost:8808/docs/index.
See example Rails application in/spec/rails_app.
You can also try this example Rails application as Online Demo here:
You can login as test users to experience user activity notifications. For more details, seeOnline Demo.
We encourage you to contribute toactivity_notification!Please check out theContributing toactivity_notification guide for guidelines about how to proceed.
Everyone interacting inactivity_notification codebases, issue trackers, and pull requests is expected to follow theactivity_notificationCode of Conduct.
We appreciate any of your contribution!
activity_notification project rocks and usesMIT License.
About
Integrated user activity notifications for Ruby on Rails