devise_slack_notifiable 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 405a786a39943e716f064ab9fbb0f40f93c0d48b6e8ebb9bd9890041ecc85ef7
4
+ data.tar.gz: a39dbf5d465f6b475e4c408dc80ccb27227806a449da6925348c8e728ae279c3
5
+ SHA512:
6
+ metadata.gz: 1476715f8668cc552ac89fa267b6e2e5f133381b24f2454a0b93c5356b3de3de47a1222c4b845c7842860386bb5df7e35eff68767e955a55574caa3091df62c2
7
+ data.tar.gz: 27a0e40a15f0fe22ba041278e503287b5619518ccec0490a611137325cb3fd6ca41f939af421dbb7bfe436fed9cc52bcc6ccf8b0f60ff0874dcf690b3235825e
@@ -0,0 +1,9 @@
1
+ root = true
2
+
3
+ [*]
4
+ indent_style = space
5
+ indent_size = 2
6
+ end_of_line = lf
7
+ charset = utf-8
8
+ trim_trailing_whitespace = true
9
+ insert_final_newline = true
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ # IntelliJ
14
+ .idea/
15
+ devise_slack_notifiable.iml
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,12 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.6.5
6
+ before_install: gem install bundler -v 2.1.4
7
+
8
+ deploy:
9
+ provider: rubygems
10
+ api_key: "YOUR API KEY"
11
+ on:
12
+ tags: true
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at whitemerry@outlook.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in devise_slack_notifiable.gemspec
6
+ gemspec
7
+
8
+ gem 'rake', '~> 12.0'
9
+ gem 'rspec', '~> 3.0'
10
+ gem 'slack-notifier'
@@ -0,0 +1,160 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ devise_slack_notifiable (0.1.0)
5
+ rails
6
+ slack-notifier
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actioncable (6.0.3.2)
12
+ actionpack (= 6.0.3.2)
13
+ nio4r (~> 2.0)
14
+ websocket-driver (>= 0.6.1)
15
+ actionmailbox (6.0.3.2)
16
+ actionpack (= 6.0.3.2)
17
+ activejob (= 6.0.3.2)
18
+ activerecord (= 6.0.3.2)
19
+ activestorage (= 6.0.3.2)
20
+ activesupport (= 6.0.3.2)
21
+ mail (>= 2.7.1)
22
+ actionmailer (6.0.3.2)
23
+ actionpack (= 6.0.3.2)
24
+ actionview (= 6.0.3.2)
25
+ activejob (= 6.0.3.2)
26
+ mail (~> 2.5, >= 2.5.4)
27
+ rails-dom-testing (~> 2.0)
28
+ actionpack (6.0.3.2)
29
+ actionview (= 6.0.3.2)
30
+ activesupport (= 6.0.3.2)
31
+ rack (~> 2.0, >= 2.0.8)
32
+ rack-test (>= 0.6.3)
33
+ rails-dom-testing (~> 2.0)
34
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
35
+ actiontext (6.0.3.2)
36
+ actionpack (= 6.0.3.2)
37
+ activerecord (= 6.0.3.2)
38
+ activestorage (= 6.0.3.2)
39
+ activesupport (= 6.0.3.2)
40
+ nokogiri (>= 1.8.5)
41
+ actionview (6.0.3.2)
42
+ activesupport (= 6.0.3.2)
43
+ builder (~> 3.1)
44
+ erubi (~> 1.4)
45
+ rails-dom-testing (~> 2.0)
46
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
47
+ activejob (6.0.3.2)
48
+ activesupport (= 6.0.3.2)
49
+ globalid (>= 0.3.6)
50
+ activemodel (6.0.3.2)
51
+ activesupport (= 6.0.3.2)
52
+ activerecord (6.0.3.2)
53
+ activemodel (= 6.0.3.2)
54
+ activesupport (= 6.0.3.2)
55
+ activestorage (6.0.3.2)
56
+ actionpack (= 6.0.3.2)
57
+ activejob (= 6.0.3.2)
58
+ activerecord (= 6.0.3.2)
59
+ marcel (~> 0.3.1)
60
+ activesupport (6.0.3.2)
61
+ concurrent-ruby (~> 1.0, >= 1.0.2)
62
+ i18n (>= 0.7, < 2)
63
+ minitest (~> 5.1)
64
+ tzinfo (~> 1.1)
65
+ zeitwerk (~> 2.2, >= 2.2.2)
66
+ builder (3.2.4)
67
+ concurrent-ruby (1.1.6)
68
+ crass (1.0.6)
69
+ diff-lcs (1.3)
70
+ erubi (1.9.0)
71
+ globalid (0.4.2)
72
+ activesupport (>= 4.2.0)
73
+ i18n (1.8.3)
74
+ concurrent-ruby (~> 1.0)
75
+ loofah (2.6.0)
76
+ crass (~> 1.0.2)
77
+ nokogiri (>= 1.5.9)
78
+ mail (2.7.1)
79
+ mini_mime (>= 0.1.1)
80
+ marcel (0.3.3)
81
+ mimemagic (~> 0.3.2)
82
+ method_source (1.0.0)
83
+ mimemagic (0.3.5)
84
+ mini_mime (1.0.2)
85
+ mini_portile2 (2.4.0)
86
+ minitest (5.14.1)
87
+ nio4r (2.5.2)
88
+ nokogiri (1.10.9-x64-mingw32)
89
+ mini_portile2 (~> 2.4.0)
90
+ rack (2.2.3)
91
+ rack-test (1.1.0)
92
+ rack (>= 1.0, < 3)
93
+ rails (6.0.3.2)
94
+ actioncable (= 6.0.3.2)
95
+ actionmailbox (= 6.0.3.2)
96
+ actionmailer (= 6.0.3.2)
97
+ actionpack (= 6.0.3.2)
98
+ actiontext (= 6.0.3.2)
99
+ actionview (= 6.0.3.2)
100
+ activejob (= 6.0.3.2)
101
+ activemodel (= 6.0.3.2)
102
+ activerecord (= 6.0.3.2)
103
+ activestorage (= 6.0.3.2)
104
+ activesupport (= 6.0.3.2)
105
+ bundler (>= 1.3.0)
106
+ railties (= 6.0.3.2)
107
+ sprockets-rails (>= 2.0.0)
108
+ rails-dom-testing (2.0.3)
109
+ activesupport (>= 4.2.0)
110
+ nokogiri (>= 1.6)
111
+ rails-html-sanitizer (1.3.0)
112
+ loofah (~> 2.3)
113
+ railties (6.0.3.2)
114
+ actionpack (= 6.0.3.2)
115
+ activesupport (= 6.0.3.2)
116
+ method_source
117
+ rake (>= 0.8.7)
118
+ thor (>= 0.20.3, < 2.0)
119
+ rake (12.3.3)
120
+ rspec (3.9.0)
121
+ rspec-core (~> 3.9.0)
122
+ rspec-expectations (~> 3.9.0)
123
+ rspec-mocks (~> 3.9.0)
124
+ rspec-core (3.9.2)
125
+ rspec-support (~> 3.9.3)
126
+ rspec-expectations (3.9.2)
127
+ diff-lcs (>= 1.2.0, < 2.0)
128
+ rspec-support (~> 3.9.0)
129
+ rspec-mocks (3.9.1)
130
+ diff-lcs (>= 1.2.0, < 2.0)
131
+ rspec-support (~> 3.9.0)
132
+ rspec-support (3.9.3)
133
+ slack-notifier (2.3.2)
134
+ sprockets (3.7.2)
135
+ concurrent-ruby (~> 1.0)
136
+ rack (> 1, < 3)
137
+ sprockets-rails (3.2.1)
138
+ actionpack (>= 4.0)
139
+ activesupport (>= 4.0)
140
+ sprockets (>= 3.0.0)
141
+ thor (1.0.1)
142
+ thread_safe (0.3.6)
143
+ tzinfo (1.2.7)
144
+ thread_safe (~> 0.1)
145
+ websocket-driver (0.7.2)
146
+ websocket-extensions (>= 0.1.0)
147
+ websocket-extensions (0.1.5)
148
+ zeitwerk (2.3.0)
149
+
150
+ PLATFORMS
151
+ x64-mingw32
152
+
153
+ DEPENDENCIES
154
+ devise_slack_notifiable!
155
+ rake (~> 12.0)
156
+ rspec (~> 3.0)
157
+ slack-notifier
158
+
159
+ BUNDLED WITH
160
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 whitemerry
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.
@@ -0,0 +1,125 @@
1
+ # DeviseSlackNotifiable
2
+
3
+ Devise slack notifications gem. It posts message after registration and confirmation (if Devise confirmations strategy is enabled).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'devise_slack_notifiable'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install devise_slack_notifiable
20
+
21
+ ## Usage
22
+
23
+ ### 1. Slack
24
+ Prepare Slack Webhook - it should look like `https://hooks.slack.com/services/XXX/XXX/XXX`.
25
+
26
+ Not sure how to do that? Check out [slack documentation](https://api.slack.com/messaging/webhooks#getting_started).
27
+
28
+ ### 2. Application
29
+ After preparing Slack Webhook create initializer - `config/initializers/devise_slack_notifiable.rb`:
30
+ ```ruby
31
+ DeviseSlackNotifiable.configure do |config|
32
+ # Enabled state
33
+ # By default integration is disabled. You need to enable it manually on desired environments.
34
+ # For example production only:
35
+ # config.enabled = Rails.env.production?
36
+ # Default: false
37
+ config.enabled = true
38
+
39
+ # Slack Webhook URL
40
+ # Required when integration enabled.
41
+ # It's recommended to use rails credentials instead of raw url (https://edgeguides.rubyonrails.org/security.html#custom-credentials)
42
+ # Default: nil
43
+ config.slack_webhook = 'YOUR_SLACK_WEBHOOK_URL'
44
+
45
+ # Confirmation message state
46
+ # If You want You can disable sending confirmation message:
47
+ # config.confirmation_message_enabled
48
+ # Default: true
49
+
50
+ # Context fields
51
+ # To all messages sent there is context attached that adds entity fields.
52
+ # If You want to customize fields:
53
+ # config.context_fields = [:id, :email, :first_name, :last_name]
54
+ # Default: [:id, :email]
55
+ end
56
+ ```
57
+
58
+ After creating initializer add `:slack_notifiable` to the devise call in your model (we’re assuming here you already have a User model with some Devise modules):
59
+ ```ruby
60
+ class User < ActiveRecord::Base
61
+ devise :database_authenticatable, :confirmable, :slack_notifiable
62
+ end
63
+ ```
64
+
65
+ And you are ready to go!
66
+
67
+ ## Messages
68
+ Messages overview:
69
+
70
+ ![Registration notification](./docs/registration-notification.png)
71
+ ![Confirmation notification](./docs/confirmation-notification.png)
72
+
73
+ ### Customization
74
+
75
+ #### Context
76
+ If You want to add more fields to context check out configuration in initializer - it's based on `context_fields`.
77
+
78
+ Example with context extended by first and last name (as on screenshots):
79
+ ```ruby
80
+ config.context_fields = [:id, :email, :first_name, :last_name]
81
+ ```
82
+
83
+ #### Sending own messages
84
+ You can send own messages with this context for anywhere You want inside rails application:
85
+ ```ruby
86
+ # Let's assume that customer with id 1 asked for sales contact
87
+ user = User.find(1)
88
+ formatter = ->(entity) { "Customer #{entity.id} asked for sales contact!" }
89
+
90
+ notifier = DeviseSlackNotifiable::Notifier.new
91
+ notifier.send_message(user, formatter)
92
+ ```
93
+
94
+ #### Message formatting
95
+ You can customize messages by initializer:
96
+ ```ruby
97
+ config.registration_message_formatter = lambda { |entity|
98
+ "Yeah 🎉! Looks like we have new #{entity.model_name.human}! 😊"
99
+ }
100
+ ```
101
+
102
+ ```ruby
103
+ config.confirmation_message_formatter = lambda { |entity|
104
+ "#{entity.model_name.human} have just confirmed his account 🥂"
105
+ }
106
+ ```
107
+
108
+ ## Development
109
+
110
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
111
+
112
+ 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).
113
+
114
+ ## Contributing
115
+
116
+ Bug reports and pull requests are welcome on GitHub at https://github.com/invoicity/devise_slack_notifiable. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/invoicity/devise_slack_notifiable/blob/master/CODE_OF_CONDUCT.md).
117
+
118
+
119
+ ## License
120
+
121
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
122
+
123
+ ## Code of Conduct
124
+
125
+ Everyone interacting in the DeviseSlackNotifiable project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/devise_slack_notifiable/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "devise_slack_notifiable"
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(__FILE__)
@@ -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,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/devise_slack_notifiable/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'devise_slack_notifiable'
7
+ spec.version = DeviseSlackNotifiable::VERSION
8
+ spec.authors = ['whitemerry']
9
+ spec.email = ['whitemerry@outlook.com']
10
+
11
+ spec.summary = 'Devise slack notifactions gem'
12
+ # spec.description = 'TODO: Write a longer description or delete this line.'
13
+ spec.homepage = 'https://github.com/invoicity/devise_slack_notifiable'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
16
+
17
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
18
+
19
+ spec.metadata['homepage_uri'] = spec.homepage
20
+ spec.metadata['source_code_uri'] = 'https://github.com/invoicity/devise_slack_notifiable'
21
+ spec.metadata['changelog_uri'] = 'https://github.com/invoicity/devise_slack_notifiable/releases'
22
+
23
+ spec.add_dependency 'rails'
24
+ spec.add_dependency 'slack-notifier'
25
+
26
+ # Specify which files should be added to the gem when it is released.
27
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
28
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
29
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
30
+ end
31
+ spec.bindir = 'exe'
32
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
+ spec.require_paths = ['lib']
34
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Devise
4
+ module Models
5
+ module SlackNotifiable
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ after_create :registration_notification
10
+
11
+ protected
12
+
13
+ def after_confirmation
14
+ confirmation_notification
15
+
16
+ super
17
+ end
18
+
19
+ def confirmation_notification
20
+ return unless DeviseSlackNotifiable.configuration.confirmation_message_enabled
21
+
22
+ send_slack_notification(
23
+ DeviseSlackNotifiable.configuration.confirmation_message_formatter
24
+ )
25
+ end
26
+
27
+ def registration_notification
28
+ send_slack_notification(
29
+ DeviseSlackNotifiable.configuration.registration_message_formatter
30
+ )
31
+ end
32
+
33
+ private
34
+
35
+ def send_slack_notification(formatter)
36
+ notifier = DeviseSlackNotifiable::Notifier.new
37
+ notifier.send_message(self, formatter)
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'devise_slack_notifiable/version'
4
+ require 'devise_slack_notifiable/configuration'
5
+ require 'devise_slack_notifiable/notifier'
6
+ require 'devise_slack_notifiable/errors/configuration'
7
+ require 'devise/models/slack_notifiable'
8
+
9
+ module DeviseSlackNotifiable
10
+ class << self
11
+ attr_accessor :configuration
12
+ end
13
+
14
+ def self.configure
15
+ self.configuration ||= DeviseSlackNotifiable::Configuration.new
16
+ yield(configuration)
17
+ end
18
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DeviseSlackNotifiable
4
+ class Configuration
5
+ attr_accessor :enabled,
6
+ :slack_webhook,
7
+ :registration_message_formatter,
8
+ :confirmation_message_formatter,
9
+ :confirmation_message_enabled,
10
+ :context_fields
11
+
12
+ def initialize
13
+ @enabled = false
14
+ @slack_webhook = nil
15
+ @confirmation_message_enabled = true
16
+
17
+ @context_fields = %i[id email]
18
+
19
+ @registration_message_formatter = lambda { |entity|
20
+ "Yeah 🎉! Looks like we have new #{entity.model_name.human}! 😊"
21
+ }
22
+
23
+ @confirmation_message_formatter = lambda { |entity|
24
+ "#{entity.model_name.human} have just confirmed his account 🥂"
25
+ }
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DeviseSlackNotifiable
4
+ module Errors
5
+ class Configuration < StandardError; end
6
+ end
7
+ end
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'slack-notifier'
4
+
5
+ module DeviseSlackNotifiable
6
+ class Notifier
7
+ def initialize
8
+ return unless enabled?
9
+
10
+ raise DeviseSlackNotifiable::Errors::Configuration, 'Missing Slack Webhook URL' unless webhook
11
+
12
+ @client = Slack::Notifier.new(webhook)
13
+ end
14
+
15
+ # Sends slack message
16
+ #
17
+ # @param [Model] entity
18
+ # @param [Proc] message_formatter
19
+ def send_message(entity, message_formatter)
20
+ return true unless enabled?
21
+
22
+ @client.ping(
23
+ formatter(
24
+ message_formatter.call(entity),
25
+ entity
26
+ )
27
+ )
28
+ end
29
+
30
+ protected
31
+
32
+ attr_reader :client
33
+
34
+ def enabled?
35
+ DeviseSlackNotifiable.configuration.enabled
36
+ end
37
+
38
+ def webhook
39
+ DeviseSlackNotifiable.configuration.slack_webhook
40
+ end
41
+
42
+ def context_fields
43
+ DeviseSlackNotifiable.configuration.context_fields
44
+ end
45
+
46
+ def formatter(message, entity)
47
+ {
48
+ blocks: [
49
+ {
50
+ type: 'section',
51
+ text: {
52
+ type: 'plain_text',
53
+ text: message,
54
+ emoji: true
55
+ }
56
+ },
57
+ {
58
+ type: 'divider'
59
+ },
60
+ {
61
+ type: 'section',
62
+ text: {
63
+ type: 'plain_text',
64
+ text: 'Context:',
65
+ emoji: true
66
+ }
67
+ },
68
+ {
69
+ type: 'section',
70
+ fields: context_fields.map do |field|
71
+ {
72
+ type: 'mrkdwn',
73
+ text: "*#{field.to_s.humanize}:* #{entity.send(field)}"
74
+ }
75
+ end
76
+ }
77
+ ]
78
+ }
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DeviseSlackNotifiable
4
+ VERSION = '0.1.0'
5
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: devise_slack_notifiable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - whitemerry
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-06-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: slack-notifier
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description:
42
+ email:
43
+ - whitemerry@outlook.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".editorconfig"
49
+ - ".gitignore"
50
+ - ".rspec"
51
+ - ".travis.yml"
52
+ - CODE_OF_CONDUCT.md
53
+ - Gemfile
54
+ - Gemfile.lock
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - bin/console
59
+ - bin/setup
60
+ - devise_slack_notifiable.gemspec
61
+ - docs/confirmation-notification.png
62
+ - docs/registration-notification.png
63
+ - lib/devise/models/slack_notifiable.rb
64
+ - lib/devise_slack_notifiable.rb
65
+ - lib/devise_slack_notifiable/configuration.rb
66
+ - lib/devise_slack_notifiable/errors/configuration.rb
67
+ - lib/devise_slack_notifiable/notifier.rb
68
+ - lib/devise_slack_notifiable/version.rb
69
+ homepage: https://github.com/invoicity/devise_slack_notifiable
70
+ licenses:
71
+ - MIT
72
+ metadata:
73
+ allowed_push_host: https://rubygems.org
74
+ homepage_uri: https://github.com/invoicity/devise_slack_notifiable
75
+ source_code_uri: https://github.com/invoicity/devise_slack_notifiable
76
+ changelog_uri: https://github.com/invoicity/devise_slack_notifiable/releases
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: 2.3.0
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubygems_version: 3.0.3
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Devise slack notifactions gem
96
+ test_files: []