slackcat 0.0.3 → 0.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: efe79753317eb5e517f34405ac2eacc8d1519a21
4
- data.tar.gz: 569adcfea88901c9934564de2b4da741f16098b5
3
+ metadata.gz: 8998a4c43b391f21c4377190d0bfc9a5b186155a
4
+ data.tar.gz: 9325c7a36decaba80e4b3bbb45aef94ef272ac0e
5
5
  SHA512:
6
- metadata.gz: 74832a42654ce15a7e5a8d0cce85a4ef5b990663f024bec479c71b5998fdc211a2d9a990a0ee641773f0814877c6cad2f4991bca061ed594ca5663aa7f4e1c4c
7
- data.tar.gz: 9b6787dc0e4efb41972f5accec14a63d45debb56f19fe863925478021de3a9d35990a9cf35a7d01a958ffaf5df0f5a33227c8c980fadd7fab90e82a65784010c
6
+ metadata.gz: ea3a3d2c15820e024e53da67c6f26ec563ab92e8856deb087604427f9d4aff2eaf344f5850d7b15b7f654f5c38c41c0bac12d79183d3a5801435a00ecbc4f26c
7
+ data.tar.gz: 5ebfbbdb284fd3a33e814cbf0266840c39936aab039e131ecf2bce8b2fc03d0ddf2d4136ecf4de8c4e1caf099593a06f85abc08cde6e91483425f54b9ea807d5
data/README.md CHANGED
@@ -9,7 +9,7 @@ Log in to your slack.com account and get your API token from
9
9
  https://api.slack.com/.
10
10
 
11
11
  gem install slackcat
12
- export SLACKCAT_TOKEN=<your api token>
12
+ export SLACK_TOKEN=<your api token>
13
13
  echo 'hello world' | slackcat -c <channel>
14
14
 
15
15
  ## Usage
@@ -19,15 +19,16 @@ list filenames as arguments. Multiple files will be concatenated.
19
19
 
20
20
  Environment variables:
21
21
 
22
- * `SLACKCAT_TOKEN`: your token from https://api.slack.com/.
23
- * `SLACKCAT_CHANNELS`: default comma-separated list of channel names
24
- to share files
22
+ * `SLACK_TOKEN`: your token from https://api.slack.com/.
23
+ * `SLACK_CHANNELS`: default comma-separated list of channel names to share files
24
+ * `SLACK_GROUPS`: default comma-separated list of private groups to share files
25
25
 
26
26
  Command-line options:
27
27
 
28
28
  ```
29
29
  --token, -k: Slack API token
30
30
  --channels, -c: Channels to share into
31
+ --groups, -g: Private groups to share into
31
32
  --filetype, -t: File type identifier
32
33
  --title, -T: Title of file
33
34
  --filename, -n: Filename of file
data/bin/slackcat CHANGED
@@ -3,33 +3,38 @@
3
3
  require 'httparty'
4
4
  require 'trollop'
5
5
 
6
- require 'pp'
7
-
8
6
  class Slackcat
9
7
  include HTTParty
10
8
  base_uri 'https://slack.com/api'
11
-
9
+
12
10
  def initialize(token)
13
11
  @token = token
14
12
  end
15
-
13
+
16
14
  def channels
17
15
  self.class.get('/channels.list', query: { token: @token }).tap do |response|
18
16
  raise "error retrieving channel list: #{response.fetch('error', 'unknown error')}" unless response['ok']
19
17
  end
20
18
  end
21
-
19
+
20
+ def groups
21
+ self.class.get('/groups.list', query: { token: @token }).tap do |response|
22
+ raise "error retrieving group list: #{response.fetch('error', 'unknown error')}" unless response['ok']
23
+ end
24
+ end
25
+
22
26
  def upload(params)
23
27
  self.class.post('/files.upload', body: params.merge({token: @token})).tap do |response|
24
28
  raise "error uploading file: #{response.fetch('error', 'unknown error')}" unless response['ok']
25
29
  end
26
30
  end
27
-
31
+
28
32
  end
29
33
 
30
34
  opts = Trollop::options do
31
35
  opt :token, 'Slack API token', type: :string, short: 'k', default: ENV.fetch('SLACK_TOKEN', nil)
32
36
  opt :channels, 'Channels to share into', type: :string, short: 'c', default: ENV.fetch('SLACK_CHANNELS', nil)
37
+ opt :groups, 'Groups to share into', type: :string, short: 'g', default: ENV.fetch('SLACK_GROUPS', nil)
33
38
  opt :filetype, 'File type identifier', type: :string, short: 't'
34
39
  opt :title, 'Title of file', type: :string, short: 'T'
35
40
  opt :filename, 'Filename of file', type: :string, short: 'n'
@@ -47,16 +52,28 @@ channels = if opts[:channels]
47
52
  names = opts[:channels].gsub(/\#/, '').split(/[\s,]+/) # array of names with no #
48
53
  slack.channels['channels'].inject({}) do |hash, channel| # get channel list
49
54
  hash[channel['name']] = channel['id']; hash # index by name
50
- end.values_at(*names).join(',') # list of ids matching given names
55
+ end.values_at(*names) # list of ids matching given names
51
56
  end
52
57
 
58
+ ## get group IDs
59
+ groups = if opts[:groups]
60
+ names = opts[:groups].gsub(/\#/, '').split(/[\s,]+/) # array of names with no #, probably not an issue for groups, but whatever.
61
+ slack.groups['groups'].inject({}) do |hash, group | # get channel list
62
+ hash[group['name']] = group['id']; hash # index by name
63
+ end.values_at(*names) # list of ids matching given names
64
+ end
65
+
66
+ ids = []
67
+ ids.concat(channels) if channels
68
+ ids.concat(groups) if groups
69
+
53
70
  params = {
54
71
  content: ARGF.read,
55
72
  filetype: opts[:filetype],
56
73
  filename: opts[:filename],
57
74
  title: opts[:title],
58
75
  initial_comment: opts[:initial_comment],
59
- channels: channels,
76
+ channels: ids.join(","),
60
77
  }.select { |_, value| value }
61
78
 
62
79
  slack.upload(params)
@@ -1,3 +1,3 @@
1
1
  module Slackcat
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/slackcat.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "slackcat/version"
2
+
3
+ module Slackcat
4
+ # Your code goes here...
5
+ 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.0.3
4
+ version: 0.0.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-02-21 00:00:00.000000000 Z
11
+ date: 2014-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,6 +80,7 @@ files:
80
80
  - README.md
81
81
  - Rakefile
82
82
  - bin/slackcat
83
+ - lib/slackcat.rb
83
84
  - lib/slackcat/version.rb
84
85
  - slackcat.gemspec
85
86
  homepage: https://github.com/rlister/slackcat
@@ -102,8 +103,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
103
  version: '0'
103
104
  requirements: []
104
105
  rubyforge_project:
105
- rubygems_version: 2.0.3
106
+ rubygems_version: 2.0.14
106
107
  signing_key:
107
108
  specification_version: 4
108
109
  summary: Upload a file to slack
109
110
  test_files: []
111
+ has_rdoc: