Skip to content

Commit

Permalink
HipChat: Add support for notify flag. Use HTTPS.
Browse files Browse the repository at this point in the history
  • Loading branch information
powdahound committed Feb 4, 2011
1 parent e38108a commit b5bab22
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
8 changes: 5 additions & 3 deletions docs/hipchat
Expand Up @@ -4,15 +4,17 @@ HipChat
Install Notes
-------------

1. Auth token - one of your group's API tokens. See: http://www.hipchat.com/docs/api/auth
2. Room - the full name of the room to send the message to. The room's room_id will also work.
1. Auth token - One of your group's API tokens. See: http://www.hipchat.com/docs/api/auth
2. Room - The full name of the room to send the message to. The room's room_id will also work.
3. Notify - Whether or not to notify room members.

Developer Notes
---------------

data
- auth_token
- room_id
- room
- notify (boolean)

payload
- refer to docs/github_payload
22 changes: 17 additions & 5 deletions services/hipchat.rb
@@ -1,15 +1,27 @@
service :hip_chat do |data, payload|
# make sure we have what we need
throw :halt, [400, "Missing auth_token"] if data['auth_token'].to_s == ''
throw :halt, [400, "Missing room"] if data['room'].to_s == ''
throw :halt, [400, "Missing 'auth_token'"] if data['auth_token'].to_s == ''
throw :halt, [400, "Missing 'room'"] if data['room'].to_s == ''

# send it
url = URI.parse("http://api.hipchat.com/v1/rooms/message_github")
Net::HTTP.post_form(url, {
req = Net::HTTP::Post.new("/v1/webhooks/github")
req.set_form_data({
:auth_token => data['auth_token'],
:room_id => data['room'],
:payload => JSON.generate(payload),
:notify => data['notify'] ? 1 : 0
})
req["Content-Type"] = 'application/x-www-form-urlencoded'

http = Net::HTTP.new("api.hipchat.com", 443)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
begin
http.start do |connection|
connection.request(req)
end
rescue Net::HTTPBadResponse
raise GitHub::ServiceConfigurationError, "Invalid configuration"
end

# Sinatra expects a string return
"Great success!"
Expand Down

0 comments on commit b5bab22

Please sign in to comment.