Browse files

Cleaning up language in README, comments and cleaning up code format

  • Loading branch information...
1 parent e731ed5 commit 793d600c715c24ce8fd0fe60abda800d59ba1e00 @avand avand committed Oct 19, 2011
Showing with 36 additions and 33 deletions.
  1. +2 −5 README.textile
  2. +34 −28 lib/hipchat.rb
View
7 README.textile
@@ -7,15 +7,12 @@ h2. Usage
bc.. client = HipChat::Client.new(api_token)
client['my room'].send('username', 'I talk')
-# Lets hipchat send notifications to users (default false)
+# 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"
+# Color it red. or "yellow", "green", "purple", "random" (default "yellow")
client['my room'].send('username', 'Build failed!', :color => 'red')
-# Legacy mode, notifies users but you can't change colors :)
-client['my room'].send('username', 'I quit!', true)
-
h2. Capistrano
bc.. require 'hipchat/capistrano'
View
62 lib/hipchat.rb
@@ -43,44 +43,50 @@ def initialize(token, params)
#
# Usage:
#
- # send 'nickname', 'some message'
- # # => posts without notifying users and with default color (yellow)
- #
+ # # Default
+ # send 'nickname', 'some message'
+ #
+ # # Notify users and color the message red
# send 'nickname', 'some message', :notify => true, :color => 'red'
- # # => Posts notifying users and with color red
#
- # Available options currently only are :color ("yellow", "red", "green", "purple", or "random") and
- # notify (true or false).
+ # # Notify users (deprecated)
+ # send 'nickname', 'some message', true
+ #
+ # Options:
#
+ # +color+:: "yellow", "red", "green", "purple", or "random"
+ # (default "yellow")
+ # +notify+:: true or false
+ # (default false)
def send(from, message, options_or_notify = false)
- # The api used to only allow the notify users option, but other things like color should be
- # available as parameters too.
- if options_or_notify == true or options_or_notify == false
- # warn "DEPRECATED: notify boolean flag has been replaced with room.send(nick, msg, :notify => true/false). Please update your code accordingly!"
- options = {:notify => options_or_notify }
+ options = if options_or_notify == true or options_or_notify == false
+ warn "DEPRECATED: Specify notify flag as an option (e.g., :notify => true)"
+ { :notify => options_or_notify }
else
- # Make sure options are available as a hash at this stage, either from a hash given
- # as argument or by initializing
- options = options_or_notify || {}
+ options_or_notify || {}
end
- # Merge in default options
- options = {:color => 'yellow', :notify => false}.merge(options)
-
+
+ options = { :color => 'yellow', :notify => false }.merge options
+
response = self.class.post('/message',
- :query => { :auth_token => @token },
- :body => {:room_id => room_id,
- :from => from,
- :message => message,
- :color => options[:color],
- :notify => options[:notify] ? 1 : 0})
+ :query => { :auth_token => @token },
+ :body => {
+ :room_id => room_id,
+ :from => from,
+ :message => message,
+ :color => options[:color],
+ :notify => options[:notify] ? 1 : 0
+ }
+ )
case response.code
when 200; true
- when 404; raise UnknownRoom, "Unknown room: `#{room_id}'"
- when 401; raise Unauthorized, "Access denied to room `#{room_id}'"
- else raise UnknownResponseCode, "Unexpected #{response.code} for " <<
- "room `#{room_id}'"
-
+ when 404
+ raise UnknownRoom, "Unknown room: `#{room_id}'"
+ when 401
+ raise Unauthorized, "Access denied to room `#{room_id}'"
+ else
+ raise UnknownResponseCode, "Unexpected #{response.code} for room `#{room_id}'"
end
end
end

0 comments on commit 793d600

Please sign in to comment.