exception_notification-lark-notifier 1.0.0 → 1.0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4e0a0ee12c91e89f27b20f8af7803b09cc1cad5c4c81de4f4740add60409af83
4
- data.tar.gz: 5c9d14db23ec2f71276cd1cfbfe026fdc620f465dee858b32a5f2876903ee3c8
3
+ metadata.gz: a952dcfa9e9a72d7ece18771204fb3ccd603c557743483b0bdedee25895ada95
4
+ data.tar.gz: 8914ae0f5ef4c17d332da7d96ce87df098b968c93b90cdc4e89cebfd9a8a2237
5
5
  SHA512:
6
- metadata.gz: 2045bebbcc8ef6f9428b28c80203660d37109fc96267b9123a2e0e00872b91b4914ca12695bf2e153d0d86e2df1715ce7129fb62d7be95e098da2fc432425350
7
- data.tar.gz: b3bc14d8e61f6caa17d373becb1baeca121ba0b0892c6a28fa7db5664c601f4431b30731ad6356cd190ca78bdf4e49ca4a61282c1364e3458d5b4a5a3eebfee2
6
+ metadata.gz: f3b006430401da944ee17f5a5e55a2594c97030b8637013b176443641471426a686ee713c82199a3bbb8516910efd5d1be3097d7f9a077ac2105a0e64cc84f1c
7
+ data.tar.gz: ce331203d3d2cb020ec008d70a1ecbbc207cc20e7253e8011e98e73937bd1a65e61c53c19537966929f7071de1ee252419a36affc59dac63e2a52b80b21dfed6
data/Gemfile.lock CHANGED
@@ -1,40 +1,40 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- exception_notification-lark-notifier (0.0.1)
4
+ exception_notification-lark-notifier (1.0.2)
5
5
  exception_notification (~> 4.0)
6
6
  http (~> 5.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
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)
11
+ actionmailer (7.0.4.3)
12
+ actionpack (= 7.0.4.3)
13
+ actionview (= 7.0.4.3)
14
+ activejob (= 7.0.4.3)
15
+ activesupport (= 7.0.4.3)
16
16
  mail (~> 2.5, >= 2.5.4)
17
17
  net-imap
18
18
  net-pop
19
19
  net-smtp
20
20
  rails-dom-testing (~> 2.0)
21
- actionpack (7.0.4)
22
- actionview (= 7.0.4)
23
- activesupport (= 7.0.4)
21
+ actionpack (7.0.4.3)
22
+ actionview (= 7.0.4.3)
23
+ activesupport (= 7.0.4.3)
24
24
  rack (~> 2.0, >= 2.2.0)
25
25
  rack-test (>= 0.6.3)
26
26
  rails-dom-testing (~> 2.0)
27
27
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
28
- actionview (7.0.4)
29
- activesupport (= 7.0.4)
28
+ actionview (7.0.4.3)
29
+ activesupport (= 7.0.4.3)
30
30
  builder (~> 3.1)
31
31
  erubi (~> 1.4)
32
32
  rails-dom-testing (~> 2.0)
33
33
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
34
- activejob (7.0.4)
35
- activesupport (= 7.0.4)
34
+ activejob (7.0.4.3)
35
+ activesupport (= 7.0.4.3)
36
36
  globalid (>= 0.3.6)
37
- activesupport (7.0.4)
37
+ activesupport (7.0.4.3)
38
38
  concurrent-ruby (~> 1.0, >= 1.0.2)
39
39
  i18n (>= 1.6, < 2)
40
40
  minitest (>= 5.1)
@@ -44,7 +44,7 @@ GEM
44
44
  ast (2.4.2)
45
45
  builder (3.2.4)
46
46
  childprocess (4.1.0)
47
- concurrent-ruby (1.1.10)
47
+ concurrent-ruby (1.2.2)
48
48
  crack (0.4.5)
49
49
  rexml
50
50
  crass (1.0.6)
@@ -61,7 +61,7 @@ GEM
61
61
  ffi-compiler (1.0.1)
62
62
  ffi (>= 1.0.0)
63
63
  rake
64
- globalid (1.0.0)
64
+ globalid (1.1.0)
65
65
  activesupport (>= 5.0)
