{"id":14955963,"url":"https://github.com/yhirano55/pubsub_notifier","last_synced_at":"2025-10-06T09:31:05.063Z","repository":{"id":56889580,"uuid":"96870605","full_name":"yhirano55/pubsub_notifier","owner":"yhirano55","description":":postbox::bee: Pub/Sub Notifier for Rails","archived":false,"fork":false,"pushed_at":"2017-07-14T10:28:23.000Z","size":34,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-20T01:14:47.963Z","etag":null,"topics":["activejob","pubsub","rails5","ruby","wisper"],"latest_commit_sha":null,"homepage":"https://github.com/yhirano55/pubsub_notifier","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yhirano55.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-11T08:34:54.000Z","updated_at":"2023-09-08T17:27:20.000Z","dependencies_parsed_at":"2022-08-20T15:20:44.373Z","dependency_job_id":null,"html_url":"https://github.com/yhirano55/pubsub_notifier","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yhirano55%2Fpubsub_notifier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yhirano55%2Fpubsub_notifier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yhirano55%2Fpubsub_notifier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yhirano55%2Fpubsub_notifier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yhirano55","download_url":"https://codeload.github.com/yhirano55/pubsub_notifier/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234862663,"owners_count":18898394,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["activejob","pubsub","rails5","ruby","wisper"],"created_at":"2024-09-24T13:12:05.703Z","updated_at":"2025-10-06T09:31:04.657Z","avatar_url":"https://github.com/yhirano55.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PubsubNotifier\n\n[![Build Status](https://travis-ci.org/yhirano55/pubsub_notifier.svg?branch=master)](https://travis-ci.org/yhirano55/pubsub_notifier)\n[![Gem Version](https://badge.fury.io/rb/pubsub_notifier.svg)](https://badge.fury.io/rb/pubsub_notifier)\n\nPublish-Subscribe Notifier for Ruby on Rails.\n\nThis gem relies on [krisleech/wisper](https://github.com/krisleech/wisper/) provides Pub/Sub capabilities.\n\n## Installation\n\n```ruby\ngem 'pubsub_notifier'\n```\n\nAnd you can run the generator, which will set up an application notifier with some useful defaults for you:\n\n```bash\nrails g pubsub_notifier:install\n```\n\nAfter generating your application notifier, restart the Rails server so that Rails can pick up any classes in the new `app/notifiers/` directory.\n\nOptionally, you need to perform asynchronously. Add `sidekiq` or `resuque` to your Gemfile:\n\n```ruby\ngem 'sidekiq'\n```\n\nThen set your queue adapter of active_job:\n\n```ruby\nRails.application.config.active_job.queue_adapter = :sidekiq\n```\n\n## Usage\n\n### ActiveRecord\n\n```ruby\nclass User \u003c ApplicationRecord\n  subscribe :UserMailer\n  subscribe :UserNotifier, async: true, queue: :high\nend\n\nclass UserMailer \u003c ApplicationMailer\n  acts_as_notifier\n\n  default from: 'admin@example.com'\n\n  def welcome(user)\n    @user = user\n    mail(to: @user.email, subject: 'Welcome to My Awesome Site')\n  end\nend\n\nclass UserNotifier \u003c ApplicationNotifier\n  use :slack, channel: '#general', username: 'angel', icon_emoji: ':innocent:'\n\n  def welcome(user)\n    notify_success(\"#{user.name} has joined.\")\n  end\nend\n\nuser = User.first\nuser.broadcast(:welcome) # or user.publish(:welcome)\n```\n\n### Pure Ruby Object\n\n```ruby\nclass Register\n  include PubsubNotifier::Proxy\n\n  subscribe :UserRegisterNotifier\n\n  attr_accessor :name\n\n  validates :name, presence: true\n\n  def execute\n    if valid?\n      broadcast(:success)\n    else\n      broadcast(:failure)\n    end\n  end\nend\n\nclass UserRegisterNotifier \u003c ApplicationNotifier\n  use :slack, channel: '#random', username: 'noreply', icon_emoji: ':grinning:'\n\n  def success(context)\n    notify_success('succeed')\n  end\n\n  def failure(context)\n    notify_failure('failure')\n  end\nend\n\nregister = Register.new(name: 'hello')\nregister.execute\n```\n\n### Configuration\n\n```ruby\n# config/initializers/pubsub_notifier.rb\nPubsubNotifier.config.logger = Rails.logger\n\nrequire \"pubsub_notifier/slack_client\"\n\nPubsubNotifier::SlackClient.configure do |config|\n  config.default_channel    = ENV['SLACK_DEFAULT_CHANNEL']\n  config.default_username   = ENV['SLACK_DEFAULT_USERNAME']\n  config.default_icon_emoji = ENV['SLACK_DEFAULT_ICON_EMOJI']\n  config.webhook_url        = ENV['SLACK_WEBHOOK_URL']\nend\n```\n\n### Generate a Notifier class\n\nYou can generate a notifier class by generate command:\n\n```bash\nrails g notifier user\n      create  app/notifiers/user_notifier.rb\n      invoke  test_unit\n      create    test/notifiers/user_notifier_test.rb\n```\n\n### Implement Notification Client\n\nYou can easily implement Client for Notification like plugin:\n\n```ruby\nmodule PubsubNotifier\n  class SomethingClient \u003c ::PubsubNotifier::Client::Base\n    def initialize(options = {})\n      # implement this\n    end\n\n    def notify_success(message)\n      # implement this\n    end\n\n    def notify_failure(message)\n      # implement this\n    end\n\n    def something_special(*args)\n      # implement if you need\n    end\n  end\nend\n\nPubsubNotifier.clients :something, PubsubNotifier::SomethingClient\n```\n\nThen you can use on a notifier class:\n\n```ruby\nclass SomeNotifier \u003c ApplicationNotifier\n  use :something\n\n  def welcome(recipient)\n    notify_success(recipient.name)\n  end\nend\n```\n\nIf you want to know more information to implement notification client, please check  `lib/pubsub_notifier/slack_client.rb`.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyhirano55%2Fpubsub_notifier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyhirano55%2Fpubsub_notifier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyhirano55%2Fpubsub_notifier/lists"}