Skip to content

Instantly share code, notes, and snippets.

@mivok
Created August 20, 2014 18:38
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mivok/ab4e23e5e3a6fe2bdb04 to your computer and use it in GitHub Desktop.
Save mivok/ab4e23e5e3a6fe2bdb04 to your computer and use it in GitHub Desktop.
#!/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