Created
August 20, 2014 18:38
-
-
Save mivok/ab4e23e5e3a6fe2bdb04 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Sends cat pics to hipchat using either the hipchat api or kitty command | |
# | |
# Go to https://yourcompany.hipchat.com/account/api to get an API key and put | |
# it in '.api_token' in the same directory as this script. | |
# | |
# To send ascii cats you need the 'kitty' gem installed: gem install kitty | |
# | |
require 'hipchat' | |
require 'json' | |
require 'mixlib/cli' | |
api_token = File.read(File.expand_path("../.api_token", __FILE__)).chomp | |
class KittyCLI | |
include Mixlib::CLI | |
option :user, | |
:short => "-u USER", | |
:long => "--user USER", | |
:description => "Send to a user" | |
option :room, | |
:short => "-r ROOM", | |
:long => "--room ROOM", | |
:description => "Send to a room" | |
option :ascii, | |
:short => "-a", | |
:long => "--ascii", | |
:boolean => true, | |
:default => false, | |
:description => "Send ascii cat instead of a gif" | |
option :help, | |
:short => "-h", | |
:long => "--help", | |
:description => "Show this message", | |
:on => :tail, | |
:boolean => true, | |
:show_options => true, | |
:exit => 0 | |
end | |
cli = KittyCLI.new | |
cli.parse_options | |
client = HipChat::Client.new(api_token, :api_version => 'v2') | |
if cli.config[:ascii] | |
kitty = "/code #{%x{ kitty }}" | |
else | |
kitty = %x{ curl -v 'thecatapi.com/api/images/get?format=src&type=gif' 2>&1 | grep Location | awk '{print $3}' }.chomp | |
end | |
if cli.config[:user] | |
target = client.user(cli.config[:user]) | |
target.send(kitty) | |
elsif cli.config[:room] | |
target = client[cli.config[:room]] | |
target.send("Kitty", kitty, :message_format => "text") | |
else | |
puts "Need at least one of user/room" | |
exit 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment