slackcat 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8f11f1b851e7c133cf3d42791935865c8d8ee1a3
4
+ data.tar.gz: 9bba5f97ae8edf49e617ebf560aebcf2845946c8
5
+ SHA512:
6
+ metadata.gz: 16cff737bd551802fe55f58701fd76b2bed9e997eae420efe6ea2cb771a4bee8c13ffc688b3c65bc7f4a375da72bee80c5fdabc9ef580f282dba07495cd21f35
7
+ data.tar.gz: f4b80327411546a4172d9f151b29855f86cb1875f33cfcda4073c3395360060b177075e911a4cfca341fc4130105befe170fe9ad57213cc6ceb3824da05660ab
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Richard Lister
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Slackcat
2
+
3
+ Upload files and snippets to [Slack](http://slack.com) chat from the
4
+ command-line.
5
+
6
+ ## Getting started
7
+
8
+ Log in to your slack.com account and get your API token from
9
+ https://api.slack.com/.
10
+
11
+ gem install 'slackcat'
12
+ export SLACKCAT_TOKEN=<your api token>
13
+ echo 'hello world' | slackcat -c <channel>
14
+
15
+ ## Usage
16
+
17
+ `slackcat` is used similarly to unix `cat`: read data from STDIN or
18
+ list filenames as arguments. Multiple files will be concatenated.
19
+
20
+ Environment variables:
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
25
+
26
+ Command-line options:
27
+
28
+ ```
29
+ --token, -k: Slack API token
30
+ --channels, -c: Channels to share into
31
+ --filetype, -t: File type identifier
32
+ --title, -T: Title of file
33
+ --filename, -n: Filename of file
34
+ --initial-comment, -i: Initial comment to add
35
+ --help, -h: Show this message
36
+ ```
37
+
38
+ File uploads to slack are private by default. If you list channels,
39
+ content will be shared to them.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/slackcat ADDED
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'httparty'
4
+ require 'trollop'
5
+
6
+ class Slackcat
7
+ include HTTParty
8
+ base_uri 'https://slack.com/api'
9
+
10
+ def initialize(token)
11
+ @token = token
12
+ end
13
+
14
+ def channels
15
+ self.class.get('/channels.list', query: { token: @token }).tap do |response|
16
+ raise "error retrieving channel list: #{response.fetch('error', 'unknown error')}" unless response['ok']
17
+ end
18
+ end
19
+
20
+ def upload(params)
21
+ self.class.post('/files.upload', body: params.merge({token: @token})).tap do |response|
22
+ raise "error uploading file: #{response.fetch('error', 'unknown error')}" unless response['ok']
23
+ end
24
+ end
25
+
26
+ end
27
+
28
+ opts = Trollop::options do
29
+ opt :token, 'Slack API token', type: :string, short: 'k', default: ENV.fetch('SLACK_TOKEN', nil)
30
+ opt :channels, 'Channels to share into', type: :string, short: 'c', default: ENV.fetch('SLACK_CHANNELS', nil)
31
+ opt :filetype, 'File type identifier', type: :string, short: 't'
32
+ opt :title, 'Title of file', type: :string, short: 'T'
33
+ opt :filename, 'Filename of file', type: :string, short: 'n'
34
+ opt :initial_comment, 'Initial comment to add', type: :string, short: 'i'
35
+ end
36
+
37
+ raise 'set slack API token using SLACK_TOKEN or -k option' unless opts[:token]
38
+ slack = Slackcat.new(opts[:token])
39
+
40
+ ## get channel IDs
41
+ channels = if opts[:channels]
42
+ names = opts[:channels].gsub(/\#/, '').split(/[\s,]+/) # array of names with no #
43
+ slack.channels['channels'].inject({}) do |hash, channel| # get channel list
44
+ hash[channel['name']] = channel['id']; hash # index by name
45
+ end.values_at(*names).join(',') # list of ids matching given names
46
+ end
47
+
48
+ params = {
49
+ content: ARGF.read,
50
+ filetype: opts[:filetype],
51
+ filename: opts[:filename],
52
+ title: opts[:title],
53
+ initial_comment: opts[:initial_comment],
54
+ channels: channels,
55
+ }.select { |_, value| value }
56
+
57
+ slack.upload(params)
@@ -0,0 +1,3 @@
1
+ module Slackcat
2
+ VERSION = "0.0.1"
3
+ end
data/slackcat.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'slackcat/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "slackcat"
8
+ spec.version = Slackcat::VERSION
9
+ spec.authors = ["Richard Lister"]
10
+ spec.email = ["rlister@gmail.com"]
11
+ spec.description = %q{Upload a file to slack}
12
+ spec.summary = %q{Upload a file to slack}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_dependency 'httparty'
25
+ spec.add_dependency 'trollop'
26
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: slackcat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Richard Lister
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: httparty
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: trollop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Upload a file to slack
70
+ email:
71
+ - rlister@gmail.com
72
+ executables:
73
+ - slackcat
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - bin/slackcat
83
+ - lib/slackcat/version.rb
84
+ - slackcat.gemspec
85
+ homepage: ''
86
+ licenses:
87
+ - MIT
88
+ metadata: {}
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 2.0.3
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: Upload a file to slack
109
+ test_files: []