slack-reporter 0.1.0
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 +7 -0
- data/CHANGELOG.md +5 -0
- data/README.md +66 -0
- data/lib/slack-reporter.rb +50 -0
- data/lib/version.rb +3 -0
- metadata +62 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6a32ec694cb0e2467b3383cbbca9076a93cd4071
|
4
|
+
data.tar.gz: 53c731ca83868be64335b692790df3101017bc99
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ebeeb0ceefb40f9ffbedd031c38f7c3d8490121c87600993c8e805e768b53f40f1faed4240a8cf0741928a36dfef5a5ede82441def367beddb0de0b49d422bb6
|
7
|
+
data.tar.gz: 6c82ef7b3f0df67ef0e5f62b24da80d0e018efa759b4b24c4b082165aef0d9f765996d7f9f5d26a9d28d6e09e039ec9af6aac441ad989c1b8fb417c196b31590
|
data/CHANGELOG.md
ADDED
data/README.md
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# Slack Reporter
|
2
|
+
|
3
|
+
A very simple wrapper for a a simple wrapper for posting to slack channels.
|
4
|
+
requires [slack-notifier](https://github.com/stevenosloan/slack-notifier)
|
5
|
+
|
6
|
+
### Requirements
|
7
|
+
A slack channel with webhooks intergration and your api key in the `SLACK_WEBHOOK_URI` environmental variable.
|
8
|
+
|
9
|
+
Finnally this is your gemfile.
|
10
|
+
`gem 'slack_reporter'`
|
11
|
+
|
12
|
+
### Usage
|
13
|
+
|
14
|
+
```
|
15
|
+
SlackReporter.new('user reporter', { channel: '#awesome-feedback' }).call do
|
16
|
+
"#{current_user.name} said we are awesome!"
|
17
|
+
end
|
18
|
+
```
|
19
|
+
|
20
|
+
This will report the following to the '#awesome-feedback` channnel
|
21
|
+
```
|
22
|
+
user_reporter BOT 10:04 PM
|
23
|
+
Bob said we are awesome!
|
24
|
+
```
|
25
|
+
|
26
|
+
Ofcourse whats the use without defaults!! SlackReporter uses four defaults, one for the webhook, one for the channel and two for naming the reporter.
|
27
|
+
They default to
|
28
|
+
|
29
|
+
```
|
30
|
+
{
|
31
|
+
webhook: ENV["SLACK_WEBHOOK_URI"],
|
32
|
+
channel: '#feedback',
|
33
|
+
name: 'user',
|
34
|
+
followup: '_announcer'
|
35
|
+
}
|
36
|
+
```
|
37
|
+
You can set your own by `SlackReporter.defaults` by providing the values you want to change afterwards.
|
38
|
+
|
39
|
+
|
40
|
+
With defauts set the reporter can be called simply by
|
41
|
+
|
42
|
+
```
|
43
|
+
SlackReporter.new.call do
|
44
|
+
"Important message!!"
|
45
|
+
end
|
46
|
+
```
|
47
|
+
|
48
|
+
### Notes
|
49
|
+
The reporter gets called *ONLY* on production enviroments if inside Rails or Hanami.
|
50
|
+
To report regardless of environment call `#call` with `true` in arguments e.g.
|
51
|
+
`SlackReporter.new.call(true)`
|
52
|
+
|
53
|
+
|
54
|
+
You can create as many custom reporters as you want and the use them by calling `#call` and giving them a block of text. e.g.
|
55
|
+
```
|
56
|
+
@reporter1 = SlackReporter.new("Nelson said")
|
57
|
+
@reporter1.call { 'Hahaa' }
|
58
|
+
```
|
59
|
+
|
60
|
+
|
61
|
+
The naming of a reporter matches the name if its 2 words or more, else its the `name` + `followup`
|
62
|
+
Also you can put on object or class in the reporter and it will smart name that too!!
|
63
|
+
|
64
|
+
There is an `attr_accessor` for name and channel in case you want to change them for an existing reporter.
|
65
|
+
|
66
|
+
The code is less than 50 lines so for any questions you might want to check it out!
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'slack-notifier'
|
2
|
+
require_relative 'version'
|
3
|
+
|
4
|
+
class SlackReporter
|
5
|
+
attr_accessor :name, :channel
|
6
|
+
DEFAULTS = {
|
7
|
+
webhook: ENV["SLACK_WEBHOOK_URI"].freeze,
|
8
|
+
channel: '#feedback',
|
9
|
+
name: 'user',
|
10
|
+
followup: '_announcer'
|
11
|
+
}
|
12
|
+
|
13
|
+
def self.defaults(opts={})
|
14
|
+
DEFAULTS.merge!(Hash[opts])
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(item = nil, options={ channel: nil })
|
18
|
+
@name = create_name(item)
|
19
|
+
@channel = options[:channel] || DEFAULTS[:channel]
|
20
|
+
@notifier = Slack::Notifier.new DEFAULTS[:webhook], channel: @channel, username: @name
|
21
|
+
end
|
22
|
+
|
23
|
+
def call(allow = false)
|
24
|
+
return unless allow || environmet_allows
|
25
|
+
@notifier.ping yield
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def create_name(item)
|
31
|
+
item = item.class unless item.class == Class || String
|
32
|
+
string = (item || DEFAULTS[:name]).to_s.downcase
|
33
|
+
return string if string.split.count > 1
|
34
|
+
string + DEFAULTS[:followup]
|
35
|
+
end
|
36
|
+
|
37
|
+
def environmet_allows
|
38
|
+
environment == 'production'
|
39
|
+
end
|
40
|
+
|
41
|
+
def environment
|
42
|
+
if defined?(Rails)
|
43
|
+
Rails.env
|
44
|
+
elseif defined?(Hanami)
|
45
|
+
Hanami.env
|
46
|
+
else
|
47
|
+
'production'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: slack-reporter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vasilis Spilka
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-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: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: A very simple wrapper for a a simple wrapper for posting to slack channels
|
28
|
+
email: vasspilka@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- CHANGELOG.md
|
34
|
+
- README.md
|
35
|
+
- lib/slack-reporter.rb
|
36
|
+
- lib/version.rb
|
37
|
+
homepage: http://rubygems.org/gems/slack-reporter
|
38
|
+
licenses:
|
39
|
+
- MIT
|
40
|
+
metadata: {}
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 2.2.0
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
requirements: []
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 2.5.1
|
58
|
+
signing_key:
|
59
|
+
specification_version: 4
|
60
|
+
summary: A slack webhooks wrapper
|
61
|
+
test_files: []
|
62
|
+
has_rdoc:
|