Code Monkey home page Code Monkey logo

hipchat-rb's Introduction

HipChat Wrapper

A very basic wrapper for the HipChat HTTP API.

CI Status


Coverage Status

Requirements

  • Ruby 1.9.3 or higher
  • HipChat Account, sign up here!

Usage

client = HipChat::Client.new(api_token)
# 'username' is the name for which the message will be presented as from
client['my room'].send('username', 'I talk')

# Send notifications to users (default false)
client['my room'].send('username', 'I quit!', :notify => 1)

# Color it red. or "yellow", "green", "purple", "random" (default "yellow")
client['my room'].send('username', 'Build failed!', :color => 'red')

# Have your message rendered as text in HipChat (see https://www.hipchat.com/docs/api/method/rooms/message)
client['my room'].send('username', '@coworker Build faild!', :message_format => 'text')

# Update the topic of a room in HipChat (see https://www.hipchat.com/docs/api/method/rooms/topic)
client['my room'].topic('Free Ice Cream in the kitchen')

# Change the from field for a topic update (default "API")
client['my room'].topic('Weekely sales: $10,000', :from => 'Sales Team')

# Get history from a room
client['my room'].history()

# Get history for a date in time with a particular timezone (default is latest 75 messages, timezone default is 'UTC')
client['my room'].history(:date => '2010-11-19', :timezone => 'PST')
client = HipChat::Client.new(api_token, :api_version => 'v2')
# 'username' is the name for which the message will be presented as from
client['my room'].send('username', 'I talk')

# Send notifications to users (default false)
client['my room'].send('username', 'I quit!', :notify => true)

# Color it red. or "yellow", "green", "purple", "random" (default "yellow")
client['my room'].send('username', 'Build failed!', :color => 'red')

# Have your message rendered as text in HipChat (see https://www.hipchat.com/docs/apiv2/method/send_room_notification)
client['my room'].send('username', '@coworker Build faild!', :message_format => 'text')

# Update the topic of a room in HipChat (see https://www.hipchat.com/docs/apiv2/method/set_topic)
client['my room'].topic('Free Ice Cream in the kitchen')

# Change the from field for a topic update (default "API")
client['my room'].topic('Weekely sales: $10,000', :from => 'Sales Team')

# Get history from a room
client['my room'].history()

# Get history for a date in time with a particular timezone (default is latest 75 messages, timezone default is 'UTC')
client['my room'].history(:date => '2010-11-19', :timezone => 'PST')

# Create a new room
client.create_room("Name")

# Get room data
client['my room'].get_room

# Invite user to room
client['my room'].invite("USER_ID_OR_NAME")

Capistrano

APIv1 ONLY, use APIv1 Key

Capfile

require 'hipchat/capistrano'

deploy.rb

# Required
set :hipchat_token, "<your token>"
set :hipchat_room_name, "Your room" # If you pass an array such as ["room_a", "room_b"] you can send announcements to multiple rooms.
# Optional
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

Who did it?

To determine the user that is currently running the deploy, the capistrano tasks will look for the following:

  1. The $HIPCHAT_USER environment variable
  2. The hipchat_human capistrano var.
  3. The git user.name var.
  4. The $USER environment variable.

Rails 3 Rake Task

Send a message using a rake task:

rake hipchat:send["hello world"]

or

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:

token: "<your token>"
room: "Your room"
user: "Your name" # Default to `whoami`
notify: true # Defaults to false
api_version: "v2" # optional, defaults to v1

Engine Yard

Use a deploy hook to send messages from Engine Yard’s Cloud platform.

RAILS_ROOT/deploy/after_restart.rb:

on_app_master do
  message  = "Deploying revision #{revision[0...6]} to #{node[:environment][:name]}"
  message += " (with migrations)" if migrate?
  message += "."

  # Send a message via rake task assuming a hipchat.yml in your config like above
  run "cd #{release_path} && bundle exec rake hipchat:send MESSAGE='#{message}'"
end

Chef Handler

APIv1 ONLY, use APIv1 Key

Report on Chef runs. Within a Recipe:

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

Copyright

Copyright © 2012 Atlassian. See LICENSE for details.

hipchat-rb's People

Contributors

ampledata avatar arkadyan avatar avand avatar clauswitt avatar colszowka avatar cpjolicoeur avatar czarneckid avatar danlo avatar darrinholst avatar david avatar daviddufresne avatar ismaelga avatar javiertoledo avatar jlambert121 avatar joncrawford avatar justintarthur avatar kmwhite avatar ktdreyer avatar levi avatar madsheep avatar michaelbiven avatar motns avatar mrchucho avatar nogara avatar powdahound avatar rbroemeling avatar rodrigopinto avatar sanemat avatar scalp42 avatar zsiddique avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.