fde-slack-notification 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.test.env +1 -0
- data/.travis.yml +9 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +2 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/fde-slack-notification.gemspec +46 -0
- data/lib/slack/author.rb +23 -0
- data/lib/slack/field.rb +25 -0
- data/lib/slack/footer.rb +21 -0
- data/lib/slack/message.rb +76 -0
- data/lib/slack/notification.rb +25 -0
- data/lib/slack/notification/version.rb +7 -0
- metadata +246 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9888104b6904df059379e19bd43adf41f66987b9
|
4
|
+
data.tar.gz: b317c996310bb3e1e25ae3724711b74fb6d96375
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 13f37ee55bdb636b4182262beb6d5f4ad074a817f6790ed3b015d01cdc79090241db2c68c180b16ccd96ac4d0f8f17bc6be6bbaf2a4f2f0967faf46aa1c35e29
|
7
|
+
data.tar.gz: a66819f25ebea35bef1619aaf3337a4cef25cb24398551152405b296314531b0c92aa46fcdd6a3b9dd1981840b0550932a90579cbcc79e42123cc0e8b5d51b7f
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.test.env
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
SLACK_WEBHOOK_URL=SLACK_WEBHOOK_URL
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Felix Langenegger
|
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
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "slack/notification"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "slack/notification/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "fde-slack-notification"
|
8
|
+
spec.version = FDE::Slack::Notification::VERSION
|
9
|
+
spec.authors = ["Felix Langenegger"]
|
10
|
+
spec.email = ["f.langenegger@fadendaten.ch"]
|
11
|
+
|
12
|
+
spec.summary = %q{A simple slack client}
|
13
|
+
spec.description = %q{A simple slack client to send messages into a slack channel}
|
14
|
+
spec.homepage = ""
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
"public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_runtime_dependency "slack-notifier", "~> 1.5", ">= 1.5.1"
|
34
|
+
spec.add_runtime_dependency "dotenv", "~> 2.2", ">= 2.2.1"
|
35
|
+
|
36
|
+
spec.add_development_dependency "bundler", "~> 1.15"
|
37
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
38
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
39
|
+
spec.add_development_dependency "rdoc", "~> 5.1", ">= 5.1"
|
40
|
+
spec.add_development_dependency "vcr", "~> 3.0.3", ">= 3.0.3"
|
41
|
+
spec.add_development_dependency 'webmock', '~> 3.0', '>= 3.0.1'
|
42
|
+
|
43
|
+
spec.add_development_dependency "pry", "~> 0.10"
|
44
|
+
spec.add_development_dependency "pry-remote", "~> 0.1"
|
45
|
+
spec.add_development_dependency "pry-nav", "~> 0.2"
|
46
|
+
end
|
data/lib/slack/author.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
module FDE
|
2
|
+
module Slack
|
3
|
+
class Author
|
4
|
+
attr_accessor :name, :link, :icon
|
5
|
+
|
6
|
+
def initialize(name, link = nil, icon = nil)
|
7
|
+
@name = name
|
8
|
+
@link = link
|
9
|
+
@icon = icon
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_h
|
13
|
+
hash = {}
|
14
|
+
hash[:author_name] = @name
|
15
|
+
hash[:author_link] = @link if @link
|
16
|
+
hash[:author_icon] = @icon if @icon
|
17
|
+
hash
|
18
|
+
end
|
19
|
+
|
20
|
+
alias_method :to_hash, :to_h
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/slack/field.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
module FDE
|
2
|
+
module Slack
|
3
|
+
class Field
|
4
|
+
attr_accessor :title,
|
5
|
+
:value,
|
6
|
+
:short
|
7
|
+
|
8
|
+
def initialize(title, value, short = false)
|
9
|
+
@title = title
|
10
|
+
@value = value
|
11
|
+
@short = short
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_h
|
15
|
+
{
|
16
|
+
title: @title,
|
17
|
+
value: @value,
|
18
|
+
short: @short
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
alias_method :to_hash, :to_h
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/slack/footer.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module FDE
|
2
|
+
module Slack
|
3
|
+
class Footer
|
4
|
+
attr_accessor :value, :icon
|
5
|
+
|
6
|
+
def initialize(value, icon = nil)
|
7
|
+
@value = value
|
8
|
+
@icon = icon
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_h
|
12
|
+
hash = {}
|
13
|
+
hash[:footer] = @value
|
14
|
+
hash[:footer_icon] = @icon if @icon
|
15
|
+
hash
|
16
|
+
end
|
17
|
+
|
18
|
+
alias_method :to_hash, :to_h
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module FDE
|
2
|
+
module Slack
|
3
|
+
class Message
|
4
|
+
BLUE = '#BDE5F8'.freeze
|
5
|
+
GREEN = '#DFF2BF'.freeze
|
6
|
+
YELLOW = '#FEEFB3'.freeze
|
7
|
+
RED = '#FFBABA'.freeze
|
8
|
+
|
9
|
+
attr_accessor :username,
|
10
|
+
:title,
|
11
|
+
:author,
|
12
|
+
:fields,
|
13
|
+
:footer,
|
14
|
+
:color
|
15
|
+
|
16
|
+
def initialize(title, fields, author = nil, footer = nil, username = nil)
|
17
|
+
@username = username || 'FDE Slack Notifier'
|
18
|
+
@title = title
|
19
|
+
@author = author
|
20
|
+
@fields = fields
|
21
|
+
@footer = footer
|
22
|
+
end
|
23
|
+
|
24
|
+
def info(channel)
|
25
|
+
@color = BLUE
|
26
|
+
send(channel)
|
27
|
+
end
|
28
|
+
|
29
|
+
def success(channel)
|
30
|
+
@color = GREEN
|
31
|
+
send(channel)
|
32
|
+
end
|
33
|
+
|
34
|
+
def warning(channel)
|
35
|
+
@color = YELLOW
|
36
|
+
send(channel)
|
37
|
+
end
|
38
|
+
|
39
|
+
def error(channel)
|
40
|
+
@color = RED
|
41
|
+
send(channel)
|
42
|
+
end
|
43
|
+
|
44
|
+
def add_field(field)
|
45
|
+
@fields << field.to_h
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def send(channel)
|
51
|
+
notifier = ::Slack::Notifier.new(
|
52
|
+
FDE::Slack::Notification.config.webhook,
|
53
|
+
channel: channel,
|
54
|
+
username: @username
|
55
|
+
)
|
56
|
+
notifier.ping message_hash
|
57
|
+
end
|
58
|
+
|
59
|
+
def message_hash
|
60
|
+
{ attachments: [ attachment_hash ] }
|
61
|
+
end
|
62
|
+
|
63
|
+
def attachment_hash
|
64
|
+
hash = {
|
65
|
+
fallback: @title,
|
66
|
+
ts: Time.now.to_i,
|
67
|
+
color: @color,
|
68
|
+
fields: @fields
|
69
|
+
}
|
70
|
+
hash.merge!(@author.to_h)
|
71
|
+
hash.merge!(@footer.to_h)
|
72
|
+
hash
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "slack-notifier"
|
2
|
+
|
3
|
+
require "slack/notification/version"
|
4
|
+
require "slack/message"
|
5
|
+
require "slack/field"
|
6
|
+
require "slack/author"
|
7
|
+
require "slack/footer"
|
8
|
+
|
9
|
+
module FDE
|
10
|
+
module Slack
|
11
|
+
module Notification
|
12
|
+
class Config
|
13
|
+
attr_accessor :webhook
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.config
|
17
|
+
@@config ||= Config.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.configure
|
21
|
+
yield self.config
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,246 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fde-slack-notification
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Felix Langenegger
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-09-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: slack-notifier
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.5.1
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.5'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.5.1
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: dotenv
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '2.2'
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 2.2.1
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '2.2'
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 2.2.1
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: bundler
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '1.15'
|
60
|
+
type: :development
|
61
|
+
prerelease: false
|
62
|
+
version_requirements: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - "~>"
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '1.15'
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: rake
|
69
|
+
requirement: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - "~>"
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '10.0'
|
74
|
+
type: :development
|
75
|
+
prerelease: false
|
76
|
+
version_requirements: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - "~>"
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '10.0'
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: rspec
|
83
|
+
requirement: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - "~>"
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '3.0'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - "~>"
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '3.0'
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: rdoc
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - "~>"
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '5.1'
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '5.1'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - "~>"
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '5.1'
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '5.1'
|
115
|
+
- !ruby/object:Gem::Dependency
|
116
|
+
name: vcr
|
117
|
+
requirement: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - "~>"
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: 3.0.3
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 3.0.3
|
125
|
+
type: :development
|
126
|
+
prerelease: false
|
127
|
+
version_requirements: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 3.0.3
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: 3.0.3
|
135
|
+
- !ruby/object:Gem::Dependency
|
136
|
+
name: webmock
|
137
|
+
requirement: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - "~>"
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '3.0'
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: 3.0.1
|
145
|
+
type: :development
|
146
|
+
prerelease: false
|
147
|
+
version_requirements: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - "~>"
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '3.0'
|
152
|
+
- - ">="
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: 3.0.1
|
155
|
+
- !ruby/object:Gem::Dependency
|
156
|
+
name: pry
|
157
|
+
requirement: !ruby/object:Gem::Requirement
|
158
|
+
requirements:
|
159
|
+
- - "~>"
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
version: '0.10'
|
162
|
+
type: :development
|
163
|
+
prerelease: false
|
164
|
+
version_requirements: !ruby/object:Gem::Requirement
|
165
|
+
requirements:
|
166
|
+
- - "~>"
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: '0.10'
|
169
|
+
- !ruby/object:Gem::Dependency
|
170
|
+
name: pry-remote
|
171
|
+
requirement: !ruby/object:Gem::Requirement
|
172
|
+
requirements:
|
173
|
+
- - "~>"
|
174
|
+
- !ruby/object:Gem::Version
|
175
|
+
version: '0.1'
|
176
|
+
type: :development
|
177
|
+
prerelease: false
|
178
|
+
version_requirements: !ruby/object:Gem::Requirement
|
179
|
+
requirements:
|
180
|
+
- - "~>"
|
181
|
+
- !ruby/object:Gem::Version
|
182
|
+
version: '0.1'
|
183
|
+
- !ruby/object:Gem::Dependency
|
184
|
+
name: pry-nav
|
185
|
+
requirement: !ruby/object:Gem::Requirement
|
186
|
+
requirements:
|
187
|
+
- - "~>"
|
188
|
+
- !ruby/object:Gem::Version
|
189
|
+
version: '0.2'
|
190
|
+
type: :development
|
191
|
+
prerelease: false
|
192
|
+
version_requirements: !ruby/object:Gem::Requirement
|
193
|
+
requirements:
|
194
|
+
- - "~>"
|
195
|
+
- !ruby/object:Gem::Version
|
196
|
+
version: '0.2'
|
197
|
+
description: A simple slack client to send messages into a slack channel
|
198
|
+
email:
|
199
|
+
- f.langenegger@fadendaten.ch
|
200
|
+
executables: []
|
201
|
+
extensions: []
|
202
|
+
extra_rdoc_files: []
|
203
|
+
files:
|
204
|
+
- ".gitignore"
|
205
|
+
- ".rspec"
|
206
|
+
- ".test.env"
|
207
|
+
- ".travis.yml"
|
208
|
+
- Gemfile
|
209
|
+
- LICENSE.txt
|
210
|
+
- README.md
|
211
|
+
- Rakefile
|
212
|
+
- bin/console
|
213
|
+
- bin/setup
|
214
|
+
- fde-slack-notification.gemspec
|
215
|
+
- lib/slack/author.rb
|
216
|
+
- lib/slack/field.rb
|
217
|
+
- lib/slack/footer.rb
|
218
|
+
- lib/slack/message.rb
|
219
|
+
- lib/slack/notification.rb
|
220
|
+
- lib/slack/notification/version.rb
|
221
|
+
homepage: ''
|
222
|
+
licenses:
|
223
|
+
- MIT
|
224
|
+
metadata:
|
225
|
+
allowed_push_host: https://rubygems.org
|
226
|
+
post_install_message:
|
227
|
+
rdoc_options: []
|
228
|
+
require_paths:
|
229
|
+
- lib
|
230
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
231
|
+
requirements:
|
232
|
+
- - ">="
|
233
|
+
- !ruby/object:Gem::Version
|
234
|
+
version: '0'
|
235
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
236
|
+
requirements:
|
237
|
+
- - ">="
|
238
|
+
- !ruby/object:Gem::Version
|
239
|
+
version: '0'
|
240
|
+
requirements: []
|
241
|
+
rubyforge_project:
|
242
|
+
rubygems_version: 2.6.8
|
243
|
+
signing_key:
|
244
|
+
specification_version: 4
|
245
|
+
summary: A simple slack client
|
246
|
+
test_files: []
|