h1. HipChat Wrapper
A very basic wrapper for the HipChat HTTP API.
h2. CI Status
"!https://travis-ci.org/hipchat/hipchat-rb.svg!":https://travis-ci.org/hipchat/hipchat-rb !https://coveralls.io/repos/hipchat/hipchat-rb/badge.svg(Coverage Status)!:https://coveralls.io/r/hipchat/hipchat-rb
h2. Requirements
h2. Installation
h3. Gemfile
bc. gem 'hipchat'
h3. Install
bc. gem install hipchat
h1. Usage
h2. "API v1":https://www.hipchat.com/docs/api
bc.. client = HipChat::Client.new(api_token, :api_version => 'v1')
client = HipChat::Client.new(api_token, :api_version => 'v1', :http_proxy => 'http://proxy_host:proxy_port')
client['my room'].send('username', 'I talk')
client['my room'].send('username', 'I quit!', :notify => true)
client['my room'].send('username', 'Build failed!', :color => 'red')
client['my room'].send('username', '@coworker Build faild!', :message_format => 'text')
client['my room'].topic('Free Ice Cream in the kitchen')
client['my room'].topic('Weekely sales: $10,000', :from => 'Sales Team')
client['my room'].history()
client['my room'].history(:date => '2010-11-19', :timezone => 'PST')
client.create_room("Name", :owner_user_id => 'user_id')
h2. "API v2":https://www.hipchat.com/docs/apiv2
bc.. client = HipChat::Client.new(api_token)
client = HipChat::Client.new(api_token, :http_proxy => 'http://proxy_host:proxy_port')
client['my room'].send('username', 'I talk')
client['my room'].send('username', 'I quit!', :notify => true)
client['my room'].send('username', 'Build failed!', :color => 'red')
client['my room'].send('username', '@coworker Build faild!', :message_format => 'text')
client['my room'].topic('Free Ice Cream in the kitchen')
client['my room'].topic('Weekely sales: $10,000', :from => 'Sales Team')
client['my room'].history()
client['my room'].history(:date => '2010-11-19', :timezone => 'PST')
client['my room'].statistics()
client.create_room("Name", options = {})
client['my room'].get_room
It's recommended to call client['my room'].get_room then pass in modified hash attributes to #update_room client['my room'].update_room(options = {})
client['my room'].delete_room
client['my room'].invite("USER_ID_OR_NAME", options = {})
client.user('foo@bar.org').send('I can send private messages')
client.user('foo@bar.org').status('this is my status', :name=>'Foo Bar', :status=>'Doing very important stuff', :show=>'xa', :mention_name=>'foo', :email=>'foo@barr.org')
h2. Custom Server URL
bc.. client = HipChat::Client.new(api_token, :server_url => 'https://domain.com')
client['my room'].send('username', 'I talk')
client['my room'].send('username', 'I quit!', :notify => true)
client['my room'].send('username', 'Build failed!', :color => 'red')
client['my room'].send('username', '@coworker Build faild!', :message_format => 'text')
client['my room'].topic('Free Ice Cream in the kitchen')
client['my room'].topic('Weekely sales: $10,000', :from => 'Sales Team')
client['my room'].history()
client['my room'].history(:date => '2010-11-19', :timezone => 'PST')
client.create_room("Name", options = {})
client['my room'].get_room
It's easiest to call client['my room'].get_room, parse the json and then pass in modified hash attributes client['my room'].update_room(options = {})
client['my room'].invite("USER_ID_OR_NAME", options = {})
client.user('foo@bar.org').send('I can send private messages')
h2. Capistrano
Capfile
bc. require 'hipchat/capistrano'
deploy.rb
bc.. # Required
set :hipchat_token, "
set :hipchat_enabled, true # set to false to prevent any messages from being sent set :hipchat_announce, false # notify users set :hipchat_color, 'yellow' #normal message color set :hipchat_success_color, 'green' #finished deployment message color set :hipchat_failed_color, 'red' #cancelled deployment message color set :hipchat_message_format, 'html' # Sets the deployment message format, see https://www.hipchat.com/docs/api/method/rooms/message set :hipchat_options, { :api_version => "v2" # Set "v2" to send messages with API v2 }
h3. Who did it?
To determine the user that is currently running the deploy, the capistrano tasks will look for the following:
h3. Commit log notification (only for Capistrano 2)
Send commit log with deploy notification. We currently support git and svn.
bc.. set :hipchat_commit_log, true
set :hipchat_commit_log_format, ":time :user\n:message\n" set :hipchat_commit_log_time_format, "%Y/%m/%d %H:%M:%S" set :hipchat_commit_log_message_format, "^PROJECT-\d+" # extracts ticket number from message
h2. Rails 3 Rake Task
Send a message using a rake task:
bc. rake hipchat:send["hello world"]
or
bc. rake hipchat:send MESSAGE="hello world"
Options like the room, API token, user name and notification flag can be set in YAML.
RAILS_ROOT/config/hipchat.yml:
bc.. token: "whoami
notify: true # Defaults to false
api_version: "v2" # optional, defaults to v2
color: "yellow"
h2. Engine Yard
Use a "deploy hook":http://bit.ly/qnbIkP to send messages from Engine Yard's Cloud platform.
RAILS_ROOT/deploy/after_restart.rb:
bc.. on_app_master do message = "Deploying revision #{config.active_revision} to #{config.environment_name}" message += " (with migrations)" if config.migrate? message += "."
run "cd #{config.release_path} && bundle exec rake hipchat:send MESSAGE='#{message}'" end
h2. Chef Handler
APIv1 ONLY, use APIv1 Key NOTE: APIv2 required for HipChat Server & HipChat Data Center
Report on Chef runs.
h3. Within a Recipe:
bc.. include_recipe 'chef_handler'
gem_package 'hipchat'
chef_handler 'HipChat::NotifyRoom' do action :enable arguments ['API_KEY', 'HIPCHAT_ROOM'] source File.join(Gem.all_load_paths.grep(/hipchat/).first, 'hipchat', 'chef.rb') end
h3. With client.rb:
bc.. require 'hipchat/chef' hipchat_handler = HipChat::NotifyRoom.new("API_KEY", "HIPCHAT_ROOM") exception_handlers << hipchat_handler
h3. With HipChat Data Center and HipChat Server
Add an "options" hash to set your URL:
h2. Copyright
Copyright (c) 2017 Atlassian. See LICENSE for details.