slackcat 0.2.3 → 0.2.4
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/README.md +6 -0
- data/bin/slackcat +34 -2
- data/lib/slackcat/version.rb +1 -1
- 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: a7d0f09e52d13e42a56261adc9842c431e4233ba
|
4
|
+
data.tar.gz: f9d3f6b185df7c404e6c155e5e87cf1006e50587
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f8e66464d544bfe2f9bbbcfe860f19c0f4f55e0a638163cd4ed296a64c66c61c1890a0c628bd72ce174878a544569a5b9a02f15242077f32251d487099bda71
|
7
|
+
data.tar.gz: a2d76c18fffca0df7a28a98b6a677f8389bf8c306fb83331ee8e46ab02dd59e71510e155d20e57679586d705e1b5138bf25c94ffd3ac885204fdc8e13bec7d31
|
data/README.md
CHANGED
@@ -14,6 +14,10 @@ export SLACK_TOKEN=<your api token>
|
|
14
14
|
echo 'hello world' | slackcat -c <channel>
|
15
15
|
```
|
16
16
|
|
17
|
+
Note: since gem dependencies build extension modules, you may need
|
18
|
+
ruby headers installed. For example, using system ruby on debian
|
19
|
+
derivatives, you need to install the `ruby-dev` package.
|
20
|
+
|
17
21
|
## Environment variables
|
18
22
|
|
19
23
|
* `SLACK_TOKEN`: your token from https://api.slack.com/.
|
@@ -33,6 +37,8 @@ echo 'hello world' | slackcat -c <channel>
|
|
33
37
|
--initial-comment, -i <s>: Initial comment to add
|
34
38
|
--post, -p: Post instead of upload
|
35
39
|
--multipart, -m: Multipart upload each file
|
40
|
+
--download, -d <s>: Download a linked file
|
41
|
+
--save-as, -s <s>: Save downloaded file as
|
36
42
|
--help, -h: Show this message
|
37
43
|
```
|
38
44
|
|
data/bin/slackcat
CHANGED
@@ -41,8 +41,8 @@ class Slackcat
|
|
41
41
|
|
42
42
|
## translate a username into an IM id
|
43
43
|
def im_for_user(username)
|
44
|
-
user = users.find do |
|
45
|
-
|
44
|
+
user = users.find do |u|
|
45
|
+
u['name'] == username
|
46
46
|
end
|
47
47
|
ims.find do |im|
|
48
48
|
im['user'] == user['id']
|
@@ -63,6 +63,31 @@ class Slackcat
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
+
## download a file posted by another user
|
67
|
+
def download(params, save_as)
|
68
|
+
info = self.class.get('/files.info', query: params.merge({token: @token})).tap do |response|
|
69
|
+
raise "error retrieving information for for file #{params[:file]}: #{response.fetch('error', 'unknown error')}" unless response['ok']
|
70
|
+
end.fetch('file')
|
71
|
+
|
72
|
+
if download = info['url']
|
73
|
+
uri = URI(download)
|
74
|
+
name = uri.path.split('/').last
|
75
|
+
|
76
|
+
if save_as
|
77
|
+
if File.directory?(save_as)
|
78
|
+
name = "#{save_as}/#{name}"
|
79
|
+
else
|
80
|
+
name = save_as
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
File.open(name, 'wb') { |f| f.write HTTParty.get(download).parsed_response }
|
85
|
+
return name
|
86
|
+
else
|
87
|
+
raise "error determining private download URL for file #{params[:file]}"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
66
91
|
end
|
67
92
|
|
68
93
|
opts = Trollop::options do
|
@@ -76,6 +101,8 @@ opts = Trollop::options do
|
|
76
101
|
opt :initial_comment, 'Initial comment to add', type: :string, short: 'i'
|
77
102
|
opt :post, 'Post instead of upload', type: :boolean, short: 'p', default: false
|
78
103
|
opt :multipart, 'Multipart upload each file', type: :boolean, short: 'm', default: false
|
104
|
+
opt :download, 'Download a linked file', type: :string, short: 'd'
|
105
|
+
opt :save_as, 'Save downloaded file as', type: :string, short: 's'
|
79
106
|
end
|
80
107
|
|
81
108
|
raise 'set slack API token using SLACK_TOKEN or -k option' unless opts[:token]
|
@@ -113,6 +140,11 @@ elsif opts[:multipart] #upload multiple individual binary files
|
|
113
140
|
ARGV.each do |arg|
|
114
141
|
slack.upload({file: File.new(arg), filename: arg}.merge(params))
|
115
142
|
end
|
143
|
+
elsif opts[:download] #download a linked file
|
144
|
+
uri = URI(opts[:download])
|
145
|
+
file = uri.path.split('/')[3] # 0 is always empty, 1 is always 'files', 2 is always username
|
146
|
+
dst = slack.download({file: file}, opts[:save_as])
|
147
|
+
puts "File downloaded to #{dst}"
|
116
148
|
else #upload concatenated text snippet
|
117
149
|
slack.upload(params.merge(content: ARGF.read))
|
118
150
|
end
|
data/lib/slackcat/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slackcat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Lister
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|