66
66
  hashdiff (1.0.1)
67
67
  http (5.1.1)
@@ -72,7 +72,7 @@ GEM
72
72
  http-cookie (1.0.5)
73
73
  domain_name (~> 0.5)
74
74
  http-form_data (2.3.0)
75
- i18n (1.12.0)
75
+ i18n (1.13.0)
76
76
  concurrent-ruby (~> 1.0)
77
77
  iniparse (1.5.0)
78
78
  json (2.6.3)
@@ -80,16 +80,16 @@ GEM
80
80
  llhttp-ffi (0.4.0)
81
81
  ffi-compiler (~> 1.0)
82
82
  rake (~> 13.0)
83
- loofah (2.19.1)
83
+ loofah (2.21.2)
84
84
  crass (~> 1.0.2)
85
- nokogiri (>= 1.5.9)
86
- mail (2.8.0)
85
+ nokogiri (>= 1.12.0)
86
+ mail (2.8.1)
87
87
  mini_mime (>= 0.1.1)
88
88
  net-imap
89
89
  net-pop
90
90
  net-smtp
91
91
  mini_mime (1.1.2)
92
- minitest (5.16.3)
92
+ minitest (5.18.0)
93
93
  net-imap (0.3.4)
94
94
  date
95
95
  net-protocol
@@ -99,7 +99,7 @@ GEM
99
99
  timeout
100
100
  net-smtp (0.3.3)
101
101
  net-protocol
102
- nokogiri (1.13.10-x86_64-linux)
102
+ nokogiri (1.14.4-x86_64-linux)
103
103
  racc (~> 1.4)
104
104
  overcommit (0.59.1)
105
105
  childprocess (>= 0.6.3, < 5)
@@ -110,13 +110,13 @@ GEM
110
110
  ast (~> 2.4.1)
111
111
  public_suffix (5.0.1)
112
112
  racc (1.6.2)
113
- rack (2.2.5)
114
- rack-test (2.0.2)
113
+ rack (2.2.7)
114
+ rack-test (2.1.0)
115
115
  rack (>= 1.3)
116
116
  rails-dom-testing (2.0.3)
117
117
  activesupport (>= 4.2.0)
118
118
  nokogiri (>= 1.6)
119
- rails-html-sanitizer (1.4.4)
119
+ rails-html-sanitizer (1.5.0)
120
120
  loofah (~> 2.19, >= 2.19.1)
121
121
  rainbow (3.1.1)
122
122
  rake (13.0.6)
@@ -156,8 +156,8 @@ GEM
156
156
  language_server-protocol (~> 3.17.0.2)
157
157
  rubocop (= 1.40.0)
158
158
  rubocop-performance (= 1.15.1)
159
- timeout (0.3.1)
160
- tzinfo (2.0.5)
159
+ timeout (0.3.2)
160
+ tzinfo (2.0.6)
161
161
  concurrent-ruby (~> 1.0)
162
162
  unf (0.1.4)
163
163
  unf_ext
data/README.md CHANGED
@@ -55,6 +55,18 @@ The Incoming WebHook URL on Lark.
55
55
 
56
56
  The secret key for *Signature validation*.
57
57
 
58
+ #### app_name
59
+
60
+ *String, optional*
61
+
62
+ Your application name, shown in the notification.
63
+
64
+ #### env_name
65
+
66
+ *String, optional*
67
+
68
+ Your env name, shown in the notification.
69
+
58
70
  #### http
59
71
 
60
72
  *Hash, optional*
@@ -21,8 +21,13 @@ module ExceptionNotificationLarkNotifier
21
21
  parse_response(response) do |parse_as, result|
22
22
  case parse_as
23
23
  when :json
24
- break result if result["StatusCode"] == 0
25
- raise ExceptionNotificationLarkNotifier::Exceptions::APIError, result["msg"]
24
+ if result.key?("code")
25
+ break result if result["code"] == 0
26
+ raise ExceptionNotificationLarkNotifier::Exceptions::APIError, result["msg"]
27
+ else
28
+ break result if result["StatusCode"] == 0
29
+ raise ExceptionNotificationLarkNotifier::Exceptions::APIError, result["StatusMessage"]
30
+ end
26
31
  else
27
32
  result
28
33
  end
@@ -1,3 +1,3 @@
1
1
  module ExceptionNotificationLarkNotifier
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -2,19 +2,44 @@ module ExceptionNotifier
2
2
  class LarkNotifier
3
3
  include ExceptionNotifier::BacktraceCleaner
4
4
 
5
+ class << self
6
+ def rails_app_name
7
+ return unless defined?(::Rails) && ::Rails.respond_to?(:application)
8
+ if ::Gem::Version.new(::Rails.version) >= ::Gem::Version.new("6.0")
9
+ ::Rails.application.class.module_parent_name
10
+ else
11
+ ::Rails.application.class.parent_name
12
+ end
13
+ end
14
+
15
+ def rails_env_name
16
+ return unless defined?(::Rails) && ::Rails.respond_to?(:env)
17
+ ::Rails.env
18
+ end
19
+ end
20
+
5
21
  def initialize(options)
6
- @default_appname = "#{rails_app_name} (env: #{rails_env_name})" if rails_app_name && rails_env_name
22
+ @default_app_name = self.class.rails_app_name
23
+ @default_env_name = self.class.rails_env_name
24
+ @default_options = options
25
+
7
26
  @notifier = ExceptionNotificationLarkNotifier::Client.new(
8
27
  options.slice(:webhook_url, :webhook_secret, :http)
9
28
  )
10
29
  end
11
30
 
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)
31
+ def call(exception, call_options = {})
32
+ options = call_options.merge(@default_options)
33
+ app_name = options.delete(:app_name) || @default_app_name
34
+ env_name = options.delete(:env_name) || @default_env_name
35
+
36
+ title = "Exception Occurred"
37
+ title += " in #{app_name}" if app_name
38
+ title += " (env: #{env_name})" if env_name
39
+
40
+ backtrace = exception.backtrace ? clean_backtrace(exception) : []
41
+ summary, data = information_from_options(exception.class, options)
42
+ fields = fields(exception.message, backtrace, data)
18
43
 
19
44
  @notifier.post interactive: {
20
45
  header: {
@@ -22,7 +47,7 @@ module ExceptionNotifier
22
47
  },
23
48
  elements: [{
24
49
  tag: "div",
25
- text: {tag: "lark_md", content: info},
50
+ text: {tag: "lark_md", content: summary},
26
51
  fields: fields
27
52
  }]
28
53
  }
@@ -30,26 +55,26 @@ module ExceptionNotifier
30
55
 
31
56
  private
32
57
 
33
- def fields(clean_message, backtrace, data)
58
+ def fields(message, backtrace, data)
34
59
  fields = []
35
60
 
36
- unless clean_message.empty?
61
+ unless message.empty?
37
62
  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"}}
63
+ fields << {is_short: false, text: {tag: "plain_text", content: message}}
64
+ fields << {is_short: false, text: {tag: "plain_text", content: "\n"}}
40
65
  end
41
66
 
42
67
  unless backtrace.empty?
43
68
  fields << {is_short: false, text: {tag: "lark_md", content: "**Backtrace:**"}}
44
69
  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"}}
70
+ fields << {is_short: false, text: {tag: "plain_text", content: "\n"}}
46
71
  end
47
72
 
48
73
  unless data.empty?
49
74
  data = data.map { |k, v| "#{k}: #{v}" }.join("\n")
50
75
  fields << {is_short: false, text: {tag: "lark_md", content: "**Data:**"}}
51
76
  fields << {is_short: false, text: {tag: "plain_text", content: data}}
52
- fields << {is_short: false, text: {tag: "lark_md", content: "\n"}}
77
+ fields << {is_short: false, text: {tag: "plain_text", content: "\n"}}
53
78
  end
54
79
 
55
80
  fields
@@ -79,19 +104,5 @@ module ExceptionNotifier
79
104
 
80
105
  [text, data]
81
106
  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
107
  end
97
108
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exception_notification-lark-notifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Doe
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-29 00:00:00.000000000 Z
11
+ date: 2023-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: exception_notification