slack-post 0.0.1 → 0.1.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,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- YTVjZjRiYjU4ODg3OTRkMmU5NzlmNjQyMzA5ZGNiNmE1OTJhODhhMw==
5
- data.tar.gz: !binary |-
6
- ZWE1MmFiOWUzNzg5ZTAwODU1NTA0ZTI0OTUzNGNkN2U1YjIyODkwMA==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- ZTU4MzU2NDUzNmQ0NDQ5MGMxNzE4YjNhZjMzNDQxZmEzODc0NDg4MDg0Mzlj
10
- ZTU3YmEwMjQyYjJiMTk5ZDEzNmM0Y2Y3NDMxNzgzMGUzNWM0MjJkOGM2MDJj
11
- NWZjYzhjZDQ0MmEwMDhjNWUyZTAwN2NjYTIwNjMxZjc1Mzk4MjA=
12
- data.tar.gz: !binary |-
13
- MGU2Zjc2M2M2NTI3MmRiN2IwZjliMjBmNDMyMDQ1NGFlZmYwM2I3NWI4NGM5
14
- ZWU0YmNjZTg3NzcwYTI3Mzg4YmY2YWMxZjUyZjEzOTI5NzVlY2M1YzU3M2Nj
15
- OTFmYmMxNWMxMzk5NDg2YTRjYTI4NTU0NGJmYThiOTEzMGU3Mjc=
2
+ SHA1:
3
+ metadata.gz: 86078125f4d37d83582258b66f07212486dbb43f
4
+ data.tar.gz: e4f33f59f2e3cb686e647e7512c734d98ab1f106
5
+ SHA512:
6
+ metadata.gz: 3a25872cff85e15826d1385b5adff552dc2b5af06f2ab641e770e22685544a9b6127f65fea0a0824c4dd161afd489ab35675368d2decfaf5f11dfa1a31689188
7
+ data.tar.gz: da6ea5afcd462abf6c2030b9d4c9e94c3b5cec119dde52ab41bdfd1f1b183d5994cc49d159a40dd23247850bb748dfb81803bde6f0a142cec1ec08a55640c230
data/.gitignore CHANGED
@@ -15,3 +15,5 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+
19
+ /vendor/
data/README.md CHANGED
@@ -6,7 +6,7 @@ Just a simple thing to post messages to your [Slack](http://slack.com) rooms.
6
6
 
7
7
  Add this line to your application's Gemfile:
8
8
 
9
- gem 'slack-post', git: "git@github.com:CozyCo/slack-post.git", branch: "release"
9
+ gem 'slack-post'
10
10
 
11
11
  And then execute:
12
12
 
@@ -25,6 +25,29 @@ Slack::Post.configure(
25
25
  Slack::Post.post "Domo arigato.", '#general'
26
26
  ```
27
27
 
28
+ ### slack-post Command
29
+
30
+ slack-post comes with a `slack-post` command so you can send messages from the command line:
31
+
32
+ ```sh
33
+ $ slack-post
34
+ Missing options: subdomain, message
35
+ Usage: slack-post [options]
36
+ -s, --subdomain [SUBDOMAIN] Your slack subdomain
37
+ -m, --message [MESSAGE] Your message
38
+ -r, --room [ROOM] The slack room where the message should go (without '#', default 'general')
39
+ -u, --username [USERNAME] The username, default 'slackbot'
40
+ -f, --config-file [CONFIGFILE] The configuration file with token or set SLACK_TOKEN environment variable
41
+
42
+ $ SLACK_TOKEN="1asbcdsdfpoiej2" slack-post -s foo -r random -m "line1\nline2"
43
+ ```
44
+
45
+ If SLACK_TOKEN isn't set, slack-post tries to read it from ~/.slack.conf or from the file defined with `--config-file`.
46
+ ```sh
47
+ $ cat ~/.slack.conf
48
+ token: "1asbcdsdfpoiej2"
49
+ ```
50
+
28
51
  ## Contributing
29
52
 
30
53
  1. Fork it
data/bin/slack-post ADDED
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'slack/post'
4
+ require 'yaml'
5
+ require 'optparse'
6
+
7
+ def read_token(file)
8
+ token = ENV['SLACK_TOKEN']
9
+ if token.nil?
10
+ if file
11
+ token = YAML.load_file(file)["token"]
12
+ else
13
+ token = YAML.load_file(ENV['HOME'] + "/.slack.conf")["token"] rescue nil
14
+ end
15
+ end
16
+ token
17
+ end
18
+
19
+ def post(options)
20
+ unless options[:channel].start_with?("#")
21
+ options[:channel] = "#" + options[:channel]
22
+ end
23
+ Slack::Post.configure options
24
+ Slack::Post.post options[:message].gsub(/\\n/,"\n")
25
+ end
26
+
27
+ options = Hash.new
28
+ optparse = OptionParser.new do |opts|
29
+ opts.banner = "Usage: slack-post [options]"
30
+
31
+ opts.on('-s', '--subdomain [SUBDOMAIN]', String, 'Your slack subdomain') do |subdomain|
32
+ options[:subdomain] = subdomain
33
+ end
34
+
35
+ opts.on('-m', '--message [MESSAGE]', 'Your message') do |message|
36
+ options[:message] = message
37
+ end
38
+
39
+ options[:channel] = 'general'
40
+ opts.on('-r', '--room [ROOM]', String, 'The slack room where the message should go (without \'#\', default \'general\')') do |room|
41
+ options[:channel] = room
42
+ end
43
+
44
+ options[:username] = 'slackbot'
45
+ opts.on('-u', '--username [USERNAME]', String, 'The username, default \'slackbot\'') do |username|
46
+ options[:username] = username
47
+ end
48
+
49
+ opts.on('-f', '--config-file [CONFIGFILE]', String, 'The configuration file with token or set SLACK_TOKEN environment variable') do |config_file|
50
+ options[:config_file] = config_file
51
+ end
52
+
53
+ opts.on('-h', 'Show this help') do
54
+ puts opts
55
+ exit 1
56
+ end
57
+ end
58
+
59
+ begin
60
+ optparse.parse!
61
+
62
+ mandatory = [:subdomain, :message]
63
+ missing = mandatory.select { |param| options[param].nil? }
64
+ if not missing.empty?
65
+ $stderr.puts "Missing options: #{missing.join(', ')}"
66
+ $stderr.puts optparse
67
+ exit 1
68
+ end
69
+
70
+ options[:token] = read_token(options[:config_file])
71
+ if options[:token].nil?
72
+ $stderr.puts "Could not find any token!"
73
+ exit 1
74
+ end
75
+
76
+ post options
77
+ rescue => e
78
+ puts $!.to_s
79
+ puts optparse
80
+ exit 1
81
+ end
82
+
83
+
@@ -1,5 +1,5 @@
1
1
  module Slack
2
2
  module Post
3
- VERSION = "0.0.1"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
data/lib/slack/post.rb CHANGED
@@ -11,7 +11,7 @@ module Slack
11
11
  channel: '#general'
12
12
  }.freeze
13
13
 
14
- def self.post(message,chan=nil)
14
+ def self.post(message,chan=nil,opts={})
15
15
  raise "You need to call Slack::Post.configure before trying to send messages." unless configured?(chan.nil?)
16
16
  pkt = {
17
17
  channel: chan || config[:channel],
@@ -20,10 +20,16 @@ module Slack
20
20
  if config[:username]
21
21
  pkt[:username] = config[:username]
22
22
  end
23
+ if opts.has_key?(:icon_url) or config.has_key?(:icon_url)
24
+ pkt[:icon_url] = opts[:icon_url] || config[:icon_url]
25
+ end
26
+ if opts.has_key?(:icon_emoji) or config.has_key?(:icon_emoji)
27
+ pkt[:icon_emoji] = opts[:icon_emoji] || config[:icon_emoji]
28
+ end
23
29
  uri = URI.parse(post_url)
24
30
  http = Net::HTTP.new(uri.host, uri.port)
25
31
  http.use_ssl = true
26
- http.ssl_version = :SSLv3
32
+ http.ssl_version = :TLSv1
27
33
  http.verify_mode = OpenSSL::SSL::VERIFY_PEER
28
34
  req = Net::HTTP::Post.new(uri.request_uri)
29
35
  req.body = Yajl::Encoder.encode(pkt)
@@ -58,7 +64,7 @@ module Slack
58
64
  @config = config.merge(prune(opts))
59
65
  end
60
66
 
61
- KnownConfigParams = [:username,:channel,:subdomain,:token].freeze
67
+ KnownConfigParams = [:username,:channel,:subdomain,:token,:icon_url,:icon_emoji].freeze
62
68
 
63
69
  def self.prune(opts)
64
70
  opts.inject({}) do |acc,(k,v)|
metadata CHANGED
@@ -1,69 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slack-post
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Bragg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-18 00:00:00.000000000 Z
11
+ date: 2014-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: yajl-ruby
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  description: Pretty simple really. It posts to slack fer ya.
56
56
  email:
57
57
  - remotezygote@gmail.com
58
- executables: []
58
+ executables:
59
+ - slack-post
59
60
  extensions: []
60
61
  extra_rdoc_files: []
61
62
  files:
62
- - .gitignore
63
+ - ".gitignore"
63
64
  - Gemfile
64
65
  - LICENSE.txt
65
66
  - README.md
66
67
  - Rakefile
68
+ - bin/slack-post
67
69
  - lib/slack/post.rb
68
70
  - lib/slack/post/version.rb
69
71
  - slack-post.gemspec
@@ -77,17 +79,17 @@ require_paths:
77
79
  - lib
78
80
  required_ruby_version: !ruby/object:Gem::Requirement
79
81
  requirements:
80
- - - ! '>='
82
+ - - ">="
81
83
  - !ruby/object:Gem::Version
82
84
  version: '0'
83
85
  required_rubygems_version: !ruby/object:Gem::Requirement
84
86
  requirements:
85
- - - ! '>='
87
+ - - ">="
86
88
  - !ruby/object:Gem::Version
87
89
  version: '0'
88
90
  requirements: []
89
91
  rubyforge_project:
90
- rubygems_version: 2.0.3
92
+ rubygems_version: 2.0.14
91
93
  signing_key:
92
94
  specification_version: 4
93
95
  summary: It's for posting messages to your slack.