active_notifier 0.4.0 → 0.4.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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +8 -16
- data/.travis.yml +2 -0
- data/README.md +1 -1
- data/lib/active_notifier/configurable.rb +3 -0
- data/lib/active_notifier/core_ext/erb/result_with_hash.rb +24 -0
- data/lib/active_notifier/core_ext/net/http/post.rb +12 -0
- data/lib/active_notifier/notifiable.rb +2 -0
- data/lib/active_notifier/notifier.rb +1 -0
- data/lib/active_notifier/notifier_adapters/abstract.rb +1 -0
- data/lib/active_notifier/notifier_adapters/dingtalk.rb +26 -16
- data/lib/active_notifier/version.rb +1 -1
- data/lib/active_notifier.rb +6 -4
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8919ed9bb7359c3c50bc1501c733507015b25f9b158f309dd522f38fc4058663
|
4
|
+
data.tar.gz: 6b7e4c32efce34c3b111a1b9a52ddcb6e119a8302c1053411f8132be02e0d37d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e943777261d19d6ac66da441ffbb899cee74a686b46a91aad7b0a871863b06cc8b7ea9ad5d255ee0a59644307a502fe6965b428d7a9c1bff28a05bad9f5542d9
|
7
|
+
data.tar.gz: 32a64dcc3fde456796fba803c42b1a347e33206b9170f490491c577b111e9c4a72d2a72124fa08bbfc03ae6a2f08f00d007a39af14cd398bc72b879b2f6e136c
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -5,27 +5,19 @@ AllCops:
|
|
5
5
|
- 'vendor/**/*'
|
6
6
|
Metrics/LineLength:
|
7
7
|
Max: 120
|
8
|
-
Style/AsciiComments:
|
9
|
-
Enabled: false
|
10
|
-
Style/FrozenStringLiteralComment:
|
11
|
-
Enabled: false
|
12
|
-
Style/Documentation:
|
13
|
-
Enabled: false
|
14
|
-
Style/BlockComments:
|
15
|
-
Enabled: false
|
16
8
|
Metrics/MethodLength:
|
17
|
-
Max: 30
|
9
|
+
Max: 30 # default * 3
|
18
10
|
Metrics/AbcSize:
|
19
|
-
Max:
|
20
|
-
Style/StringLiterals:
|
21
|
-
Enabled: false
|
22
|
-
Style/BlockDelimiters:
|
23
|
-
Enabled: false
|
11
|
+
Max: 50 # default * 2
|
24
12
|
Metrics/ModuleLength:
|
25
13
|
Exclude:
|
26
14
|
- "**/*_spec.rb"
|
27
15
|
Metrics/BlockLength:
|
28
16
|
Exclude:
|
29
17
|
- "**/*_spec.rb"
|
30
|
-
Style/
|
31
|
-
|
18
|
+
Style/FrozenStringLiteralComment:
|
19
|
+
EnforcedStyle: never
|
20
|
+
Style/StringLiterals:
|
21
|
+
EnforcedStyle: double_quotes
|
22
|
+
Style/BlockDelimiters:
|
23
|
+
EnforcedStyle: braces_for_chaining
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -103,7 +103,7 @@ Notifer.exec(...)
|
|
103
103
|
|
104
104
|
* [More Examples](https://github.com/pinewong/active_notifier/blob/master/spec/active_notifier_spec.rb)
|
105
105
|
* [RDoc](https://www.rubydoc.info/github/pinewong/active_notifier)
|
106
|
-
* [Gem RDoc](http://www.rubydoc.info/gems/active_notifier/0.4.
|
106
|
+
* [Gem RDoc](http://www.rubydoc.info/gems/active_notifier/0.4.1)
|
107
107
|
|
108
108
|
## Development
|
109
109
|
|
@@ -1,7 +1,9 @@
|
|
1
1
|
module ActiveNotifier
|
2
|
+
# ActiveNotifier support for configuration
|
2
3
|
module Configurable
|
3
4
|
extend ActiveSupport::Concern
|
4
5
|
|
6
|
+
# Core functions for Configuration
|
5
7
|
module ClassMethods
|
6
8
|
# Configure for ActiveNotifier.
|
7
9
|
#
|
@@ -22,6 +24,7 @@ module ActiveNotifier
|
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
27
|
+
# Store the configuration data
|
25
28
|
class Configuration
|
26
29
|
# Alias const for ActiveNotifier
|
27
30
|
# @!attribute [r]
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# Add #result_with_hash for version less than 2.5
|
2
|
+
class ERB
|
3
|
+
if RUBY_VERSION < "2.5"
|
4
|
+
def result_with_hash(hash)
|
5
|
+
b = new_toplevel(hash.keys)
|
6
|
+
hash.each_pair do |key, value|
|
7
|
+
b.local_variable_set(key, value)
|
8
|
+
end
|
9
|
+
result(b)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
# File lib/erb.rb, line 901
|
15
|
+
def new_toplevel(vars = nil)
|
16
|
+
b = TOPLEVEL_BINDING
|
17
|
+
if vars
|
18
|
+
vars = vars.select { |v| b.local_variable_defined?(v) }
|
19
|
+
return b.eval("tap {|;#{vars.join(',')}| break binding}") unless vars.empty?
|
20
|
+
end
|
21
|
+
b.dup
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Net
|
2
|
+
# Add ::post for version less than 2.4 and change ::post for version 2.4
|
3
|
+
class HTTP
|
4
|
+
if RUBY_VERSION < "2.5"
|
5
|
+
def self.post(url, data, header = nil)
|
6
|
+
start(url.hostname, url.port, use_ssl: url.scheme == "https") do |http|
|
7
|
+
http.post(url, data, header)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -1,12 +1,13 @@
|
|
1
1
|
module ActiveNotifier
|
2
2
|
module NotifierAdapters
|
3
|
+
# Dingtalk implement for ActiveNotifier::Notifier adapter
|
3
4
|
class Dingtalk < ActiveAdapter::Implement
|
4
5
|
VALID_TYPES = %i[text markdown].freeze
|
5
6
|
|
6
7
|
# (see NotifierAdapters::Abstract#notify)
|
7
|
-
# @
|
8
|
-
# @
|
9
|
-
# @
|
8
|
+
# @option options [#to_s] :title
|
9
|
+
# @option options [#to_a] :at_mobiles
|
10
|
+
# @option options [Boolean] :is_at_all
|
10
11
|
def notify(token, type, message, **options)
|
11
12
|
webhook = "#{ActiveNotifier.config.adapters_with_base_url.fetch(:dingtalk)}#{token}"
|
12
13
|
unless VALID_TYPES.include?(type)
|
@@ -17,26 +18,35 @@ module ActiveNotifier
|
|
17
18
|
error_message = "Message of the Dingtalk adapter can't be blank, please check template file"
|
18
19
|
raise ActiveNotifier::AdapterError, error_message
|
19
20
|
end
|
20
|
-
|
21
|
-
is_at_all = !!options[:is_at_all]
|
22
|
-
|
23
|
-
body = case type
|
24
|
-
when :text
|
25
|
-
get_text_body(message, at_mobiles, is_at_all)
|
26
|
-
when :markdown
|
27
|
-
title = options[:title].to_s
|
28
|
-
raise ActiveNotifier::AdapterError, "Dingtalk adapter require other options: title" if title.empty?
|
29
|
-
get_markdown_body(title, message, at_mobiles, is_at_all)
|
30
|
-
end
|
21
|
+
body = get_body(type, message, **options)
|
31
22
|
headers = {
|
32
|
-
|
33
|
-
|
23
|
+
"Content-Type" => "application/json",
|
24
|
+
"Accept" => "application/json"
|
34
25
|
}
|
35
26
|
Net::HTTP.post(URI(webhook), body.to_json, headers)
|
36
27
|
end
|
37
28
|
|
38
29
|
private
|
39
30
|
|
31
|
+
# @param type [Symbol]
|
32
|
+
# @param message [String]
|
33
|
+
# @param options [Hash]
|
34
|
+
# @option options [#to_s] :title
|
35
|
+
# @option options [#to_a] :at_mobiles
|
36
|
+
# @option options [Boolean] :is_at_all
|
37
|
+
def get_body(type, message, **options)
|
38
|
+
at_mobiles = options[:at_mobiles].to_a
|
39
|
+
is_at_all = options[:is_at_all] ? true : false
|
40
|
+
case type
|
41
|
+
when :text
|
42
|
+
get_text_body(message, at_mobiles, is_at_all)
|
43
|
+
when :markdown
|
44
|
+
title = options[:title].to_s
|
45
|
+
raise ActiveNotifier::AdapterError, "Dingtalk adapter require other options: title" if title.empty?
|
46
|
+
get_markdown_body(title, message, at_mobiles, is_at_all)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
40
50
|
def get_text_body(content, at_mobiles, is_at_all)
|
41
51
|
{
|
42
52
|
msgtype: "text",
|
data/lib/active_notifier.rb
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
require "net/http"
|
2
2
|
require "active_support/all"
|
3
3
|
require "active_adapter"
|
4
|
-
require "active_notifier/version"
|
5
|
-
require "active_notifier/notifier"
|
6
4
|
|
5
|
+
Dir["#{File.expand_path(__dir__)}/active_notifier/core_ext/**/*.rb"].each { |file| require file }
|
6
|
+
require "active_notifier/configurable"
|
7
|
+
require "active_notifier/notifiable"
|
8
|
+
|
9
|
+
# Notify message through webhooks
|
7
10
|
module ActiveNotifier
|
8
11
|
extend ActiveSupport::Autoload
|
9
12
|
|
10
|
-
autoload :
|
11
|
-
autoload :Notifiable
|
13
|
+
autoload :Notifier
|
12
14
|
|
13
15
|
eager_autoload do
|
14
16
|
autoload_at "active_notifier/errors" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_notifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pine Wong
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-07-
|
11
|
+
date: 2018-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_adapter
|
@@ -57,6 +57,8 @@ files:
|
|
57
57
|
- bin/setup
|
58
58
|
- lib/active_notifier.rb
|
59
59
|
- lib/active_notifier/configurable.rb
|
60
|
+
- lib/active_notifier/core_ext/erb/result_with_hash.rb
|
61
|
+
- lib/active_notifier/core_ext/net/http/post.rb
|
60
62
|
- lib/active_notifier/errors.rb
|
61
63
|
- lib/active_notifier/notifiable.rb
|
62
64
|
- lib/active_notifier/notifier.rb
|