hipchat-cli 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +39 -0
- data/bin/hipchat_notify +13 -0
- data/lib/hip_chat_cli/application.rb +66 -0
- data/lib/hip_chat_cli/message.rb +32 -0
- data/lib/hip_chat_cli/version.rb +3 -0
- data/lib/hip_chat_cli.rb +4 -0
- metadata +69 -0
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
## A Ruby Command Line tool for the HipChat API
|
2
|
+
|
3
|
+
Currently provides a simple, easy to use command line tool for sending a message to a HipChat room. Similar to https://github.com/hipchat/hipchat-cli, but about a billion times more Ruby.
|
4
|
+
|
5
|
+
### Usage
|
6
|
+
|
7
|
+
Install the gem:
|
8
|
+
|
9
|
+
gem install hipchat-cli
|
10
|
+
|
11
|
+
Use the bin:
|
12
|
+
|
13
|
+
hipchat_notify --room [Room Name] --token [API TOKEN] Hello World!
|
14
|
+
|
15
|
+
or
|
16
|
+
|
17
|
+
echo "Hello World" | hipchat_notify --room [Room Name] --token [API TOKEN]
|
18
|
+
|
19
|
+
### Options
|
20
|
+
|
21
|
+
-t, --token API_TOKEN [required] The API token for HipChat
|
22
|
+
-r, --room ROOM [required] The room ID to receive the message
|
23
|
+
-u, --user USERNAME The name of the sender. Default: API Client
|
24
|
+
-f, --format FORMAT The format of the message. Default: html
|
25
|
+
-c, --color COLOR message color: "red", "yellow", "green", "purple" or "random" (default "yellow")
|
26
|
+
-n, --notify notify the users in the room about the message
|
27
|
+
-h, --help Show the options and sample usage
|
28
|
+
|
29
|
+
|
30
|
+
### Contributing
|
31
|
+
|
32
|
+
1. Check master to make sure your idea hasn't already been created
|
33
|
+
2. Fork the repo
|
34
|
+
3. Add your changes. Make sure the tests pass (if any)
|
35
|
+
4. Submit a pull request.
|
36
|
+
|
37
|
+
### License
|
38
|
+
|
39
|
+
See LICENSE for details
|
data/bin/hipchat_notify
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require_relative "../lib/hip_chat_cli"
|
4
|
+
|
5
|
+
begin
|
6
|
+
HipChatCli::Application.new(ARGV).run
|
7
|
+
rescue Errno::ENOENT => err
|
8
|
+
abort "hip_chat_cli: #{err.message}"
|
9
|
+
rescue OptionParser::MissingArgument => err
|
10
|
+
abort "hip_chat_cli: #{err.message}\nusage: hipchat_notify -h"
|
11
|
+
rescue OptionParser::InvalidOption => err
|
12
|
+
abort "hip_chat_cli: #{err.message}\nusage: hipchat_notify -h"
|
13
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module HipChatCli
|
2
|
+
class Application
|
3
|
+
def initialize(argv)
|
4
|
+
@options, @msg = parse_options(argv)
|
5
|
+
end
|
6
|
+
|
7
|
+
def run
|
8
|
+
HipChatCli::Message.new(@options).deliver(@msg)
|
9
|
+
end
|
10
|
+
|
11
|
+
def help
|
12
|
+
@help
|
13
|
+
end
|
14
|
+
|
15
|
+
def parse_options(argv)
|
16
|
+
options = {
|
17
|
+
color: "yellow",
|
18
|
+
notify: false,
|
19
|
+
username: ENV['HIPCHAT_API_USERNAME'] || "API Client",
|
20
|
+
room: ENV['HIPCHAT_API_ROOM'] || nil,
|
21
|
+
token: ENV['HIPCHAT_API_TOKEN'] || nil
|
22
|
+
}
|
23
|
+
|
24
|
+
parser = OptionParser.new
|
25
|
+
parser.banner = "Usage: hipchat_notify [OPTIONS] message"
|
26
|
+
parser.separator ""
|
27
|
+
parser.separator "Options"
|
28
|
+
|
29
|
+
parser.on("-t","--token API_TOKEN","[required] The API token for HipChat") do |token|
|
30
|
+
options[:token] = token
|
31
|
+
end
|
32
|
+
|
33
|
+
parser.on("-r","--room ROOM","[required] The room ID to receive the message") do |room|
|
34
|
+
options[:room] = room
|
35
|
+
end
|
36
|
+
|
37
|
+
parser.on("-u","--user USERNAME","The name of the sender. Default: API Client") do |username|
|
38
|
+
options[:username] = username
|
39
|
+
end
|
40
|
+
|
41
|
+
parser.on("-f","--format FORMAT","The format of the message. Default: html") do |format|
|
42
|
+
options[:format] = format
|
43
|
+
end
|
44
|
+
|
45
|
+
parser.on("-c","--color COLOR",'message color: "red", "yellow", "green", "purple", "gray" or "random" (default "yellow")') do |color|
|
46
|
+
options[:color] = color if %w(red yellow green purple gray random).include?(color.downcase)
|
47
|
+
end
|
48
|
+
|
49
|
+
parser.on("-n","--notify","notify the users in the room about the message") do
|
50
|
+
options[:notify] = true
|
51
|
+
end
|
52
|
+
|
53
|
+
parser.on("-h","--help","help") do
|
54
|
+
puts parser.to_s
|
55
|
+
exit 0
|
56
|
+
end
|
57
|
+
|
58
|
+
@help = parser.to_s
|
59
|
+
|
60
|
+
message = parser.parse(argv).join(' ')
|
61
|
+
message = STDIN.read if message.nil? || message == ""
|
62
|
+
|
63
|
+
[options, message]
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'hipchat'
|
2
|
+
|
3
|
+
module HipChatCli
|
4
|
+
class Message
|
5
|
+
def initialize(params)
|
6
|
+
|
7
|
+
%w(token room).each do |key|
|
8
|
+
raise OptionParser::MissingArgument, "#{key} is a required option" if params[key.to_sym].nil?
|
9
|
+
end
|
10
|
+
|
11
|
+
@room = params[:room]
|
12
|
+
@notify = params[:notify] || false
|
13
|
+
@format = params[:format] || 'html'
|
14
|
+
@color = params[:color] || 'yellow'
|
15
|
+
@username = params[:username] || 'API'
|
16
|
+
|
17
|
+
@client = HipChat::Client.new(params[:token])
|
18
|
+
end
|
19
|
+
|
20
|
+
def deliver(message)
|
21
|
+
|
22
|
+
raise OptionParser::MissingArgument, "message is required" if message.nil? || message == ''
|
23
|
+
|
24
|
+
@client[@room].send(@username, message, {
|
25
|
+
:notify => @notify,
|
26
|
+
:message_format => @format,
|
27
|
+
:color => @color
|
28
|
+
}
|
29
|
+
)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/hip_chat_cli.rb
ADDED
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hipchat-cli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jeremy Baker
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-07-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: hipchat
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: A Ruby Command Line interface for the HipChat API
|
31
|
+
email:
|
32
|
+
- jhubert@gmail.com
|
33
|
+
executables:
|
34
|
+
- hipchat_notify
|
35
|
+
extensions: []
|
36
|
+
extra_rdoc_files: []
|
37
|
+
files:
|
38
|
+
- bin/hipchat_notify
|
39
|
+
- lib/hip_chat_cli/application.rb
|
40
|
+
- lib/hip_chat_cli/message.rb
|
41
|
+
- lib/hip_chat_cli/version.rb
|
42
|
+
- lib/hip_chat_cli.rb
|
43
|
+
- README.md
|
44
|
+
homepage: http://github.com/jhubert/hipchat-cli-rb
|
45
|
+
licenses: []
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 1.9.2
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.3.6
|
62
|
+
requirements: []
|
63
|
+
rubyforge_project: hipchat_cli
|
64
|
+
rubygems_version: 1.8.23
|
65
|
+
signing_key:
|
66
|
+
specification_version: 3
|
67
|
+
summary: A Ruby Command Line interface for the HipChat API
|
68
|
+
test_files: []
|
69
|
+
has_rdoc:
|