actionslack 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/action_slack/base.rb +1 -5
- data/lib/action_slack/configuration.rb +11 -1
- data/lib/action_slack/logger.rb +5 -0
- data/lib/action_slack/notifier.rb +27 -3
- data/lib/action_slack/send_job.rb +2 -2
- data/lib/action_slack/version.rb +1 -1
- data/lib/action_slack/webhook.rb +2 -2
- data/lib/action_slack.rb +15 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27afb3fa4f6da31ef2138615bbf368d9cded850396c67122d73a647ca6bf2d1d
|
4
|
+
data.tar.gz: 9b3804e467796b8a3a0d44d720afd384e8a46cf8840a2250b2ad60b0f3ffe98f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ad13e13c673e0e4c208ae4950e27403d271d23389f522485b00ce667fb166fbb49dd40340c511dd6a3108604d394b0d12861690787c41870ad4ddfc726a5b1f
|
7
|
+
data.tar.gz: 2f8394d469eddc413087431ff0bebfa62f018ec09cb0aea9b191fbc0236a152fc5ba2a920fc58f8da0f66cf5f26164e512c14989c73ea599916505e2ec9ee646
|
data/lib/action_slack/base.rb
CHANGED
@@ -12,11 +12,7 @@ module ActionSlack
|
|
12
12
|
def notify(**kargs)
|
13
13
|
instance = create(**kargs)
|
14
14
|
|
15
|
-
|
16
|
-
SendJob.perform_later(url: instance.url, message: instance.message)
|
17
|
-
else
|
18
|
-
Notifier.notify(url: instance.url, message: instance.message)
|
19
|
-
end
|
15
|
+
Notifier.notify(url: instance.url, message: instance.message)
|
20
16
|
end
|
21
17
|
|
22
18
|
def attributes=(attrs)
|
@@ -24,8 +24,18 @@ module ActionSlack
|
|
24
24
|
@configuration = self.class.default_configuration.dup
|
25
25
|
end
|
26
26
|
|
27
|
+
def async?
|
28
|
+
async
|
29
|
+
end
|
30
|
+
|
31
|
+
%i[local testflight production].each do |type_name|
|
32
|
+
define_method :"#{type_name}?" do
|
33
|
+
type_name == type
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
27
37
|
set_default(:filepath, 'config/slack_webhooks.yml')
|
28
38
|
set_default(:async, true)
|
29
|
-
set_default(:
|
39
|
+
set_default(:type, :local) # production, testflight, local
|
30
40
|
end
|
31
41
|
end
|
@@ -1,9 +1,33 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module ActionSlack
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
module Notifier
|
5
|
+
module_function
|
6
|
+
|
7
|
+
def notify(url:, message:)
|
8
|
+
message = ActionSlack.configuration.testflight? ? "[ActionSlack Test Posting]\n#{message}\n" : message
|
9
|
+
|
10
|
+
if ActionSlack.configuration.async?
|
11
|
+
notify_later(url, message)
|
12
|
+
else
|
13
|
+
notify_now(url, message)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def notify_now(url, message)
|
20
|
+
if ActionSlack.configuration.local?
|
21
|
+
ActionSlack.logger.debug { "Post to Slack webhook url: #{url}, message: \"#{message}\"" }
|
22
|
+
else
|
23
|
+
ActionSlack.logger.info { "Start posting to Slack webhook url: #{url}, message: \"#{message}\"" }
|
24
|
+
Slack::Notifier.new(url).post(text: message)
|
25
|
+
ActionSlack.logger.info 'Posted to Slack'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def notify_later(url, message)
|
30
|
+
SendJob.perform_later(url: url, message: message)
|
7
31
|
end
|
8
32
|
end
|
9
33
|
end
|
data/lib/action_slack/version.rb
CHANGED
data/lib/action_slack/webhook.rb
CHANGED
@@ -26,9 +26,9 @@ module ActionSlack
|
|
26
26
|
|
27
27
|
def load_yaml(src)
|
28
28
|
if Psych::VERSION > '4.0'
|
29
|
-
YAML.
|
29
|
+
YAML.safe_load(src, symbolize_names: true, freeze: true)
|
30
30
|
else
|
31
|
-
YAML.safe_load(src)
|
31
|
+
YAML.safe_load(src, symbolize_names: true)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
data/lib/action_slack.rb
CHANGED
@@ -4,6 +4,7 @@ require 'active_support'
|
|
4
4
|
require 'active_support/core_ext'
|
5
5
|
require 'yaml'
|
6
6
|
require 'erb'
|
7
|
+
require 'logger'
|
7
8
|
require 'slack-notifier'
|
8
9
|
|
9
10
|
module ActionSlack
|
@@ -13,6 +14,7 @@ module ActionSlack
|
|
13
14
|
autoload :Webhook
|
14
15
|
autoload :Notifier
|
15
16
|
autoload :Base
|
17
|
+
autoload :Logger
|
16
18
|
|
17
19
|
autoload :SendJob if const_defined?(:ActiveJob)
|
18
20
|
|
@@ -24,5 +26,18 @@ module ActionSlack
|
|
24
26
|
def configuration
|
25
27
|
@configuration ||= Configuration.new
|
26
28
|
end
|
29
|
+
|
30
|
+
def logger
|
31
|
+
@logger ||= ActionSlack::Logger.new($stdout, level: :info)
|
32
|
+
end
|
33
|
+
|
34
|
+
def logger=(logger)
|
35
|
+
if logger.nil?
|
36
|
+
self.logger.level = Logger::FATAL
|
37
|
+
return
|
38
|
+
end
|
39
|
+
|
40
|
+
@logger = logger
|
41
|
+
end
|
27
42
|
end
|
28
43
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: actionslack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kakubin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-11-
|
11
|
+
date: 2022-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -70,6 +70,7 @@ files:
|
|
70
70
|
- lib/action_slack.rb
|
71
71
|
- lib/action_slack/base.rb
|
72
72
|
- lib/action_slack/configuration.rb
|
73
|
+
- lib/action_slack/logger.rb
|
73
74
|
- lib/action_slack/notifier.rb
|
74
75
|
- lib/action_slack/send_job.rb
|
75
76
|
- lib/action_slack/version.rb
|
@@ -97,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
98
|
- !ruby/object:Gem::Version
|
98
99
|
version: '0'
|
99
100
|
requirements: []
|
100
|
-
rubygems_version: 3.3.
|
101
|
+
rubygems_version: 3.0.3.1
|
101
102
|
signing_key:
|
102
103
|
specification_version: 4
|
103
104
|
summary: actionslack
|