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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d53ce3d01a0e4d82cc74c4b1190c9676b5f9c7d2
4
- data.tar.gz: 6cf9c11682d18f38add4c9b24009a224181d96e1
3
+ metadata.gz: ec17396e6bab7b65c8e0d9d3973286e0e7f04b4f
4
+ data.tar.gz: 9221832546c13e35efd896d79a5546afff9e9c5e
5
5
  SHA512:
6
- metadata.gz: 9e0ffdefff653d4ce2a32e055580dfe2820c210ff6d93d1f222e38f71fa3fd20d28f37ebab7f63852617f5d0d74c1307ec5f9b45911d4418a8e267afbe7569fd
7
- data.tar.gz: 484d0339555de1aa0da775863209073b84b2fc4fd1ff204889b192f8379d312ea5ab8cc33c5ee87f9006d471c202eb3b25f1e8d92808e15805d2d9342c2aaf7e
6
+ metadata.gz: 655a405b4cb06eec4a0e1d038932580ccf5989766ffcc64b4e1a05f1545fcf68f8a3f63275841ae103d18974a7f389e4acc9af6fa7c4f7db9d66d22631e6e14d
7
+ data.tar.gz: dd7e81b21c457ee15cd1e82f0a1befea8cd2b18056138725c41c0b48abe42325a319c35492a8e002fd4ebc2c3d0dbee42fc11b6db9e4e6e55616a672e90fa03f
data/.gitignore CHANGED
@@ -3,7 +3,6 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
- Gemfile.lock
7
6
  InstalledFiles
8
7
  _yardoc
9
8
  coverage
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 'httparty'
3
+ require 'httmultiparty'
4
4
  require 'trollop'
5
5
 
6
6
  class Slackcat
7
- include HTTParty
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', type: :string, short: 'k', default: ENV.fetch('SLACK_TOKEN', nil)
57
- opt :channels, 'Channels to share', type: :string, short: 'c', default: ''
58
- opt :groups, 'Groups to share', type: :string, short: 'g', default: ''
59
- opt :users, 'Users (DMs) to share', type: :string, short: 'u', default: ''
60
- opt :filetype, 'File type identifier', type: :string, short: 't'
61
- opt :title, 'Title of file', type: :string, short: 'T'
62
- opt :filename, 'Filename of file', type: :string, short: 'n'
63
- opt :initial_comment, 'Initial comment to add', type: :string, short: 'i'
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
- slack.upload(params)
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
@@ -1,3 +1,3 @@
1
1
  module Slackcat
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/slackcat.gemspec CHANGED
@@ -21,6 +21,6 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake"
23
23
 
24
- spec.add_dependency 'httparty'
24
+ spec.add_dependency 'httmultiparty'
25
25
  spec.add_dependency 'trollop'
26
26
  end
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.1.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: httparty
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