Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Integrated user activity notifications for Ruby on Rails

License

NotificationsYou must be signed in to change notification settings

simukappu/activity_notification

Repository files navigation

Build StatusCoverage StatusDependencyInline docsGem VersionGem DownloadsMIT License

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.

About

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)

Online Demo

You can see an actual application using this gem here:

Login as the following test users to experience user activity notifications:

EmailPasswordAdmin?
ichiro@example.comchangeitYes
stephen@example.comchangeit
klay@example.comchangeit
kevin@example.comchangeit

The deployed demo application is included in this gem's source code as a test application here:/spec/rails_app

Notification index and plugin notifications

plugin-notifications-image

activity_notification deeply usesPublicActivity as reference in presentation layer.

Subscription management of notifications

subscription-management-image

Amazon SNS as optional notification target

optional-target-amazon-sns-email-image

Slack as optional notification target

optional-target-slack-image

Public REST API reference as OpenAPI Specification

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.

Table of Contents

Getting Started

This getting started shows easy setup description ofactivity_notification. SeeSetup for more details.

Gem installation

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.

Database setup

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.

Configuring models

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.

Configuring views

activity_notification provides view templates to customize your notification views.SeeConfiguring views for more details.

Configuring routes

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.

Creating notifications

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.

Displaying notifications

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.

Run example Rails application

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.

Setup

SeeSetup.

Functions

SeeFunctions.

Testing

SeeTesting.

Documentation

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.

Common Examples

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.

Contributing

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!

License

activity_notification project rocks and usesMIT License.


[8]ページ先頭

©2009-2025 Movatter.jp