slackcat 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5520ed2610ebb85feef74432cd4d8446fcd1c297
4
- data.tar.gz: 295aad9710b3419cd3f853fe0d42f10193d93d5c
3
+ metadata.gz: a7d0f09e52d13e42a56261adc9842c431e4233ba
4
+ data.tar.gz: f9d3f6b185df7c404e6c155e5e87cf1006e50587
5
5
  SHA512:
6
- metadata.gz: 21170c59cc56aa2db55dbd3a05d282d7a01a5625043fdf7c696e272be622ad823a16781b3a989fb946370f9eb2adb7299a32a455f08af1540dcaa61e5c5b405e
7
- data.tar.gz: 0c1e5bb4cce399f9e77873a7e29e9d81e2b2eab0dd72abfde79aba15e8855ca552c670b26b9eebecf107dc5a2d2db1080a4bee380d4da43e25858409b6373e07
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
 
@@ -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 |user|
45
- user['name'] == username
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
@@ -1,3 +1,3 @@
1
1
  module Slackcat
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  end
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.3
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: 2014-12-03 00:00:00.000000000 Z
11
+ date: 2015-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler