Class: HipChat::Room
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- HipChat::Room
- Includes:
- HTTParty
- Defined in:
- lib/hipchat.rb
Instance Method Summary collapse
-
#initialize(token, params) ⇒ Room
constructor
A new instance of Room.
-
#send(from, message, options_or_notify = {}) ⇒ Object
Send a message to this room.
Constructor Details
#initialize(token, params) ⇒ Room
Returns a new instance of Room.
36 37 38 39 40 |
# File 'lib/hipchat.rb', line 36 def initialize(token, params) @token = token super(params) end |
Instance Method Details
#send(from, message, options_or_notify = {}) ⇒ Object
Send a message to this room.
Usage:
# Default
send 'nickname', 'some message'
# Notify users and color the message red
send 'nickname', 'some message', :notify => true, :color => 'red'
# Notify users (deprecated)
send 'nickname', 'some message', true
Options:
color
-
“yellow”, “red”, “green”, “purple”, or “random” (default “yellow”)
notify
-
true or false (default false)
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/hipchat.rb', line 61 def send(from, , = {}) = if == true or == false warn "DEPRECATED: Specify notify flag as an option (e.g., :notify => true)" { :notify => } else || {} end = { :color => 'yellow', :notify => false }.merge response = self.class.post('/message', :query => { :auth_token => @token }, :body => { :room_id => room_id, :from => from, :message => , :color => [:color], :notify => [: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}'" end end |