notification_hub 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +21 -0
  5. data/README.md +105 -0
  6. data/Rakefile +2 -0
  7. data/bin/console +14 -0
  8. data/bin/setup +8 -0
  9. data/lib/generators/active_record/notification_hub_generator.rb +48 -0
  10. data/lib/generators/active_record/templates/migrations/devices.rb +15 -0
  11. data/lib/generators/active_record/templates/migrations/subscription_devices.rb +10 -0
  12. data/lib/generators/active_record/templates/migrations/subscriptions.rb +11 -0
  13. data/lib/generators/active_record/templates/models/device.rb +15 -0
  14. data/lib/generators/active_record/templates/models/subscription.rb +16 -0
  15. data/lib/generators/active_record/templates/models/subscription_device.rb +8 -0
  16. data/lib/generators/notification_hub/job_generator.rb +18 -0
  17. data/lib/generators/notification_hub/notification_hub_generator.rb +25 -0
  18. data/lib/generators/notification_hub/templates/initializer.rb +56 -0
  19. data/lib/generators/notification_hub/templates/jobs/active_job.rb +7 -0
  20. data/lib/generators/notification_hub/templates/jobs/sidekiq_job.rb +8 -0
  21. data/lib/generators/notification_hub/templates/notification_hub/browser_push_notification/estimate/accepted.json.jbuilder +8 -0
  22. data/lib/generators/notification_hub/templates/notification_hub/browser_push_notification/estimate/expired.json.jbuilder +9 -0
  23. data/lib/generators/notification_hub/templates/notification_hub/browser_push_notification/estimate/viewed.json.jbuilder +8 -0
  24. data/lib/generators/notification_hub/templates/notification_hub/browser_push_notification/invoice/overdue.json.jbuilder +8 -0
  25. data/lib/generators/notification_hub/templates/notification_hub/browser_push_notification/invoice/payment_received.json.jbuilder +8 -0
  26. data/lib/generators/notification_hub/templates/notification_hub/browser_push_notification/invoice/unrealized_payment_received.json.jbuilder +9 -0
  27. data/lib/generators/notification_hub/templates/notification_hub/browser_push_notification/invoice/viewed.json.jbuilder +10 -0
  28. data/lib/generators/notification_hub/templates/notification_hub/email/estimate/accepted.html.erb +10 -0
  29. data/lib/generators/notification_hub/templates/notification_hub/email/estimate/accepted.text.erb +9 -0
  30. data/lib/generators/notification_hub/templates/notification_hub/email/estimate/expired.html.erb +9 -0
  31. data/lib/generators/notification_hub/templates/notification_hub/email/estimate/expired.text.erb +9 -0
  32. data/lib/generators/notification_hub/templates/notification_hub/email/estimate/viewed.html.erb +9 -0
  33. data/lib/generators/notification_hub/templates/notification_hub/email/estimate/viewed.text.erb +9 -0
  34. data/lib/generators/notification_hub/templates/notification_hub/email/invoice/overdue.html.erb +9 -0
  35. data/lib/generators/notification_hub/templates/notification_hub/email/invoice/overdue.text.erb +9 -0
  36. data/lib/generators/notification_hub/templates/notification_hub/email/invoice/payment_received.html.erb +11 -0
  37. data/lib/generators/notification_hub/templates/notification_hub/email/invoice/payment_received.text.erb +13 -0
  38. data/lib/generators/notification_hub/templates/notification_hub/email/invoice/unrealized_payment_received.html.erb +10 -0
  39. data/lib/generators/notification_hub/templates/notification_hub/email/invoice/unrealized_payment_received.text.erb +11 -0
  40. data/lib/generators/notification_hub/templates/notification_hub/email/invoice/viewed.html.erb +9 -0
  41. data/lib/generators/notification_hub/templates/notification_hub/email/invoice/viewed.text.erb +9 -0
  42. data/lib/generators/notification_hub/templates/notification_hub/webhook/estimate/accepted.json.jbuilder +6 -0
  43. data/lib/generators/notification_hub/templates/notification_hub/webhook/estimate/expired.json.jbuilder +6 -0
  44. data/lib/generators/notification_hub/templates/notification_hub/webhook/estimate/viewed.json.jbuilder +6 -0
  45. data/lib/generators/notification_hub/templates/notification_hub/webhook/invoice/overdue.json.jbuilder +6 -0
  46. data/lib/generators/notification_hub/templates/notification_hub/webhook/invoice/payment_received.json.jbuilder +7 -0
  47. data/lib/generators/notification_hub/templates/notification_hub/webhook/invoice/unrealized_payment_received.json.jbuilder +7 -0
  48. data/lib/generators/notification_hub/templates/notification_hub/webhook/invoice/viewed.json.jbuilder +6 -0
  49. data/lib/notification_hub/channels/browser_push_notification/base.rb +19 -0
  50. data/lib/notification_hub/channels/browser_push_notification/fcm.rb +42 -0
  51. data/lib/notification_hub/channels/browser_push_notification.rb +16 -0
  52. data/lib/notification_hub/channels/email/action_mailer.rb +31 -0
  53. data/lib/notification_hub/channels/email/base.rb +17 -0
  54. data/lib/notification_hub/channels/email.rb +17 -0
  55. data/lib/notification_hub/channels/mobile_push_notification/base.rb +18 -0
  56. data/lib/notification_hub/channels/mobile_push_notification/fcm.rb +42 -0
  57. data/lib/notification_hub/channels/mobile_push_notification.rb +16 -0
  58. data/lib/notification_hub/channels/sms/aws.rb +32 -0
  59. data/lib/notification_hub/channels/sms/base.rb +18 -0
  60. data/lib/notification_hub/channels/sms.rb +16 -0
  61. data/lib/notification_hub/channels/webhook/base.rb +19 -0
  62. data/lib/notification_hub/channels/webhook/httparty.rb +39 -0
  63. data/lib/notification_hub/channels/webhook.rb +16 -0
  64. data/lib/notification_hub/device_manager.rb +19 -0
  65. data/lib/notification_hub/subscription_manager.rb +55 -0
  66. data/lib/notification_hub/version.rb +3 -0
  67. data/lib/notification_hub.rb +88 -0
  68. data/notification_hub.gemspec +26 -0
  69. metadata +167 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5432428520174d050fe0ded31d0a63c346f6da96
