sendhipchat 1.0.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.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in sendhipchat.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Brian L. Troutwine
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,36 @@
1
+ sendhipchat -- A sendmail like tool for [HipChat](http://hipchat.com)
2
+ =====================================================================
3
+
4
+ I do Ops for CarePilot.com and we make extensive use of
5
+ [HipChat](http://hipchat.com) for planning and
6
+ coordination. Incongriously--and this is my fault--our notification is
7
+ done exclusively through email, mostly for want of a sendmail that
8
+ spits out to HipChat, rather than our local, friendly mail server.
9
+
10
+ `sendhipchat` fills that want. It's inspired by sendmail in all the
11
+ ways I care about and sends [room
12
+ messages](https://www.hipchat.com/docs/api/method/rooms/message).
13
+
14
+ Installation
15
+ ------------
16
+
17
+ Assuming you have a Ruby environment setup (if you don't, I suggest
18
+ your system Ruby, [rbenv](https://github.com/sstephenson/rbenv) or
19
+ [RVM](http://beginrescueend.com/), in that order) then please:
20
+
21
+ gem install sendhipchat
22
+
23
+ and enjoy.
24
+
25
+ Usage
26
+ -----
27
+
28
+ Send messages to a single room:
29
+
30
+ echo 'single room message' | sendhipchat --api-token TOKEN --from 'sendhipchat' --rooms "SINGLE ROOM"
31
+
32
+ Send messages to multiple rooms:
33
+
34
+ echo 'multiple room message' | sendhipchat --api-token TOKEN --from 'sendhipchat' --rooms "SINGLE ROOM","OTHER ROOM"
35
+
36
+ See the help text (`sendhipchat --help`) for more options.
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'sendhipchat'
4
+ Sendhipchat::Runner.new(ARGV).run!
@@ -0,0 +1,7 @@
1
+ module Sendhipchat
2
+ ROOT = File.expand_path(File.dirname(__FILE__))
3
+
4
+ autoload :Runner, "#{ROOT}/sendhipchat/runner"
5
+ end
6
+
7
+ require "#{Sendhipchat::ROOT}/sendhipchat/version"
@@ -0,0 +1,150 @@
1
+ require 'optparse'
2
+ require 'hipchat-api'
3
+
4
+ module Sendhipchat
5
+ trap(:INT) { puts; exit }
6
+
7
+ class Runner
8
+ YELLOW = 'yellow'
9
+ RED = 'red'
10
+ GREEN = 'green'
11
+ PURPLE = 'purple'
12
+ BLUE = 'blue'
13
+
14
+ attr_accessor :options
15
+
16
+ def initialize(argv)
17
+ @argv = argv
18
+ @options = {
19
+ :api_token => nil,
20
+ :rooms => [],
21
+ :from => nil,
22
+ :notify => false,
23
+ :color => YELLOW
24
+ }
25
+
26
+ parse!
27
+ end
28
+
29
+ def parser
30
+ @parser ||= OptionParser.new do |opts|
31
+ opts.banner = <<-EOS
32
+ Usage: sendhipchat [options]
33
+
34
+ Messages are read in from STDIN
35
+ EOS
36
+ opts.separator ''
37
+ opts.on('-a TOKEN', '--api-token TOKEN', 'HipChat API token.') do |tk|
38
+ @options[:api_token] = tk
39
+ end
40
+ opts.on('-f ALIAS', '--from ALIAS', 'Message "from".') do |f|
41
+ if f.length > 15
42
+ puts 'ERROR: from name must be <= 15 characters'
43
+ puts
44
+ puts @parser
45
+ exit 1
46
+ end
47
+ @options[:from] = f
48
+ end
49
+ opts.on('--color COLOR', 'Message color: (yellow|red|blue|green|purple)') do |c|
50
+ if color_valid?(c)
51
+ @options[:color] = color_value(c)
52
+ else
53
+ puts 'ERROR: not a valid color choice'
54
+ puts
55
+ puts opts
56
+ exit 1
57
+ end
58
+ end
59
+ opts.on('--notify', 'Alert room members to message.') do
60
+ @options[:notify] = true
61
+ end
62
+ opts.on('--rooms ROOMS', 'Comma separated room names.') do |rooms|
63
+ @options[:rooms] = rooms.split(',').map { |r| r.strip }
64
+ end
65
+ opts.separator ''
66
+ opts.on_tail('-h', '--help', 'Show this message.') do
67
+ puts opts
68
+ exit 0
69
+ end
70
+ opts.on_tail('-v', '--version', 'Show version') do
71
+ puts Sendhipchat::VERSION; exit
72
+ end
73
+ end
74
+ end
75
+
76
+ def parse!
77
+ parser.parse! @argv
78
+
79
+ if @options[:api_token] == nil
80
+ puts "ERROR: Must specify API token."
81
+ puts
82
+ puts @parser
83
+ exit 1
84
+ elsif @options[:from] == nil
85
+ puts 'ERROR: Must provide a "from" alias.'
86
+ puts
87
+ puts @parser
88
+ exit 1
89
+ elsif @options[:rooms].empty?
90
+ puts 'ERROR: Must specify at least one room.'
91
+ puts
92
+ puts @parser
93
+ exit 1
94
+ end
95
+ end
96
+
97
+ def run!
98
+ hp = HipChat::API.new(@options[:api_token])
99
+
100
+ rooms_to_id = rooms_flip(hp.rooms_list['rooms'])
101
+
102
+ rooms = rooms_to_id.keys
103
+ if !( (@options[:rooms] - rooms).empty? )
104
+ puts 'ERROR: Only these rooms exist.'
105
+ puts
106
+ rooms.each do |r|
107
+ puts r
108
+ end
109
+ puts
110
+ puts @parser
111
+ exit 1
112
+ end
113
+
114
+ msg = STDIN.read
115
+ if msg.length > 5000
116
+ puts 'ERROR: message must be <= 5000 characters'
117
+ puts
118
+ puts @parser
119
+ exit 1
120
+ end
121
+
122
+ @options[:rooms].each do |r|
123
+ hp.rooms_message(room_id=rooms_to_id[r], from=@options[:from],
124
+ message=msg, notify=@options[:notify], color=@options[:color])
125
+ end
126
+ end
127
+
128
+ private
129
+
130
+ def rooms_flip(arr)
131
+ rooms = {}
132
+ arr.each do |h|
133
+ rooms[h['name']] = h['room_id']
134
+ end
135
+ rooms
136
+ end
137
+
138
+ def color_valid?(color)
139
+ ['yellow', 'red', 'green', 'purple', 'blue'].member?(color.downcase)
140
+ end
141
+
142
+ def color_value(color)
143
+ { 'yellow' => YELLOW,
144
+ 'red' => RED,
145
+ 'green' => GREEN,
146
+ 'purple' => PURPLE,
147
+ 'blue' => BLUE}[color.downcase]
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,3 @@
1
+ module Sendhipchat
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "sendhipchat/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "sendhipchat"
7
+ s.version = Sendhipchat::VERSION
8
+ s.authors = ["Brian L. Troutwine"]
9
+ s.email = ["brian@troutwine.us"]
10
+ s.homepage = "https://github.com/blt/sendhipchat"
11
+ s.summary = %q{A sendmail alike tool for HipChat.}
12
+ s.description = %q{Send room messages to HipChat with an interface inspired by sendmail.}
13
+
14
+ s.rubyforge_project = "sendhipchat"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_runtime_dependency 'hipchat-api', '~> 1.0.2'
22
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sendhipchat
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Brian L. Troutwine
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-11-19 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: hipchat-api
16
+ requirement: &76461780 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.0.2
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *76461780
25
+ description: Send room messages to HipChat with an interface inspired by sendmail.
26
+ email:
27
+ - brian@troutwine.us
28
+ executables:
29
+ - sendhipchat
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - .gitignore
34
+ - Gemfile
35
+ - LICENSE
36
+ - README.md
37
+ - Rakefile
38
+ - bin/sendhipchat
39
+ - lib/sendhipchat.rb
40
+ - lib/sendhipchat/runner.rb
41
+ - lib/sendhipchat/version.rb
42
+ - sendhipchat.gemspec
43
+ homepage: https://github.com/blt/sendhipchat
44
+ licenses: []
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubyforge_project: sendhipchat
63
+ rubygems_version: 1.8.10
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: A sendmail alike tool for HipChat.
67
+ test_files: []