slack-post 0.3.1 → 0.3.2
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 +4 -4
- data/bin/slack-post +7 -9
- data/lib/slack/post.rb +27 -27
- data/lib/slack/post/version.rb +1 -1
- data/slack-post.gemspec +2 -2
- 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: db58e73a6d91ae69420029c2dbdbab93732db574
|
4
|
+
data.tar.gz: d0dea7f95e2a374421e679615e5995b1fba9102b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92890f799660ad6564148d2af865f7efd8b7a6d774b42d6439783c9e467cc2cc21293cd64edbc962e80df02785302f38490dc44247b2d0a6859fb64dfbaf3274
|
7
|
+
data.tar.gz: b11b088f0520bd13f2b6846588f8ba6a3fc72edd7c22db98afc9d361a5cf6dd1e5eb54e572948ec793fdcd1d279bdd30f0e5be3ab091766449258ff0217941b2
|
data/bin/slack-post
CHANGED
@@ -21,29 +21,29 @@ def post(options)
|
|
21
21
|
options[:channel] = "#" + options[:channel]
|
22
22
|
end
|
23
23
|
Slack::Post.configure options
|
24
|
-
Slack::Post.post options[:message].gsub(/\\n/,"\n")
|
24
|
+
Slack::Post.post options[:message].gsub(/\\n/, "\n")
|
25
25
|
end
|
26
26
|
|
27
|
-
options =
|
27
|
+
options = {}
|
28
28
|
optparse = OptionParser.new do |opts|
|
29
29
|
opts.banner = "Usage: slack-post [options]"
|
30
30
|
|
31
31
|
opts.on('-s', '--subdomain [SUBDOMAIN]', String, 'Your slack subdomain') do |subdomain|
|
32
32
|
options[:subdomain] = subdomain
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
opts.on('-m', '--message [MESSAGE]', 'Your message') do |message|
|
36
36
|
options[:message] = message
|
37
37
|
end
|
38
38
|
|
39
39
|
options[:channel] = 'general'
|
40
40
|
opts.on('-r', '--room [ROOM]', String, 'The slack room where the message should go (without \'#\', default \'general\')') do |room|
|
41
|
-
options[:channel] = room
|
41
|
+
options[:channel] = room
|
42
42
|
end
|
43
43
|
|
44
44
|
options[:username] = 'slackbot'
|
45
45
|
opts.on('-u', '--username [USERNAME]', String, 'The username, default \'slackbot\'') do |username|
|
46
|
-
options[:username] = username
|
46
|
+
options[:username] = username
|
47
47
|
end
|
48
48
|
|
49
49
|
opts.on('-f', '--config-file [CONFIGFILE]', String, 'The configuration file with token or set SLACK_TOKEN environment variable') do |config_file|
|
@@ -56,12 +56,12 @@ optparse = OptionParser.new do |opts|
|
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
-
begin
|
59
|
+
begin
|
60
60
|
optparse.parse!
|
61
61
|
|
62
62
|
mandatory = [:subdomain, :message]
|
63
63
|
missing = mandatory.select { |param| options[param].nil? }
|
64
|
-
|
64
|
+
unless missing.empty?
|
65
65
|
$stderr.puts "Missing options: #{missing.join(', ')}"
|
66
66
|
$stderr.puts optparse
|
67
67
|
exit 1
|
@@ -79,5 +79,3 @@ rescue => e
|
|
79
79
|
puts optparse
|
80
80
|
exit 1
|
81
81
|
end
|
82
|
-
|
83
|
-
|
data/lib/slack/post.rb
CHANGED
@@ -6,24 +6,24 @@ require 'yajl'
|
|
6
6
|
|
7
7
|
module Slack
|
8
8
|
module Post
|
9
|
-
|
9
|
+
|
10
10
|
DefaultOpts = {
|
11
11
|
channel: '#general'
|
12
12
|
}.freeze
|
13
|
-
|
14
|
-
def self.post_with_attachments(message,attachments,chan=nil,opts={})
|
15
|
-
|
13
|
+
|
14
|
+
def self.post_with_attachments(message, attachments, chan = nil, opts = {})
|
15
|
+
fail "Slack::Post.configure was not called or configuration was invalid" unless configured?(chan)
|
16
16
|
pkt = {
|
17
17
|
channel: chan || config[:channel],
|
18
|
-
text: message
|
18
|
+
text: message
|
19
19
|
}
|
20
20
|
if config[:username]
|
21
21
|
pkt[:username] = config[:username]
|
22
22
|
end
|
23
|
-
if opts.
|
23
|
+
if opts.key?(:icon_url) || config.key?(:icon_url)
|
24
24
|
pkt[:icon_url] = opts[:icon_url] || config[:icon_url]
|
25
25
|
end
|
26
|
-
if opts.
|
26
|
+
if opts.key?(:icon_emoji) || config.key?(:icon_emoji)
|
27
27
|
pkt[:icon_emoji] = opts[:icon_emoji] || config[:icon_emoji]
|
28
28
|
end
|
29
29
|
if attachments.instance_of?(Array) && attachments != []
|
@@ -42,29 +42,29 @@ module Slack
|
|
42
42
|
when Net::HTTPSuccess
|
43
43
|
return true
|
44
44
|
else
|
45
|
-
|
45
|
+
fail "There was an error while trying to post. Error was: #{resp.body}"
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
49
|
def self.validated_attachment(attachment)
|
50
50
|
valid_attachment = prune(symbolize_keys(attachment), AttachmentParams)
|
51
|
-
if attachment.
|
51
|
+
if attachment.key?(:fields)
|
52
52
|
valid_attachment[:fields] = attachment[:fields].map { |h| prune(symbolize_keys(h), FieldParams) }
|
53
53
|
end
|
54
54
|
return valid_attachment
|
55
55
|
end
|
56
56
|
|
57
|
-
def self.post(message,chan=nil,opts={})
|
57
|
+
def self.post(message, chan = nil, opts = {})
|
58
58
|
post_with_attachments(message, [], chan, opts)
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
def self.post_url
|
62
62
|
config[:webhook_url] || "https://#{config[:subdomain]}.slack.com/services/hooks/incoming-webhook?token=#{config[:token]}"
|
63
63
|
end
|
64
|
-
|
65
|
-
LegacyConfigParams = [:subdomain
|
66
|
-
|
67
|
-
def self.configured?(channel_was_overriden=false)
|
64
|
+
|
65
|
+
LegacyConfigParams = [:subdomain, :token].freeze
|
66
|
+
|
67
|
+
def self.configured?(channel_was_overriden = false)
|
68
68
|
# if a channel was not manually specified, then we must have a channel option in the config OR
|
69
69
|
# we must be using the webhook_url which provided its own default channel on the Slack-side config.
|
70
70
|
return false if !channel_was_overriden && !config[:channel] && !config[:webhook_url]
|
@@ -75,25 +75,25 @@ module Slack
|
|
75
75
|
config[parm]
|
76
76
|
end
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
79
|
def self.config
|
80
80
|
@config ||= {}
|
81
81
|
end
|
82
|
-
|
82
|
+
|
83
83
|
def self.configure(opts)
|
84
84
|
@config = config.merge(prune(opts))
|
85
85
|
|
86
86
|
# If a channel has not been configured, add the default channel
|
87
87
|
# unless we are using a webhook_url, which provides its own default channel.
|
88
|
-
@config.merge!(DefaultOpts) unless
|
88
|
+
@config.merge!(DefaultOpts) unless @config[:webhook_url] || @config[:channel]
|
89
89
|
end
|
90
|
-
|
91
|
-
KnownConfigParams = [:webhook_url
|
92
|
-
AttachmentParams = [:fallback
|
93
|
-
FieldParams = [:title
|
94
|
-
|
95
|
-
def self.prune(opts, allowed_elements=KnownConfigParams)
|
96
|
-
opts.inject({}) do |acc,(k,v)|
|
90
|
+
|
91
|
+
KnownConfigParams = [:webhook_url, :username, :channel, :subdomain, :token, :icon_url, :icon_emoji].freeze
|
92
|
+
AttachmentParams = [:fallback, :text, :pretext, :color, :fields, :image_url].freeze
|
93
|
+
FieldParams = [:title, :value, :short].freeze
|
94
|
+
|
95
|
+
def self.prune(opts, allowed_elements = KnownConfigParams)
|
96
|
+
opts.inject({}) do |acc, (k, v)|
|
97
97
|
k = k.to_sym
|
98
98
|
if allowed_elements.include?(k)
|
99
99
|
acc[k] = v
|
@@ -103,8 +103,8 @@ module Slack
|
|
103
103
|
end
|
104
104
|
|
105
105
|
def self.symbolize_keys(hash)
|
106
|
-
return hash.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
|
106
|
+
return hash.inject({}) { |memo, (k, v)| memo[k.to_sym] = v; memo }
|
107
107
|
end
|
108
|
-
|
108
|
+
|
109
109
|
end
|
110
110
|
end
|
data/lib/slack/post/version.rb
CHANGED
data/slack-post.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = Slack::Post::VERSION
|
9
9
|
spec.authors = ["John Bragg"]
|
10
10
|
spec.email = ["remotezygote@gmail.com"]
|
11
|
-
spec.description =
|
12
|
-
spec.summary =
|
11
|
+
spec.description = 'Pretty simple really. It posts to slack fer ya.'
|
12
|
+
spec.summary = "It's for posting messages to your slack."
|
13
13
|
spec.homepage = ""
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slack-post
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Bragg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|