4
+ data.tar.gz: 0a0ce05afab17db9ab8c4a1334785ea6fd951997
5
+ SHA512:
6
+ metadata.gz: 88634adbe734009076ce87660c69562804a6eb66dbeee5652ea96a86c3dda28fb165f7c1df6da89fea1614beb962a7306376340b82253106d3b9234e3b9807de
7
+ data.tar.gz: 349ac8b3780b7a757751dd0ae60905942962c9af83c903fc4a4c0b3f55580eb551b2f3ec090893e60f57283be702a75737be293e8cbc3b662d11b1a51b5ade42
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in notification_hub.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Viduranga Wijesooriya
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,105 @@
1
+ # NotificationHub
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/notification_hub`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'notification_hub'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install notification_hub
22
+
23
+ ## INTRODUCTION
24
+
25
+ This gem can be used to centralize the notification dispatching of an application.
26
+
27
+ Currently, this gem supports 5 notification channels
28
+ * Email
29
+ * Webhook
30
+ * SMS
31
+ * Mobile Push Notifications
32
+ * Web Push Notifications
33
+
34
+ Each channel can be configured to use with a gateway.
35
+ Below gateways are already bult-in. You can always add custom gateways.
36
+ * Email - ActionMailer
37
+ * Webhook - HTTParty
38
+ * SMS - AWS
39
+ * Mobile Push Notifications - FCM(Firebase Cloud Messaging)
40
+ * Web Push Notifications - FCM(Firebase Cloud Messaging)
41
+
42
+ ## SETUP
43
+
44
+ Step 1
45
+ Generate relavant configuration and template files
46
+
47
+ rails generate notification_hub [Association Model]
48
+ *Association Model: default value is "user"
49
+ *Currently, ActiveRecord ORM is only supported.
50
+
51
+ Step 2
52
+ Background processor intergration (Optional)
53
+
54
+ rails generate notification_hub:job [Background Processor] [Queue]
55
+ *Background Processor: options ["active_job", "sidekiq"]
56
+ *Queue: default value is "default"
57
+
58
+ Step 3
59
+ Run database migrations
60
+
61
+ rails db:migrate
62
+
63
+
64
+ ## Usage
65
+
66
+ Step 1
67
+ Complete gateway settings in configuration file (config/initializers/notification_hub.rb)
68
+ Example: Push notifications
69
+ config.set_channel :mobile_push_notification, {
70
+ gateway: :fcm,
71
+ server_key: "test"
72
+ }
73
+
74
+ Step 2
75
+ Define events in configuration file (config/initializers/notification_hub.rb)
76
+ Example:
77
+ config.events = {
78
+ "user.signed_up" => "When an user is signed up",
79
+ "user.trial_ended" => "When the trial period is ended",
80
+ "message.received" => "When a message is received"
81
+ }
82
+
83
+
84
+ Step 2
85
+ Create message templates
86
+
87
+ Examples: URL
88
+
89
+
90
+
91
+ ## Development
92
+
93
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
94
+
95
+ 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](https://rubygems.org).
96
+
97
+ ## Contributing
98
+
99
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/notification_hub. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
100
+
101
+
102
+ ## License
103
+
104
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
105
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "notification_hub"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,48 @@
1
+ require 'rails/generators/active_record'
2
+ module ActiveRecord
3
+ module Generators
4
+ class NotificationHubGenerator < ActiveRecord::Generators::Base
5
+ argument :association_model, type: :string, default: "user"
6
+ argument :name, type: :string, default: "dummy"
7
+ source_root File.expand_path("../templates", __FILE__)
8
+
9
+ desc "Creates the NotificationHub models and their migrations"
10
+
11
+ def create_models_and_migrations
12
+ template "models/subscription.rb", "#{models_path}/notification_hub/subscription.rb", rails5?: rails5?
13
+ migration_template "migrations/subscriptions.rb", "#{migrations_path}/create_notification_hub_subscriptions.rb", migration_version: migration_version
14
+
15
+ template "models/device.rb", "#{models_path}/notification_hub/device.rb", rails5?: rails5?
16
+ migration_template "migrations/devices.rb", "#{migrations_path}/create_notification_hub_devices.rb", migration_version: migration_version
17
+
18
+ template "models/subscription_device.rb", "#{models_path}/notification_hub/subscription_device.rb", rails5?: rails5?
19
+ migration_template "migrations/subscription_devices.rb", "#{migrations_path}/create_notification_hub_subscription_devices.rb", migration_version: migration_version
20
+ end
21
+
22
+ def inject_content_to_user
23
+ content = "has_many :notification_hub_subscriptions, class_name: 'NotificationHub::Subscription', dependent: :destroy\nhas_many :notification_hub_devices, class_name: 'NotificationHub::Device', dependent: :destroy"
24
+ content = content.split("\n").map { |line| " " + line } .join("\n") << "\n"
25
+
26
+ inject_into_class("#{models_path}/#{association_model}.rb", association_model.classify, content)
27
+ end
28
+
29
+ def rails5?
30
+ Rails.version.start_with? '5'
31
+ end
32
+
33
+ def migration_version
34
+ if rails5?
35
+ "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
36
+ end
37
+ end
38
+
39
+ def migrations_path
40
+ @migrations_path ||= File.join("db", "migrate")
41
+ end
42
+
43
+ def models_path
44
+ @models_path ||= File.join("app", "models")
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,15 @@
1
+ class CreateNotificationHubDevices < ActiveRecord::Migration<%= migration_version %>
2
+ def change
3
+ create_table :notification_hub_devices do |t|
4
+ t.references :<%= association_model %>, null: false
5
+ t.string :channel_code, index: true
6
+ t.string :email
7
+ t.string :webhook_url
8
+ t.string :phone_number
9
+ t.string :push_token
10
+ t.string :push_platform, index: true
11
+ t.timestamps null: false
12
+ end
13
+ end
14
+ end
15
+
@@ -0,0 +1,10 @@
1
+ class CreateNotificationHubSubscriptionDevices < ActiveRecord::Migration<%= migration_version %>
2
+ def change
3
+ create_table :notification_hub_subscription_devices do |t|
4
+ t.belongs_to :notification_hub_subscription, index: {:name => "index_nb_subscription_devices_on_nh_subscription_id"}
5
+ t.belongs_to :notification_hub_device, index: {:name => "index_nb_subscription_devices_on_nh_device_id"}
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
10
+
@@ -0,0 +1,11 @@
1
+ class CreateNotificationHubSubscriptions < ActiveRecord::Migration<%= migration_version %>
2
+ def change
3
+ create_table :notification_hub_subscriptions do |t|
4
+ t.references :<%= association_model %>, null: false
5
+ t.string :event_code, null: false, index: true
6
+ t.string :channel_code, null: false, index: true
7
+ t.string :gateway_code, index: true
8
+ t.timestamps null: false
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ class NotificationHub::Device < <%= rails5? ? "ApplicationRecord" : "ActiveRecord::Base" %>
2
+ self.table_name = "notification_hub_devices"
3
+
4
+ belongs_to :<%= association_model %>
5
+ has_many :notification_hub_subscription_devices, class_name: 'NotificationHub::SubscriptionDevice', dependent: :destroy, foreign_key: 'notification_hub_device_id'
6
+ has_many :notification_hub_subscriptions, class_name: 'NotificationHub::Subscription', through: :notification_hub_subscription_devices
7
+
8
+ validates_presence_of :<%= association_model %>
9
+ validates_inclusion_of :channel_code, :in => ["email", "webhook", "sms", "mobile_push_notification", "browser_push_notification"]
10
+ validates_format_of :email, with: /\A[^@\s]+@[^@\s]+\z/, if: Proc.new { |d| d.channel_code == "email" }
11
+ validates_format_of :webhook_url, with: URI::regexp(%w(http https)), if: Proc.new { |d| d.channel_code == "webhook"}
12
+ validates_presence_of :phone_number, if: Proc.new { |d| d.channel_code == "sms" }
13
+ validates_presence_of :push_token, if: Proc.new { |d| d.channel_code == "mobile_push_notification" || d.channel_code == "browser_push_notification" }
14
+ validates_inclusion_of :push_platform, :in => ["android", "ios", "browser"], if: Proc.new { |d| d.channel_code == "mobile_push_notification" || d.channel_code == "browser_push_notification" }
15
+ end
@@ -0,0 +1,16 @@
1
+ class NotificationHub::Subscription < <%= rails5? ? "ApplicationRecord" : "ActiveRecord::Base" %>
2
+ self.table_name = "notification_hub_subscriptions"
3
+
4
+ belongs_to :<%= association_model %>
5
+ has_many :notification_hub_subscription_devices, class_name: 'NotificationHub::SubscriptionDevice', dependent: :destroy, foreign_key: 'notification_hub_subscription_id'
6
+ has_many :notification_hub_devices, class_name: 'NotificationHub::Device', through: :notification_hub_subscription_devices
7
+
8
+ validates :<%= association_model %>, :event_code, :channel_code, presence: true
9
+ validates_inclusion_of :event_code, :in => ::NotificationHub.events.keys
10
+ validates_inclusion_of :channel_code, :in => ["email", "webhook", "sms", "mobile_push_notification", "browser_push_notification"]
11
+ validates_inclusion_of :gateway_code, :in => ["action_mailer"], if: Proc.new { |s| s.gateway_code.present? && s.channel_code == "email" }
12
+ validates_inclusion_of :gateway_code, :in => ["aws"], if: Proc.new { |s| s.gateway_code.present? && s.channel_code == "sms" }
13
+ validates_inclusion_of :gateway_code, :in => ["fcm"], if: Proc.new { |s| s.gateway_code.present? && s.channel_code == "mobile_push_notification" }
14
+ validates_inclusion_of :gateway_code, :in => ["fcm"], if: Proc.new { |s| s.gateway_code.present? && s.channel_code == "browser_push_notification" }
15
+ validates_inclusion_of :gateway_code, :in => ["httparty"], if: Proc.new { |s| s.gateway_code.present? && s.channel_code == "webhook" }
16
+ end
@@ -0,0 +1,8 @@
1
+ class NotificationHub::SubscriptionDevice < <%= rails5? ? "ApplicationRecord" : "ActiveRecord::Base" %>
2
+ self.table_name = "notification_hub_subscription_devices"
3
+
4
+ belongs_to :notification_hub_subscription, :class_name => "NotificationHub::Subscription"
5
+ belongs_to :notification_hub_device, :class_name => "NotificationHub::Device"
6
+
7
+ validates :notification_hub_subscription, :notification_hub_device, presence: true
8
+ end
@@ -0,0 +1,18 @@
1
+ module NotificationHub
2
+ module Generators
3
+ class JobGenerator < Rails::Generators::Base
4
+ source_root File.expand_path("../templates", __FILE__)
5
+ argument :background_processor, type: :string, default: "active_job"
6
+ argument :queue_name, type: :string, default: "default"
7
+
8
+ desc "copy job file to app/jobs directory"
9
+ def copy_job_file
10
+ if background_processor == "active_job"
11
+ template "jobs/active_job.rb", "app/jobs/notification_hub_job.rb"
12
+ elsif background_processor == "sidekiq"
13
+ template "jobs/sidekiq_job.rb", "app/jobs/notification_hub_job.rb"
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,25 @@
1
+ module NotificationHub
2
+ module Generators
3
+ class NotificationHubGenerator < Rails::Generators::Base
4
+ source_root File.expand_path('../templates', __FILE__)
5
+ argument :association_model, type: :string, default: "user"
6
+
7
+ desc "Copy NotificationHub initializer"
8
+ def copy_initializer
9
+ template "initializer.rb", "config/initializers/notification_hub.rb"
10
+ end
11
+
12
+ desc "Generate models and migrations"
13
+ hook_for :orm
14
+
15
+ desc "Generate notification template directories"
16
+ def create_template_directories
17
+ empty_directory "app/views/notification_hub/email"
18
+ empty_directory "app/views/notification_hub/browser_push_notification"
19
+ empty_directory "app/views/notification_hub/mobile_push_notification"
20
+ empty_directory "app/views/notification_hub/sms"
21
+ empty_directory "app/views/notification_hub/webhook"
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,56 @@
1
+ NotificationHub.configure do |config|
2
+ # ==> Email configuration
3
+ config.set_channel :email, {
4
+ gateway: :action_mailer
5
+ }
6
+
7
+ # ==> Webhook configuration
8
+ # FIXME
9
+ # gateway(required): httparty is the default http client
10
+ # template_path(optional): default path is app/views/notification_hub/webhook
11
+ config.set_channel :webhook, {
12
+ gateway: :httparty
13
+ #timeout_time: 10
14
+ #template_path: "notification_hub/webhook"
15
+ }
16
+
17
+ # ==> SMS configuration
18
+ # gateway(required): aws is the default sms client
19
+ # template_path(optional): default path is app/views/notification_hub/sms
20
+ # *prerequisite: install and configure aws gem (https://github.com/aws/aws-sdk-ruby)
21
+ config.set_channel :sms, {
22
+ gateway: :aws
23
+ #template_path: "notification_hub/sms"
24
+ }
25
+
26
+ # ==> Mobile Push Notification configuration
27
+ # gateway(required): FCM is the default push notification client
28
+ # server_key(required if using FCM)
29
+ # notification parameters - https://firebase.google.com/docs/cloud-messaging/http-server-ref#notification-payload-support
30
+ # template_path(optional): default path is app/views/notification_hub/mobile_push_notification
31
+ config.set_channel :mobile_push_notification, {
32
+ gateway: :fcm,
33
+ server_key: "test"
34
+ #template_path: "notification_hub/mobile_push_notification"
35
+ }
36
+
37
+ # ==> Browser Push Notification configuration
38
+ # gateway(required): FCM is the default push notification client
39
+ # web api_key(required if using FCM)
40
+ # server_key(required if using FCM)
41
+ # notification parameters - https://firebase.google.com/docs/cloud-messaging/http-server-ref#notification-payload-support
42
+ # template_path(optional): default path is app/views/notification_hub/browser_push_notification
43
+ config.set_channel :browser_push_notification, {
44
+ gateway: :fcm,
45
+ web_api_key: "test",
46
+ server_key: "test"
47
+ #template_path: "notification_hub/browser_push_notification"
48
+ }
49
+
50
+ #Define the events here
51
+ config.events = {
52
+ #"user.welcome" => "Welcome message"
53
+ }
54
+
55
+ config.association_model = "<%= association_model %>"
56
+ end
@@ -0,0 +1,7 @@
1
+ class NotificationHubJob < ActiveJob::Base
2
+ queue_as :<%= queue_name %>
3
+
4
+ def perform(association_model_id, event_code, data, options)
5
+ NotificationHub.send_message(association_model_id, event_code, data, options)
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ class NotificationHubJob
2
+ include Sidekiq::Worker
3
+ sidekiq_options :queue => :<%= queue_name %>, :retry => 10, :backtrace => true
4
+
5
+ def perform(association_model_id, event_code, data, options)
6
+ NotificationHub.send_message(association_model_id, event_code, data, options)
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ company = estimate.company
2
+ json.notification do
3
+ json.title "#{I18n.t(:accepted, scope: LocaleScope::SCOPE_NOTIFICATIONS_ESTIMATE)} – #{company.primary_business.name}"
4
+ json.body "#{I18n.t(:estimate, scope: LocaleScope::SCOPE_NOTIFICATIONS_ESTIMATE)} #{estimate.statement_no} #{I18n.t(:accepted_by, scope: LocaleScope::SCOPE_NOTIFICATIONS_ESTIMATE)} #{estimate.connection_name}"
5
+ json.icon "https://s3.amazonaws.com/hiveage-production/defaults/business_logo.png"
6
+ json.click_action Rails.application.routes.url_helpers.estimate_url(estimate, host: NotificationHubHelper.host_url(company),
7
+ protocol: NotificationHubHelper.account_schema(company))
8
+ end
@@ -0,0 +1,9 @@
1
+ company = estimate.company
2
+ json.notification do
3
+ json.title "#{I18n.t(:expired, scope: LocaleScope::SCOPE_NOTIFICATIONS_ESTIMATE)} – #{company.primary_business.name}"
4
+ json.body "#{I18n.t(:estimate, scope: LocaleScope::SCOPE_NOTIFICATIONS_ESTIMATE)} #{estimate.statement_no} #{I18n.t(:sent_to, scope: LocaleScope::SCOPE_NOTIFICATIONS_ESTIMATE)} #{estimate.connection_name} #{I18n.t(:has_expired, scope: LocaleScope::SCOPE_NOTIFICATIONS_ESTIMATE)}"
5
+ json.icon "https://s3.amazonaws.com/hiveage-production/defaults/business_logo.png"
6
+ json.click_action Rails.application.routes.url_helpers.estimate_url(estimate, host: NotificationHubHelper.host_url(company),
7
+ protocol: NotificationHubHelper.account_schema(company))
8
+ end
9
+
@@ -0,0 +1,8 @@
1
+ company = estimate.company
2
+ json.notification do
3
+ json.title "#{I18n.t(:viewed, scope: LocaleScope::SCOPE_NOTIFICATIONS_ESTIMATE)} – #{company.primary_business.name}"
4
+ json.body "#{I18n.t(:estimate, scope: LocaleScope::SCOPE_NOTIFICATIONS_ESTIMATE)} #{estimate.statement_no} #{I18n.t(:viewed_by, scope: LocaleScope::SCOPE_NOTIFICATIONS_GENERIC)} #{estimate.connection_name}"
5
+ json.icon "https://s3.amazonaws.com/hiveage-production/defaults/business_logo.png"
6
+ json.click_action Rails.application.routes.url_helpers.estimate_url(estimate, host: NotificationHubHelper.host_url(company),
7
+ protocol: NotificationHubHelper.account_schema(company))
8
+ end
@@ -0,0 +1,8 @@
1
+ company = invoice.company
2
+ json.notification do
3
+ json.title "#{I18n.t(:overdue, scope: LocaleScope::SCOPE_NOTIFICATIONS_INVOICE)} – #{company.primary_business.name}"
4
+ json.body "#{I18n.t(:invoice, scope: LocaleScope::SCOPE_NOTIFICATIONS_INVOICE)} #{invoice.statement_no} #{I18n.t(:for, scope: LocaleScope::SCOPE_NOTIFICATIONS_GENERIC)} #{invoice.connection_name} #{I18n.t(:is_now_overdue, scope: LocaleScope::SCOPE_NOTIFICATIONS_INVOICE)}"
5
+ json.icon "https://s3.amazonaws.com/hiveage-production/defaults/business_logo.png"
6
+ json.click_action Rails.application.routes.url_helpers.invoice_url(invoice, host: NotificationHubHelper.host_url(company),
7
+ protocol: NotificationHubHelper.account_schema(company))
8
+ end
@@ -0,0 +1,8 @@
1
+ company = invoice.company
2
+ json.notification do
3
+ json.title "#{I18n.t(:payment_received, scope: LocaleScope::SCOPE_NOTIFICATIONS_INVOICE)} – #{company.primary_business.name}"
4
+ json.body "#{I18n.t(:payment_of, scope: LocaleScope::SCOPE_NOTIFICATIONS_INVOICE)} #{payment.currency} #{payment.amount.format_with_decimal(2)} (#{I18n.t(:via, scope: LocaleScope::SCOPE_NOTIFICATIONS_INVOICE)} #{payment.payment_method_name}) #{I18n.t(:received_from, scope: LocaleScope::SCOPE_NOTIFICATIONS_INVOICE)} #{invoice.connection_name}"
5
+ json.icon "https://s3.amazonaws.com/hiveage-production/defaults/business_logo.png"
6
+ json.click_action Rails.application.routes.url_helpers.invoice_url(invoice, host: NotificationHubHelper.host_url(company),
7
+ protocol: NotificationHubHelper.account_schema(company))
8
+ end
@@ -0,0 +1,9 @@
1
+ company = invoice.company
2
+ json.notification do
3
+ json.title "#{I18n.t(:payment_received, scope: LocaleScope::SCOPE_NOTIFICATIONS_INVOICE)} – #{company.primary_business.name}"
4
+ json.body "#{I18n.t(:unrealized_payment_of, scope: LocaleScope::SCOPE_NOTIFICATIONS_INVOICE)} #{payment.currency} #{payment.amount.format_with_decimal(2)} (#{I18n.t(:via, scope: LocaleScope::SCOPE_NOTIFICATIONS_INVOICE)} #{payment.payment_method_name}) #{I18n.t(:received_from, scope: LocaleScope::SCOPE_NOTIFICATIONS_INVOICE)} #{invoice.connection_name}"
5
+ json.icon "https://s3.amazonaws.com/hiveage-production/defaults/business_logo.png"
6
+ json.click_action Rails.application.routes.url_helpers.invoice_url(invoice, host: NotificationHubHelper.host_url(company),
7
+ protocol: NotificationHubHelper.account_schema(company))
8
+ end
9
+
@@ -0,0 +1,10 @@
1
+ company = invoice.company
2
+ json.notification do
3
+ json.title "#{I18n.t(:viewed, scope: LocaleScope::SCOPE_NOTIFICATIONS_INVOICE)} – #{company.primary_business.name}"
4
+ json.body "#{I18n.t(:invoice, scope: LocaleScope::SCOPE_NOTIFICATIONS_INVOICE)} #{invoice.statement_no} #{I18n.t(:viewed_by, scope: LocaleScope::SCOPE_NOTIFICATIONS_GENERIC)} #{invoice.connection_name}"
5
+ json.icon "https://s3.amazonaws.com/hiveage-production/defaults/business_logo.png"
6
+ json.click_action Rails.application.routes.url_helpers.invoice_url(invoice, host: NotificationHubHelper.host_url(company),
7
+ protocol: NotificationHubHelper.account_schema(company))
8
+ end
9
+
10
+
@@ -0,0 +1,10 @@
1
+ <%= render partial: "shared/system_emails/email_header", formats: :html %>
2
+
3
+ <p> <%= "#{I18n.t(:greeting, scope: LocaleScope::SCOPE_MESSAGES_GENERIC)} #{sanitize(@user.first_name)}," %> </p>
4
+ <p> <%= "#{I18n.t(:estimate, scope: LocaleScope::SCOPE_MESSAGES_GENERIC)} #{sanitize(@estimate.statement_no)} - #{I18n.t(:estimate, scope: LocaleScope::SCOPE_MESSAGES_GENERIC)} #{I18n.t(:accepted_by, scope: LocaleScope::SCOPE_MESSAGES_SPECIFIC)} #{sanitize(@estimate.business.connection_name)}." %> </p>
5
+ <p> <%= I18n.t(:more_details, scope: LocaleScope::SCOPE_MESSAGES_GENERIC) %>: </p>
6
+ <p> <%= link_to @estimate.formatted_estimate_url %> </p>
7
+ <p> &mdash; <%= I18n.t(:sent_by, scope: LocaleScope::SCOPE_MESSAGES_GENERIC) %> </p>
8
+
9
+ <%= render partial: "shared/system_emails/email_footer", formats: :html, locals: {notification_hub_message: true } %>
10
+
@@ -0,0 +1,9 @@
1
+ <%= "#{I18n.t(:greeting, scope: LocaleScope::SCOPE_MESSAGES_GENERIC)} #{sanitize(@user.first_name)}," %>
2
+
3
+ <%= "#{I18n.t(:estimate, scope: LocaleScope::SCOPE_MESSAGES_GENERIC)} #{sanitize(@estimate.statement_no)} - #{I18n.t(:estimate, scope: LocaleScope::SCOPE_MESSAGES_GENERIC)} #{I18n.t(:accepted_by, scope: LocaleScope::SCOPE_MESSAGES_SPECIFIC)} #{sanitize(@estimate.business.connection_name)}." %>
4
+
5
+ <%= I18n.t(:more_details, scope: LocaleScope::SCOPE_MESSAGES_GENERIC) %>:
6
+
7
+ <%= link_to @estimate.formatted_estimate_url %>
8
+
9
+ &mdash; <%= I18n.t(:sent_by, scope: LocaleScope::SCOPE_MESSAGES_GENERIC) %>
@@ -0,0 +1,9 @@
1
+ <%= render partial: "shared/system_emails/email_header", formats: :html %>
2
+
3
+ <p> <%= "#{I18n.t(:greeting, scope: LocaleScope::SCOPE_MESSAGES_GENERIC)} #{sanitize(@user.first_name)}," %> </p>
4
+ <p> <%= "#{I18n.t(:estimate, scope: LocaleScope::SCOPE_MESSAGES_GENERIC)} #{sanitize(@estimate.statement_no)} #{I18n.t(:sent_to, scope: LocaleScope::SCOPE_NOTIFICATIONS_ESTIMATE)} #{sanitize(@estimate.business.connection_name)} #{I18n.t(:expired_on, scope: LocaleScope::SCOPE_NOTIFICATIONS_ESTIMATE)} #{sanitize(@estimate.expire_date)}." %> </p>
5
+ <p> <%= I18n.t(:more_details, scope: LocaleScope::SCOPE_MESSAGES_GENERIC) %>: </p>
6
+ <p> <%= link_to @estimate.formatted_estimate_url %> </p>
7
+ <p> &mdash; <%= I18n.t(:sent_by, scope: LocaleScope::SCOPE_MESSAGES_GENERIC) %> </p>
8
+
9
+ <%= render partial: "shared/system_emails/email_footer", formats: :html, locals: {notification_hub_message: true } %>
@@ -0,0 +1,9 @@
1
+ <%= "#{I18n.t(:greeting, scope: LocaleScope::SCOPE_MESSAGES_GENERIC)} #{sanitize(@user.first_name)}," %>
2
+
3
+ <%= "#{I18n.t(:estimate, scope: LocaleScope::SCOPE_MESSAGES_GENERIC)} #{sanitize(@estimate.statement_no)} #{I18n.t(:sent_to, scope: LocaleScope::SCOPE_NOTIFICATIONS_ESTIMATE)} #{sanitize(@estimate.business.connection_name)} #{I18n.t(:expired_on, scope: LocaleScope::SCOPE_NOTIFICATIONS_ESTIMATE)} #{sanitize(@estimate.expire_date)}." %>
4
+
5
+ <%= I18n.t(:more_details, scope: LocaleScope::SCOPE_MESSAGES_GENERIC) %>:
6
+
7
+ <%= link_to @estimate.formatted_estimate_url %>
8
+
9
+ &mdash; <%= I18n.t(:sent_by, scope: LocaleScope::SCOPE_MESSAGES_GENERIC) %>
@@ -0,0 +1,9 @@
1
+ <%= render partial: "shared/system_emails/email_header", formats: :html %>
2
+
3
+ <p> <%= "#{I18n.t(:greeting, scope: LocaleScope::SCOPE_MESSAGES_GENERIC)} #{sanitize(@user.first_name)}," %> </p>
4
+ <p> <%= "#{I18n.t(:estimate, scope: LocaleScope::SCOPE_MESSAGES_GENERIC)} #{sanitize(@estimate.statement_no)} - #{I18n.t(:estimate, scope: LocaleScope::SCOPE_MESSAGES_GENERIC)} #{I18n.t(:viewed_by_downcase, scope: LocaleScope::SCOPE_MESSAGES_GENERIC)} #{sanitize(@estimate.business.connection_name)}." %> </p>
5
+ <p> <%= I18n.t(:more_details, scope: LocaleScope::SCOPE_MESSAGES_GENERIC) %>: </p>
6
+ <p> <%= link_to @estimate.formatted_estimate_url %> </p>
7
+ <p> &mdash; <%= I18n.t(:sent_by, scope: LocaleScope::SCOPE_MESSAGES_GENERIC) %> </p>
8
+
9
+ <%= render partial: "shared/system_emails/email_footer", formats: :html, locals: {notification_hub_message: true } %>
@@ -0,0 +1,9 @@
1
+ <%= "#{I18n.t(:greeting, scope: LocaleScope::SCOPE_MESSAGES_GENERIC)} #{sanitize(@user.first_name)}," %>
2
+
3
+ <%= "#{I18n.t(:estimate, scope: LocaleScope::SCOPE_MESSAGES_GENERIC)} #{sanitize(@estimate.statement_no)} - #{I18n.t(:estimate, scope: LocaleScope::SCOPE_MESSAGES_GENERIC)} #{I18n.t(:viewed_by_downcase, scope: LocaleScope::SCOPE_MESSAGES_GENERIC)} #{sanitize(@estimate.business.connection_name)}." %>
4
+
5
+ <%= I18n.t(:more_details, scope: LocaleScope::SCOPE_MESSAGES_GENERIC) %>:
6
+
7
+ <%= link_to @estimate.formatted_estimate_url %>
8
+
9
+ &mdash; <%= I18n.t(:sent_by, scope: LocaleScope::SCOPE_MESSAGES_GENERIC) %>
@@ -0,0 +1,9 @@
1
+ <%= render partial: "shared/system_emails/email_header", formats: :html %>
2
+
3
+ <p> <%= "#{I18n.t(:greeting, scope: LocaleScope::SCOPE_MESSAGES_GENERIC)} #{sanitize(@user.first_name)}," %> </p>
4
+ <p> <%= "#{I18n.t(:invoice, scope: LocaleScope::SCOPE_NOTIFICATIONS_INVOICE)} #{sanitize(@invoice.statement_no)} #{I18n.t(:for, scope: LocaleScope::SCOPE_NOTIFICATIONS_GENERIC)} #{sanitize(@invoice.business.connection_name)} #{I18n.t(:is_now_overdue, scope: LocaleScope::SCOPE_NOTIFICATIONS_INVOICE)}." %> </p>
5
+ <p> <%= I18n.t(:more_details, scope: LocaleScope::SCOPE_MESSAGES_GENERIC) %>: </p>
6
+ <p> <%= link_to @invoice.formatted_invoice_url %> </p>
7
+ <p> &mdash; <%= I18n.t(:sent_by, scope: LocaleScope::SCOPE_MESSAGES_GENERIC) %> </p>
8
+
9
+ <%= render partial: "shared/system_emails/email_footer", formats: :html, locals: {notification_hub_message: true } %>
@@ -0,0 +1,9 @@
1
+ <%= "#{I18n.t(:greeting, scope: LocaleScope::SCOPE_MESSAGES_GENERIC)} #{sanitize(@user.first_name)}," %>
2
+
3
+ <%= "#{I18n.t(:invoice, scope: LocaleScope::SCOPE_NOTIFICATIONS_INVOICE)} #{sanitize(@invoice.statement_no)} #{I18n.t(:for, scope: LocaleScope::SCOPE_NOTIFICATIONS_GENERIC)} #{sanitize(@invoice.business.connection_name)} #{I18n.t(:is_now_overdue, scope: LocaleScope::SCOPE_NOTIFICATIONS_INVOICE)}." %>
4
+
5
+ <%= I18n.t(:more_details, scope: LocaleScope::SCOPE_MESSAGES_GENERIC) %>:
6
+
7
+ <%= link_to @invoice.formatted_invoice_url %>
8
+
9
+ &mdash; <%= I18n.t(:sent_by, scope: LocaleScope::SCOPE_MESSAGES_GENERIC) %>
@@ -0,0 +1,11 @@
1
+ <%= render partial: "shared/system_emails/email_header", formats: :html %>
2
+
3
+ <p> <%= "#{I18n.t(:greeting, scope: LocaleScope::SCOPE_MESSAGES_GENERIC)} #{sanitize(@user.first_name)}," %> </p>
4
+ <p> <%= "#{I18n.t(:recieved_payment, scope: LocaleScope::SCOPE_MESSAGES_SPECIFIC)} #{sanitize(@invoice.business.connection_name)}." %> </p>
5
+ <p> <%= "#{I18n.t(:invoice, scope: LocaleScope::SCOPE_MESSAGES_GENERIC)}: #{sanitize(@invoice.statement_no)}" %> </p>
6
+ <p> <%= "#{I18n.t(:amount_paid, scope: LocaleScope::SCOPE_MESSAGES_SPECIFIC)}: #{sanitize(@payment.currency)} #{sanitize(@payment.amount.format_with_decimal(2))} (#{I18n.t(:via, scope: LocaleScope::SCOPE_MESSAGES_SPECIFIC)} #{@payment.payment_method_name})" %> </p>
7
+ <p> <%= I18n.t(:more_details, scope: LocaleScope::SCOPE_MESSAGES_GENERIC) %>: </p>
8
+ <p> <%= link_to @invoice.formatted_invoice_url %> </p>
9
+ <p> &mdash; <%= I18n.t(:sent_by, scope: LocaleScope::SCOPE_MESSAGES_GENERIC) %> </p>
10
+
11
+ <%= render partial: "shared/system_emails/email_footer", formats: :html, locals: {notification_hub_message: true } %>
@@ -0,0 +1,13 @@
1
+ <%= "#{I18n.t(:greeting, scope: LocaleScope::SCOPE_MESSAGES_GENERIC)} #{sanitize(@user.first_name)}," %>
2
+
3
+ <%= "#{I18n.t(:recieved_payment, scope: LocaleScope::SCOPE_MESSAGES_SPECIFIC)} #{sanitize(@invoice.business.connection_name)}." %>
4
+
5
+ <%= "#{I18n.t(:invoice, scope: LocaleScope::SCOPE_MESSAGES_GENERIC)}: #{sanitize(@invoice.statement_no)}" %>
6
+
7
+ <%= "#{I18n.t(:amount_paid, scope: LocaleScope::SCOPE_MESSAGES_SPECIFIC)}: #{sanitize(@payment.currency)} #{sanitize(@payment.amount.format_with_decimal(2))} (#{I18n.t(:via, scope: LocaleScope::SCOPE_MESSAGES_SPECIFIC)} #{@payment.payment_method_name})" %>
8
+
9
+ <%= I18n.t(:more_details, scope: LocaleScope::SCOPE_MESSAGES_GENERIC) %>:
10
+
11
+ <%= link_to @invoice.formatted_invoice_url %>
12
+
13
+ &mdash; <%= I18n.t(:sent_by, scope: LocaleScope::SCOPE_MESSAGES_GENERIC) %>