slackcat 0.1.0 → 0.2.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 +4 -4
- data/.gitignore +0 -1
- data/Gemfile.lock +31 -0
- data/bin/slackcat +34 -15
- data/lib/slackcat/version.rb +1 -1
- data/slackcat.gemspec +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec17396e6bab7b65c8e0d9d3973286e0e7f04b4f
|
4
|
+
data.tar.gz: 9221832546c13e35efd896d79a5546afff9e9c5e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 655a405b4cb06eec4a0e1d038932580ccf5989766ffcc64b4e1a05f1545fcf68f8a3f63275841ae103d18974a7f389e4acc9af6fa7c4f7db9d66d22631e6e14d
|
7
|
+
data.tar.gz: dd7e81b21c457ee15cd1e82f0a1befea8cd2b18056138725c41c0b48abe42325a319c35492a8e002fd4ebc2c3d0dbee42fc11b6db9e4e6e55616a672e90fa03f
|
data/.gitignore
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
slackcat (0.1.0)
|
5
|
+
httmultiparty
|
6
|
+
trollop
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
httmultiparty (0.3.16)
|
12
|
+
httparty (>= 0.7.3)
|
13
|
+
mimemagic
|
14
|
+
multipart-post
|
15
|
+
httparty (0.13.3)
|
16
|
+
json (~> 1.8)
|
17
|
+
multi_xml (>= 0.5.2)
|
18
|
+
json (1.8.1)
|
19
|
+
mimemagic (0.2.1)
|
20
|
+
multi_xml (0.5.5)
|
21
|
+
multipart-post (2.0.0)
|
22
|
+
rake (10.3.2)
|
23
|
+
trollop (2.0)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
bundler (~> 1.3)
|
30
|
+
rake
|
31
|
+
slackcat!
|
data/bin/slackcat
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'httmultiparty'
|
4
4
|
require 'trollop'
|
5
5
|
|
6
6
|
class Slackcat
|
7
|
-
include
|
7
|
+
include HTTMultiParty
|
8
8
|
base_uri 'https://slack.com/api'
|
9
9
|
|
10
10
|
def initialize(token)
|
@@ -34,6 +34,11 @@ class Slackcat
|
|
34
34
|
@users ||= get_objects('users.list', 'members')
|
35
35
|
end
|
36
36
|
|
37
|
+
## get my username
|
38
|
+
def auth
|
39
|
+
@auth ||= get_objects('auth.test', 'user')
|
40
|
+
end
|
41
|
+
|
37
42
|
## translate a username into an IM id
|
38
43
|
def im_for_user(username)
|
39
44
|
user = users.find do |user|
|
@@ -44,28 +49,35 @@ class Slackcat
|
|
44
49
|
end
|
45
50
|
end
|
46
51
|
|
52
|
+
## upload a file or text snippet
|
47
53
|
def upload(params)
|
48
54
|
self.class.post('/files.upload', body: params.merge({token: @token})).tap do |response|
|
49
55
|
raise "error uploading file: #{response.fetch('error', 'unknown error')}" unless response['ok']
|
50
56
|
end
|
51
57
|
end
|
52
58
|
|
59
|
+
## send message to one channel as a single post, instead of file upload
|
60
|
+
def post_message(params)
|
61
|
+
self.class.post('/chat.postMessage', body: params.merge({token: @token})).tap do |response|
|
62
|
+
raise "error posting message: #{response.fetch('error', 'unknown error')}" unless response['ok']
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
53
66
|
end
|
54
67
|
|
55
68
|
opts = Trollop::options do
|
56
|
-
opt :token, 'Slack API token',
|
57
|
-
opt :channels, 'Channels to share',
|
58
|
-
opt :groups, 'Groups to share',
|
59
|
-
opt :users, 'Users (DMs) to share',
|
60
|
-
opt :filetype, 'File type identifier',
|
61
|
-
opt :title, 'Title of file',
|
62
|
-
opt :filename, 'Filename of file',
|
63
|
-
opt :initial_comment, 'Initial comment to add',
|
69
|
+
opt :token, 'Slack API token', type: :string, short: 'k', default: ENV.fetch('SLACK_TOKEN', nil)
|
70
|
+
opt :channels, 'Channels to share', type: :string, short: 'c', default: ''
|
71
|
+
opt :groups, 'Groups to share', type: :string, short: 'g', default: ''
|
72
|
+
opt :users, 'Users (DMs) to share', type: :string, short: 'u', default: ''
|
73
|
+
opt :filetype, 'File type identifier', type: :string, short: 't'
|
74
|
+
opt :title, 'Title of file', type: :string, short: 'T'
|
75
|
+
opt :filename, 'Filename of file', type: :string, short: 'n'
|
76
|
+
opt :initial_comment, 'Initial comment to add', type: :string, short: 'i'
|
77
|
+
opt :post, 'Post instead of upload', type: :boolean, short: 'p', default: false
|
78
|
+
opt :multipart, 'Multipart upload each file', type: :boolean, short: 'm', default: false
|
64
79
|
end
|
65
80
|
|
66
|
-
## get this after opts parsed out of ARGV
|
67
|
-
opts[:filename] ||= ARGV.first
|
68
|
-
|
69
81
|
raise 'set slack API token using SLACK_TOKEN or -k option' unless opts[:token]
|
70
82
|
slack = Slackcat.new(opts[:token])
|
71
83
|
|
@@ -82,7 +94,6 @@ ims = opts[:users].split(/[\s,]+/).map do |name|
|
|
82
94
|
end
|
83
95
|
|
84
96
|
params = {
|
85
|
-
content: ARGF.read,
|
86
97
|
filetype: opts[:filetype],
|
87
98
|
filename: opts[:filename],
|
88
99
|
title: opts[:title],
|
@@ -90,4 +101,12 @@ params = {
|
|
90
101
|
channels: (channels + groups + ims).join(","),
|
91
102
|
}.select { |_, value| value }
|
92
103
|
|
93
|
-
|
104
|
+
if opts[:post] #simple text post
|
105
|
+
slack.post_message(text: ARGF.read, channel: params[:channels], username: slack.auth)
|
106
|
+
elsif opts[:multipart] #upload multiple individual binary files
|
107
|
+
ARGV.each do |arg|
|
108
|
+
slack.upload({file: File.new(arg), filename: arg}.merge(params))
|
109
|
+
end
|
110
|
+
else #upload concatenated text snippet
|
111
|
+
slack.upload(params.merge(content: ARGF.read))
|
112
|
+
end
|
data/lib/slackcat/version.rb
CHANGED
data/slackcat.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slackcat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Lister
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: httmultiparty
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - '>='
|
@@ -76,6 +76,7 @@ extra_rdoc_files: []
|
|
76
76
|
files:
|
77
77
|
- .gitignore
|
78
78
|
- Gemfile
|
79
|
+
- Gemfile.lock
|
79
80
|
- LICENSE.txt
|
80
81
|
- README.md
|
81
82
|
- Rakefile
|