slack_webhooks 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +16 -0
- data/README.md +4 -0
- data/lib/slack_webhooks.rb +67 -0
- data/lib/slack_webhooks/version.rb +3 -0
- data/slack_webhooks.gemspec +21 -0
- metadata +63 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8b322a902e2ebff402b2cf73be5baeb7eca9eec7
|
4
|
+
data.tar.gz: dcda6b9cdc7e68f138d138ed69c170411f75fdbf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 34bd5a0fa88a73efe0e994ad132fa7b07519f2147c54d385c60c3c27476aa8ae80ba7023a447eb0bcfc5a01b14f6add067150fabd381bfb8cdf8566042f82d29
|
7
|
+
data.tar.gz: 89b34ac67cc5f013badd7a7f6024d49c7e1edefedfdf3ae40cb9a5b4ff6c2d0e46a3b6987b16b18ca62b8e068def29fad0dc0499cffd1ec8305a21b99f8d6a67
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/README.md
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'slack-notifier'
|
3
|
+
require_relative 'slack_webhooks/version'
|
4
|
+
|
5
|
+
module SlackWebhooks
|
6
|
+
class Hook
|
7
|
+
|
8
|
+
attr_accessor :command, :trigger_word, :channel, :username, :text, :webhook_url, :botname
|
9
|
+
alias_method :user_name, :username
|
10
|
+
|
11
|
+
# botname is the name to post to the channel with.
|
12
|
+
# body is the outgoing webhook POST body that Slack sends.
|
13
|
+
# webhook_url is the incoming webhook to post back to slack.
|
14
|
+
def initialize(botname, body, webhook_url)
|
15
|
+
self.botname = botname
|
16
|
+
self.webhook_url = webhook_url
|
17
|
+
parsed = URI.decode_www_form(body)
|
18
|
+
parsed.each do |p|
|
19
|
+
# puts "#{p[0]}=#{p[1]}"
|
20
|
+
if p[0] == "command"
|
21
|
+
self.command = p[1]
|
22
|
+
puts "command=#{self.command}"
|
23
|
+
end
|
24
|
+
if p[0] == "trigger_word"
|
25
|
+
# This is for trigger words, not slash commands
|
26
|
+
self.trigger_word = p[1]
|
27
|
+
end
|
28
|
+
if p[0] == "channel_name"
|
29
|
+
self.channel = p[1]
|
30
|
+
end
|
31
|
+
if p[0] == "user_name"
|
32
|
+
self.username = "@#{p[1]}"
|
33
|
+
# puts "username #{username}"
|
34
|
+
end
|
35
|
+
if p[0] == "text"
|
36
|
+
self.text = p[1].strip
|
37
|
+
# puts "text=#{text}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
if self.channel == "directmessage"
|
41
|
+
self.channel = self.username
|
42
|
+
else
|
43
|
+
self.channel = "\##{self.channel}" unless self.channel[0] == '#'
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
def send(s, attachment=nil)
|
49
|
+
# Now send it to back to the channel on slack
|
50
|
+
s = "#{command} #{text}" if s.nil?
|
51
|
+
puts "Posting #{s} to #{channel}. .."
|
52
|
+
notifier = Slack::Notifier.new webhook_url
|
53
|
+
notifier.channel = channel
|
54
|
+
notifier.username = botname
|
55
|
+
|
56
|
+
resp = nil
|
57
|
+
if attachment
|
58
|
+
resp = notifier.ping s, attachments: [attachment]
|
59
|
+
else
|
60
|
+
resp = notifier.ping s
|
61
|
+
end
|
62
|
+
|
63
|
+
p resp
|
64
|
+
p resp.message
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require_relative 'lib/slack_webhooks/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = 'slack_webhooks'
|
5
|
+
s.version = SlackWebhooks::VERSION
|
6
|
+
s.licenses = ['MIT']
|
7
|
+
s.summary = "Helper for slack webhooks"
|
8
|
+
s.description = "Helper for slack webhooks!"
|
9
|
+
s.authors = ["Travis Reeder"]
|
10
|
+
s.email = 'treeder@gmail.com'
|
11
|
+
s.homepage = 'https://rubygems.org/gems/slack_webhooks'
|
12
|
+
|
13
|
+
s.files = `git ls-files`.split($\)
|
14
|
+
# s.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
15
|
+
# s.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
|
18
|
+
s.required_rubygems_version = ">= 1.3.6"
|
19
|
+
s.required_ruby_version = Gem::Requirement.new(">= 1.9")
|
20
|
+
s.add_runtime_dependency "slack-notifier", ">= 0.5.1"
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: slack_webhooks
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Travis Reeder
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-08 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.5.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.5.1
|
27
|
+
description: Helper for slack webhooks!
|
28
|
+
email: treeder@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- Gemfile
|
34
|
+
- Gemfile.lock
|
35
|
+
- README.md
|
36
|
+
- lib/slack_webhooks.rb
|
37
|
+
- lib/slack_webhooks/version.rb
|
38
|
+
- slack_webhooks.gemspec
|
39
|
+
homepage: https://rubygems.org/gems/slack_webhooks
|
40
|
+
licenses:
|
41
|
+
- MIT
|
42
|
+
metadata: {}
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '1.9'
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 1.3.6
|
57
|
+
requirements: []
|
58
|
+
rubyforge_project:
|
59
|
+
rubygems_version: 2.4.2
|
60
|
+
signing_key:
|
61
|
+
specification_version: 4
|
62
|
+
summary: Helper for slack webhooks
|
63
|
+
test_files: []
|