exception_notification-lark-notifier 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4e0a0ee12c91e89f27b20f8af7803b09cc1cad5c4c81de4f4740add60409af83
4
+ data.tar.gz: 5c9d14db23ec2f71276cd1cfbfe026fdc620f465dee858b32a5f2876903ee3c8
5
+ SHA512:
6
+ metadata.gz: 2045bebbcc8ef6f9428b28c80203660d37109fc96267b9123a2e0e00872b91b4914ca12695bf2e153d0d86e2df1715ce7129fb62d7be95e098da2fc432425350
7
+ data.tar.gz: b3bc14d8e61f6caa17d373becb1baeca121ba0b0892c6a28fa7db5664c601f4431b30731ad6356cd190ca78bdf4e49ca4a61282c1364e3458d5b4a5a3eebfee2
data/.editorconfig ADDED
@@ -0,0 +1,9 @@
1
+ root = true
2
+
3
+ [*]
4
+ charset = utf-8
5
+ indent_style = space
6
+ indent_size = 2
7
+ insert_final_newline = true
8
+ trim_trailing_whitespace = true
9
+ end_of_line = lf
data/.env.defaults ADDED
@@ -0,0 +1,2 @@
1
+ LARK_NOTIFIER_WEBHOOK_URL="https://open.larksuite.com/open-apis/bot/v2/hook/xxxxxxxxxxxxxxxxx"
2
+ LARK_NOTIFIER_WEBHOOK_SECRET="123456"
data/.overcommit.yml ADDED
@@ -0,0 +1,30 @@
1
+ # Use this file to configure the Overcommit hooks you wish to use. This will
2
+ # extend the default configuration defined in:
3
+ # https://github.com/sds/overcommit/blob/master/config/default.yml
4
+ #
5
+ # At the topmost level of this YAML file is a key representing type of hook
6
+ # being run (e.g. pre-commit, commit-msg, etc.). Within each type you can
7
+ # customize each hook, such as whether to only run it on certain files (via
8
+ # `include`), whether to only display output if it fails (via `quiet`), etc.
9
+ #
10
+ # For a complete list of hooks, see:
11
+ # https://github.com/sds/overcommit/tree/master/lib/overcommit/hook
12
+ #
13
+ # For a complete list of options that you can use to customize hooks, see:
14
+ # https://github.com/sds/overcommit#configuration
15
+ #
16
+ # Uncomment the following lines to make the configuration take effect.
17
+
18
+ CommitMsg:
19
+ CapitalizedSubject:
20
+ enabled: false
21
+
22
+ PreCommit:
23
+ RuboCop:
24
+ enabled: true
25
+ command: 'bin/rubocop'
26
+
27
+ PrePush:
28
+ RSpec:
29
+ enabled: true
30
+ command: 'bin/rspec'
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,12 @@
1
+ require: standard
2
+
3
+ inherit_gem:
4
+ standard: config/base.yml
5
+
6
+ AllCops:
7
+ SuggestExtensions: false
8
+ TargetRubyVersion: 2.7
9
+ Exclude:
10
+ - 'bin/**/*'
11
+ - 'vendor/**/*'
12
+
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.1.1
data/.yardopts ADDED
@@ -0,0 +1,2 @@
1
+ --markup=markdown
2
+ --markup-provider=redcarpet
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at johndoe@example.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in exception_notification-lark-notifier.gemspec
6
+ gemspec
7
+
8
+ # rake
9
+ gem "rake", "~> 13.0"
10
+
11
+ # lint
12
+ gem "rubocop", "~> 1.29"
13
+ gem "standard", "~> 1.12"
14
+
15
+ # test
16
+ gem "dotenv", "~> 2.7"
17
+ gem "rspec", "~> 3.0"
18
+ gem "vcr", "~> 6.0"
19
+ gem "webmock", "~> 3.18"
20
+
21
+ # doc
22
+ gem "yard", "~> 0.9"
23
+ gem "redcarpet", "~> 3.5"
24
+
25
+ # misc
26
+ gem "overcommit", "~> 0.59"
data/Gemfile.lock ADDED
@@ -0,0 +1,192 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ exception_notification-lark-notifier (0.0.1)
5
+ exception_notification (~> 4.0)
6
+ http (~> 5.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actionmailer (7.0.4)
12
+ actionpack (= 7.0.4)
13
+ actionview (= 7.0.4)
14
+ activejob (= 7.0.4)
15
+ activesupport (= 7.0.4)
16
+ mail (~> 2.5, >= 2.5.4)
17
+ net-imap
18
+ net-pop
19
+ net-smtp
20
+ rails-dom-testing (~> 2.0)
21
+ actionpack (7.0.4)
22
+ actionview (= 7.0.4)
23
+ activesupport (= 7.0.4)
24
+ rack (~> 2.0, >= 2.2.0)
25
+ rack-test (>= 0.6.3)
26
+ rails-dom-testing (~> 2.0)
27
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
28
+ actionview (7.0.4)
29
+ activesupport (= 7.0.4)
30
+ builder (~> 3.1)
31
+ erubi (~> 1.4)
32
+ rails-dom-testing (~> 2.0)
33
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
34
+ activejob (7.0.4)
35
+ activesupport (= 7.0.4)
36
+ globalid (>= 0.3.6)
37
+ activesupport (7.0.4)
38
+ concurrent-ruby (~> 1.0, >= 1.0.2)
39
+ i18n (>= 1.6, < 2)
40
+ minitest (>= 5.1)
41
+ tzinfo (~> 2.0)
42
+ addressable (2.8.1)
43
+ public_suffix (>= 2.0.2, < 6.0)
44
+ ast (2.4.2)
45
+ builder (3.2.4)
46
+ childprocess (4.1.0)
47
+ concurrent-ruby (1.1.10)
48
+ crack (0.4.5)
49
+ rexml
50
+ crass (1.0.6)
51
+ date (3.3.3)
52
+ diff-lcs (1.5.0)
53
+ domain_name (0.5.20190701)
54
+ unf (>= 0.0.5, < 1.0.0)
55
+ dotenv (2.8.1)
56
+ erubi (1.12.0)
57
+ exception_notification (4.5.0)
58
+ actionmailer (>= 5.2, < 8)
59
+ activesupport (>= 5.2, < 8)
60
+ ffi (1.15.5)
61
+ ffi-compiler (1.0.1)
62
+ ffi (>= 1.0.0)
63
+ rake
64
+ globalid (1.0.0)
65
+ activesupport (>= 5.0)
66
+ hashdiff (1.0.1)
67
+ http (5.1.1)
68
+ addressable (~> 2.8)
69
+ http-cookie (~> 1.0)
70
+ http-form_data (~> 2.2)
71
+ llhttp-ffi (~> 0.4.0)
72
+ http-cookie (1.0.5)
73
+ domain_name (~> 0.5)
74
+ http-form_data (2.3.0)
75
+ i18n (1.12.0)
76
+ concurrent-ruby (~> 1.0)
77
+ iniparse (1.5.0)
78
+ json (2.6.3)
79
+ language_server-protocol (3.17.0.2)
80
+ llhttp-ffi (0.4.0)
81
+ ffi-compiler (~> 1.0)
82
+ rake (~> 13.0)
83
+ loofah (2.19.1)
84
+ crass (~> 1.0.2)
85
+ nokogiri (>= 1.5.9)
86
+ mail (2.8.0)
87
+ mini_mime (>= 0.1.1)
88
+ net-imap
89
+ net-pop
90
+ net-smtp
91
+ mini_mime (1.1.2)
92
+ minitest (5.16.3)
93
+ net-imap (0.3.4)
94
+ date
95
+ net-protocol
96
+ net-pop (0.1.2)
97
+ net-protocol
98
+ net-protocol (0.2.1)
99
+ timeout
100
+ net-smtp (0.3.3)
101
+ net-protocol
102
+ nokogiri (1.13.10-x86_64-linux)
103
+ racc (~> 1.4)
104
+ overcommit (0.59.1)
105
+ childprocess (>= 0.6.3, < 5)
106
+ iniparse (~> 1.4)
107
+ rexml (~> 3.2)
108
+ parallel (1.22.1)
109
+ parser (3.1.3.0)
110
+ ast (~> 2.4.1)
111
+ public_suffix (5.0.1)
112
+ racc (1.6.2)
113
+ rack (2.2.5)
114
+ rack-test (2.0.2)
115
+ rack (>= 1.3)
116
+ rails-dom-testing (2.0.3)
117
+ activesupport (>= 4.2.0)
118
+ nokogiri (>= 1.6)
119
+ rails-html-sanitizer (1.4.4)
120
+ loofah (~> 2.19, >= 2.19.1)
121
+ rainbow (3.1.1)
122
+ rake (13.0.6)
123
+ redcarpet (3.5.1)
124
+ regexp_parser (2.6.1)
125
+ rexml (3.2.5)
126
+ rspec (3.12.0)
127
+ rspec-core (~> 3.12.0)
128
+ rspec-expectations (~> 3.12.0)
129
+ rspec-mocks (~> 3.12.0)
130
+ rspec-core (3.12.0)
131
+ rspec-support (~> 3.12.0)
132
+ rspec-expectations (3.12.1)
133
+ diff-lcs (>= 1.2.0, < 2.0)
134
+ rspec-support (~> 3.12.0)
135
+ rspec-mocks (3.12.1)
136
+ diff-lcs (>= 1.2.0, < 2.0)
137
+ rspec-support (~> 3.12.0)
138
+ rspec-support (3.12.0)
139
+ rubocop (1.40.0)
140
+ json (~> 2.3)
141
+ parallel (~> 1.10)
142
+ parser (>= 3.1.2.1)
143
+ rainbow (>= 2.2.2, < 4.0)
144
+ regexp_parser (>= 1.8, < 3.0)
145
+ rexml (>= 3.2.5, < 4.0)
146
+ rubocop-ast (>= 1.23.0, < 2.0)
147
+ ruby-progressbar (~> 1.7)
148
+ unicode-display_width (>= 1.4.0, < 3.0)
149
+ rubocop-ast (1.24.0)
150
+ parser (>= 3.1.1.0)
151
+ rubocop-performance (1.15.1)
152
+ rubocop (>= 1.7.0, < 2.0)
153
+ rubocop-ast (>= 0.4.0)
154
+ ruby-progressbar (1.11.0)
155
+ standard (1.20.0)
156
+ language_server-protocol (~> 3.17.0.2)
157
+ rubocop (= 1.40.0)
158
+ rubocop-performance (= 1.15.1)
159
+ timeout (0.3.1)
160
+ tzinfo (2.0.5)
161
+ concurrent-ruby (~> 1.0)
162
+ unf (0.1.4)
163
+ unf_ext
164
+ unf_ext (0.0.8.2)
165
+ unicode-display_width (2.3.0)
166
+ vcr (6.1.0)
167
+ webmock (3.18.1)
168
+ addressable (>= 2.8.0)
169
+ crack (>= 0.3.2)
170
+ hashdiff (>= 0.4.0, < 2.0.0)
171
+ webrick (1.7.0)
172
+ yard (0.9.28)
173
+ webrick (~> 1.7.0)
174
+
175
+ PLATFORMS
176
+ x86_64-linux
177
+
178
+ DEPENDENCIES
179
+ dotenv (~> 2.7)
180
+ exception_notification-lark-notifier!
181
+ overcommit (~> 0.59)
182
+ rake (~> 13.0)
183
+ redcarpet (~> 3.5)
184
+ rspec (~> 3.0)
185
+ rubocop (~> 1.29)
186
+ standard (~> 1.12)
187
+ vcr (~> 6.0)
188
+ webmock (~> 3.18)
189
+ yard (~> 0.9)
190
+
191
+ BUNDLED WITH
192
+ 2.3.8
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 John Doe
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,84 @@
1
+ # Exception Notification - Lark Notifier
2
+
3
+ The [Exception Notification](https://github.com/smartinez87/exception_notification) gem provides a
4
+ set of notifiers for sending notifications when errors occur in a Rack/Rails application. This gem
5
+ adds support for delivering notifications to [Lark](https://www.larksuite.com).
6
+
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'exception_notification'
14
+ gem 'exception_notification-lark-notifier'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle install
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install exception_notification-lark-notifier
24
+
25
+
26
+ ## Usage
27
+
28
+ In order to receive exceptions in Lark, you need to add a custom bot to the group chat.
29
+
30
+ To configure it, you need to set the webhook address, like this:
31
+
32
+ ```ruby
33
+ Rails.application.config.middleware.use ExceptionNotification::Rack,
34
+ lark: {
35
+ webhook_url: 'https://open.larksuite.com/open-apis/bot/v2/hook/xxxxxxxxxxxxxxxxx',
36
+ webhook_secret: '123456',
37
+ http: {
38
+ timeout_class: HTTP::Timeout::Global,
39
+ timeout_options: {global_timeout: 5}
40
+ }
41
+ }
42
+ ```
43
+
44
+ ### Options
45
+
46
+ #### webhook_url
47
+
48
+ *String, required*
49
+
50
+ The Incoming WebHook URL on Lark.
51
+
52
+ #### webhook_secret
53
+
54
+ *String, optional*
55
+
56
+ The secret key for *Signature validation*.
57
+
58
+ #### http
59
+
60
+ *Hash, optional*
61
+
62
+ Configure the HTTP client.
63
+
64
+
65
+ ## Development
66
+
67
+ 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.
68
+
69
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
70
+
71
+
72
+ ## Contributing
73
+
74
+ Bug reports and pull requests are welcome on GitHub at https://github.com/souk4711/exception_notification-lark-notifier. 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/souk4711/exception_notification-lark-notifier/blob/main/CODE_OF_CONDUCT.md).
75
+
76
+
77
+ ## License
78
+
79
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
80
+
81
+
82
+ ## Code of Conduct
83
+
84
+ Everyone interacting in the exception_notification-lark-notifier project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/souk4711/exception_notification-lark-notifier/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+
5
+ require "rubocop/rake_task"
6
+ RuboCop::RakeTask.new
7
+
8
+ require "rspec/core/rake_task"
9
+ RSpec::Core::RakeTask.new(:spec)
10
+
11
+ task default: %i[rubocop spec]
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/exception_notification-lark-notifier/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "exception_notification-lark-notifier"
7
+ spec.version = ExceptionNotificationLarkNotifier::VERSION
8
+ spec.authors = ["John Doe"]
9
+ spec.email = ["johndoe@example.com"]
10
+
11
+ spec.summary = "Lark notifier for exception notification gem."
12
+ spec.description = "Lark notifier for exception notification gem."
13
+ spec.homepage = "https://github.com/souk4711/exception_notification-lark-notifier"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.7.0"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/souk4711/exception_notification-lark-notifier"
19
+ spec.metadata["changelog_uri"] = "https://github.com/souk4711/exception_notification-lark-notifier"
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
+ `git ls-files -z`.split("\x0").reject do |f|
25
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
26
+ end
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ # Uncomment to register a new dependency of your gem
33
+ spec.add_dependency "exception_notification", "~> 4.0"
34
+ spec.add_dependency "http", "~> 5.0"
35
+
36
+ # For more information and examples about making a new gem, check out our
37
+ # guide at: https://bundler.io/guides/creating_gem.html
38
+ spec.metadata["rubygems_mfa_required"] = "true"
39
+ end
@@ -0,0 +1,48 @@
1
+ module ExceptionNotificationLarkNotifier
2
+ class Client
3
+ def initialize(options)
4
+ @secret = options[:webhook_secret].to_s.strip
5
+ @http = Http.new(
6
+ uri: options.fetch(:webhook_url),
7
+ options: options[:http] || {}
8
+ )
9
+ end
10
+
11
+ def ping(payload)
12
+ payload = {text: payload} unless payload.is_a?(Hash)
13
+ post(payload)
14
+ end
15
+
16
+ def post(payload)
17
+ message = build_message(payload)
18
+
19
+ unless @secret.empty?
20
+ timestamp = Time.now.to_i
21
+ sign = Signer.generate(timestamp, @secret)
22
+ message[:timestamp] = timestamp
23
+ message[:sign] = sign
24
+ end
25
+
26
+ @http.post(json: message)
27
+ end
28
+
29
+ private
30
+
31
+ def build_message(payload)
32
+ case payload
33
+ in { text: content }
34
+ {msg_type: "text", content: {text: content}}
35
+ in { post: content }
36
+ {msg_type: "post", content: {post: content}}
37
+ in { image: content }
38
+ {msg_type: "image", content: {image_key: content}}
39
+ in { share_chat: content }
40
+ {msg_type: "share_chat", content: {share_chat_id: content}}
41
+ in { interactive: content }
42
+ {msg_type: "interactive", card: content}
43
+ else
44
+ raise ::ArgumentError, "msg_type is required"
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,12 @@
1
+ module ExceptionNotificationLarkNotifier
2
+ class Exceptions
3
+ # Generic error
4
+ Error = Class.new(StandardError)
5
+
6
+ # Generic HTTP error
7
+ HttpError = Class.new(Error)
8
+
9
+ # Generic API error, non 0 response code
10
+ APIError = Class.new(Error)
11
+ end
12
+ end
@@ -0,0 +1,70 @@
1
+ module ExceptionNotificationLarkNotifier
2
+ class Http
3
+ def initialize(options)
4
+ @uri = options.fetch(:uri)
5
+ @options = options.fetch(:options)
6
+ end
7
+
8
+ def post(options)
9
+ request(:post, options)
10
+ end
11
+
12
+ private
13
+
14
+ def request(verb, options)
15
+ begin
16
+ response = http(@options).request(verb, @uri, options)
17
+ rescue HTTP::Error => e
18
+ raise ExceptionNotificationLarkNotifier::Exceptions::HttpError, e.message
19
+ end
20
+
21
+ parse_response(response) do |parse_as, result|
22
+ case parse_as
23
+ when :json
24
+ break result if result["StatusCode"] == 0
25
+ raise ExceptionNotificationLarkNotifier::Exceptions::APIError, result["msg"]
26
+ else
27
+ result
28
+ end
29
+ end
30
+ end
31
+
32
+ def http(options)
33
+ HTTP::Client.new(HTTP::Options.new(options))
34
+ end
35
+
36
+ def parse_response(response)
37
+ content_type = response.headers[:content_type]
38
+ parse_as = {
39
+ %r{^application/json} => :json,
40
+ %r{^text/plain} => :plain
41
+ }.each_with_object([]) { |match, memo| memo << match[1] if content_type&.match?(match[0]) }.first || :plain
42
+
43
+ if parse_as == :plain
44
+ result = begin
45
+ parse_json_response(response)
46
+ rescue
47
+ nil
48
+ end
49
+ if result
50
+ return yield(:json, result)
51
+ else
52
+ return yield(:plain, response.body)
53
+ end
54
+ end
55
+
56
+ result = case parse_as
57
+ when :json
58
+ parse_json_response(response)
59
+ else
60
+ response.body
61
+ end
62
+
63
+ yield(parse_as, result)
64
+ end
65
+
66
+ def parse_json_response(response)
67
+ JSON.parse(response.body.to_s)
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,8 @@
1
+ module ExceptionNotificationLarkNotifier
2
+ class Signer
3
+ def self.generate(timestamp, secret)
4
+ string = "#{timestamp}\n#{secret}"
5
+ Base64.strict_encode64(OpenSSL::HMAC.digest(OpenSSL::Digest.new("sha256"), string, ""))
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module ExceptionNotificationLarkNotifier
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,12 @@
1
+ require "base64"
2
+ require "openssl"
3
+
4
+ require "exception_notification"
5
+ require "http"
6
+
7
+ require_relative "exception_notification-lark-notifier/client"
8
+ require_relative "exception_notification-lark-notifier/exceptions"
9
+ require_relative "exception_notification-lark-notifier/http"
10
+ require_relative "exception_notification-lark-notifier/signer"
11
+ require_relative "exception_notification-lark-notifier/version"
12
+ require_relative "exception_notifier/lark_notifier"
@@ -0,0 +1,97 @@
1
+ module ExceptionNotifier
2
+ class LarkNotifier
3
+ include ExceptionNotifier::BacktraceCleaner
4
+
5
+ def initialize(options)
6
+ @default_appname = "#{rails_app_name} (env: #{rails_env_name})" if rails_app_name && rails_env_name
7
+ @notifier = ExceptionNotificationLarkNotifier::Client.new(
8
+ options.slice(:webhook_url, :webhook_secret, :http)
9
+ )
10
+ end
11
+
12
+ def call(exception, options = {})
13
+ title = @default_appname ? "Exception Occurred in #{@default_appname}" : "Exception Occurred"
14
+ clean_message = exception.message.tr("`", "'")
15
+ backtrace = exception.backtrace ? clean_backtrace(exception) : ""
16
+ info, data = information_from_options(exception.class, options)
17
+ fields = fields(clean_message, backtrace, data)
18
+
19
+ @notifier.post interactive: {
20
+ header: {
21
+ title: {tag: "plain_text", content: title}
22
+ },
23
+ elements: [{
24
+ tag: "div",
25
+ text: {tag: "lark_md", content: info},
26
+ fields: fields
27
+ }]
28
+ }
29
+ end
30
+
31
+ private
32
+
33
+ def fields(clean_message, backtrace, data)
34
+ fields = []
35
+
36
+ unless clean_message.empty?
37
+ fields << {is_short: false, text: {tag: "lark_md", content: "**Message:**"}}
38
+ fields << {is_short: false, text: {tag: "plain_text", content: clean_message}}
39
+ fields << {is_short: false, text: {tag: "lark_md", content: "\n"}}
40
+ end
41
+
42
+ unless backtrace.empty?
43
+ fields << {is_short: false, text: {tag: "lark_md", content: "**Backtrace:**"}}
44
+ fields << {is_short: false, text: {tag: "plain_text", content: backtrace.first(10).join("\n")}}
45
+ fields << {is_short: false, text: {tag: "lark_md", content: "\n"}}
46
+ end
47
+
48
+ unless data.empty?
49
+ data = data.map { |k, v| "#{k}: #{v}" }.join("\n")
50
+ fields << {is_short: false, text: {tag: "lark_md", content: "**Data:**"}}
51
+ fields << {is_short: false, text: {tag: "plain_text", content: data}}
52
+ fields << {is_short: false, text: {tag: "lark_md", content: "\n"}}
53
+ end
54
+
55
+ fields
56
+ end
57
+
58
+ def information_from_options(exception_class, options)
59
+ errors_count = options[:accumulated_errors_count].to_i
60
+ measure_word = if errors_count > 1
61
+ errors_count
62
+ else
63
+ (/^[aeiou]/i.match?(exception_class.to_s) ? "An" : "A")
64
+ end
65
+ exception_name = "*#{measure_word}* **#{exception_class}**"
66
+
67
+ env = options[:env]
68
+ if env.nil?
69
+ data = options[:data] || {}
70
+ text = "#{exception_name} *occured in background*"
71
+ else
72
+ data = (env["exception_notifier.exception_data"] || {}).merge(options[:data] || {})
73
+ kontroller = env["action_controller.instance"]
74
+ request = "#{env["REQUEST_METHOD"]} #{env["REQUEST_URI"]}"
75
+ text = "#{exception_name} *occurred while* **#{request}**"
76
+ text += " *was processed by* **#{kontroller.controller_name}##{kontroller.action_name}**" if kontroller
77
+ end
78
+ text += "\n --------------\n"
79
+
80
+ [text, data]
81
+ end
82
+
83
+ def rails_app_name
84
+ return unless defined?(::Rails) && ::Rails.respond_to?(:application)
85
+ if ::Gem::Version.new(::Rails.version) >= ::Gem::Version.new("6.0")
86
+ ::Rails.application.class.module_parent_name
87
+ else
88
+ ::Rails.application.class.parent_name
89
+ end
90
+ end
91
+
92
+ def rails_env_name
93
+ return unless defined?(::Rails) && ::Rails.respond_to?(:env)
94
+ ::Rails.env
95
+ end
96
+ end
97
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: exception_notification-lark-notifier
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - John Doe
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-12-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: exception_notification
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: http
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.0'
41
+ description: Lark notifier for exception notification gem.
42
+ email:
43
+ - johndoe@example.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".editorconfig"
49
+ - ".env.defaults"
50
+ - ".overcommit.yml"
51
+ - ".rspec"
52
+ - ".rubocop.yml"
53
+ - ".ruby-version"
54
+ - ".yardopts"
55
+ - CODE_OF_CONDUCT.md
56
+ - Gemfile
57
+ - Gemfile.lock
58
+ - LICENSE.txt
59
+ - README.md
60
+ - Rakefile
61
+ - exception_notification-lark-notifier.gemspec
62
+ - lib/exception_notification-lark-notifier.rb
63
+ - lib/exception_notification-lark-notifier/client.rb
64
+ - lib/exception_notification-lark-notifier/exceptions.rb
65
+ - lib/exception_notification-lark-notifier/http.rb
66
+ - lib/exception_notification-lark-notifier/signer.rb
67
+ - lib/exception_notification-lark-notifier/version.rb
68
+ - lib/exception_notifier/lark_notifier.rb
69
+ homepage: https://github.com/souk4711/exception_notification-lark-notifier
70
+ licenses:
71
+ - MIT
72
+ metadata:
73
+ homepage_uri: https://github.com/souk4711/exception_notification-lark-notifier
74
+ source_code_uri: https://github.com/souk4711/exception_notification-lark-notifier
75
+ changelog_uri: https://github.com/souk4711/exception_notification-lark-notifier
76
+ rubygems_mfa_required: 'true'
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.7.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.3.7
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Lark notifier for exception notification gem.
96
+ test_files: []