slack_notifier 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -1
- data/Rakefile +16 -1
- data/lib/slack_notifier/message.rb +38 -19
- data/lib/slack_notifier/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d5dd58d5214793c72a02e8c8cf95f531f49109fc
|
4
|
+
data.tar.gz: a955a28facbb7163fb12130647990c736caf5f2b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6365577bde7b310d5d37b0ae6939725aaf658b58e7bb220612158f723c7cb9b0705895d6c39aa097044cf58bf925712cbf76161bc6b012c6326b97cbcb89df8
|
7
|
+
data.tar.gz: 4d4aba93faee572f11506ea8926bbd92d41ce0172e79c5c2f08c40315c198370d3673896e5e2d0622fc98a336e0a86add89ab069c4a5078bf4dc75bef009fd84
|
data/README.md
CHANGED
@@ -38,6 +38,7 @@ SlackNotifier.configure({
|
|
38
38
|
```
|
39
39
|
|
40
40
|
## Usage
|
41
|
+
### Send directly
|
41
42
|
```ruby
|
42
43
|
SlackNotifier::Message.send(
|
43
44
|
text: "This uses all default configuration",
|
@@ -51,10 +52,21 @@ SlackNotifier::Message.send(
|
|
51
52
|
text: ex.message,
|
52
53
|
icon_emoji: ':bug:',
|
53
54
|
report: ex.backtrace,
|
54
|
-
report_color: '#D3D3D3'
|
55
|
+
report_color: '#D3D3D3',
|
56
|
+
report_title: 'Backtrace'
|
55
57
|
)
|
56
58
|
```
|
57
59
|
|
60
|
+
### Send later
|
61
|
+
```ruby
|
62
|
+
message = SlackNotifier::Message.compose(
|
63
|
+
text: "This uses all default configuration",
|
64
|
+
report: 'Some report/attachment text'
|
65
|
+
)
|
66
|
+
|
67
|
+
message.deliver
|
68
|
+
```
|
69
|
+
|
58
70
|
## Development
|
59
71
|
|
60
72
|
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/Rakefile
CHANGED
@@ -1,2 +1,17 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
|
-
|
2
|
+
|
3
|
+
task default: :spec
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'rspec/core/rake_task'
|
7
|
+
|
8
|
+
RSpec::Core::RakeTask.new(:spec, :tag) do |t, task_args|
|
9
|
+
t.rspec_opts = ['--format documentation']
|
10
|
+
t.rspec_opts << '--color'
|
11
|
+
t.rspec_opts << '--order rand:42'
|
12
|
+
t.rspec_opts << "--tag #{task_args[:tag]}" if task_args[:tag]
|
13
|
+
end
|
14
|
+
rescue LoadError
|
15
|
+
# no rspec available
|
16
|
+
raise 'Yo, no RSpec?'
|
17
|
+
end
|
@@ -1,11 +1,24 @@
|
|
1
1
|
module SlackNotifier
|
2
2
|
class Message
|
3
|
-
def self.
|
3
|
+
def self.compose(text:, channel: nil, nickname: nil, icon_emoji: nil, report: nil, report_title: nil, report_color: nil)
|
4
4
|
channel ||= Config.default_channel
|
5
5
|
nickname ||= Config.default_nickname
|
6
|
-
|
7
|
-
report_color
|
8
|
-
|
6
|
+
icon_emoji ||= Config.default_icon_emoji
|
7
|
+
report_color ||= Config.default_report_color
|
8
|
+
report_title ||= Config.default_report_title
|
9
|
+
new(text, channel, nickname, icon_emoji, report, report_title, report_color)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.send(text:, channel: nil, nickname: nil, icon_emoji: nil, report: nil, report_title: nil, report_color: nil)
|
13
|
+
compose(
|
14
|
+
text: text,
|
15
|
+
channel: channel,
|
16
|
+
nickname: nickname,
|
17
|
+
icon_emoji: icon_emoji,
|
18
|
+
report: report,
|
19
|
+
report_title: report_title,
|
20
|
+
report_color: report_color
|
21
|
+
).tap(&:deliver)
|
9
22
|
rescue => ex
|
10
23
|
raise ex if Config.raise_delivery_errors
|
11
24
|
puts ex.message
|
@@ -13,17 +26,6 @@ module SlackNotifier
|
|
13
26
|
end
|
14
27
|
|
15
28
|
def deliver
|
16
|
-
payload_hash = {
|
17
|
-
username: @nickname,
|
18
|
-
text: @message.gsub('\'', '`'),
|
19
|
-
channel: @channel
|
20
|
-
}
|
21
|
-
|
22
|
-
payload_hash.merge!(icon_param)
|
23
|
-
payload_hash.merge!(compose_attachment) if !@report.nil? && !@report.empty?
|
24
|
-
|
25
|
-
payload = payload_hash.to_json
|
26
|
-
|
27
29
|
cmd = %(curl -X POST --data-urlencode 'payload=#{payload}' #{Config.webhook_url})
|
28
30
|
puts "Executing: `#{cmd}`"
|
29
31
|
|
@@ -35,25 +37,42 @@ module SlackNotifier
|
|
35
37
|
|
36
38
|
private
|
37
39
|
|
38
|
-
def initialize(
|
39
|
-
@
|
40
|
+
def initialize(text, channel, nickname, icon, report, report_title, report_color)
|
41
|
+
@text = text
|
40
42
|
@channel = channel
|
41
43
|
@nickname = nickname
|
42
44
|
@icon_emoji = icon
|
43
45
|
@report = report
|
46
|
+
@report_title = report_title
|
44
47
|
@report_color = report_color
|
45
48
|
@created_at = Time.now
|
46
49
|
end
|
47
50
|
|
51
|
+
def payload
|
52
|
+
payload_hash = base_param
|
53
|
+
payload_hash.merge!(icon_param)
|
54
|
+
payload_hash.merge!(attachment_param)
|
55
|
+
payload_hash.to_json
|
56
|
+
end
|
57
|
+
|
58
|
+
def base_param
|
59
|
+
{
|
60
|
+
username: @nickname,
|
61
|
+
text: @text.gsub('\'', '`'),
|
62
|
+
channel: @channel
|
63
|
+
}
|
64
|
+
end
|
65
|
+
|
48
66
|
def icon_param
|
49
67
|
{ icon_emoji: @icon_emoji }
|
50
68
|
end
|
51
69
|
|
52
|
-
def
|
70
|
+
def attachment_param
|
71
|
+
return {} if @report.nil? || @report.empty?
|
53
72
|
{
|
54
73
|
attachments: [
|
55
74
|
{
|
56
|
-
title:
|
75
|
+
title: @report_title,
|
57
76
|
color: @report_color,
|
58
77
|
text: key_value_pairs_to_s(@report)
|
59
78
|
}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slack_notifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elod Peter
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-06-
|
12
|
+
date: 2017-06-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: titleize
|