Class: HipChat::Room
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- HipChat::Room
- Includes:
- HTTParty
- Defined in:
- lib/hipchat-chef.rb
Instance Method Summary collapse
-
#history(options = {}) ⇒ Object
Pull this room’s history.
-
#initialize(token, params) ⇒ Room
constructor
A new instance of Room.
-
#send(from, message, options_or_notify = {}) ⇒ Object
Send a message to this room.
-
#topic(new_topic, options = {}) ⇒ Object
Change this room’s topic.
Constructor Details
#initialize(token, params) ⇒ Room
Returns a new instance of Room.
51 52 53 54 55 |
# File 'lib/hipchat-chef.rb', line 51 def initialize(token, params) @token = token super(params) end |
Instance Method Details
#history(options = {}) ⇒ Object
Pull this room’s history
Usage
# Default
Options
date-
Whether to return a specific day (YYYY-MM-DD format) or recent
(default "recent") timezone-
Your timezone. Supported timezones are at: www.hipchat.com/docs/api/timezones
(default "UTC") format-
Format to retrieve the history in. Valid options are JSON and XML
(default "JSON")
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/hipchat-chef.rb', line 162 def history( = {}) = { :date => 'recent', :timezone => 'UTC', :format => 'JSON' }.merge response = self.class.get('/history', :query => { :room_id => room_id, :date => [:date], :timezone => [:timezone], :format => [:format], :auth_token => @token, } ) case response.code when 200 response.body when 404 raise UnknownRoom, "Unknown room: `#{room_id}'" when 401 raise , "Access denied to room `#{room_id}'" else raise UnknownResponseCode, "Unexpected #{response.code} for room `#{room_id}'" end end |
#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)
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/hipchat-chef.rb', line 76 def send(from, , = {}) if from.length > 15 raise UsernameTooLong, "Username #{from} is `#{from.length} characters long. Limit is 15'" end = 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 => , :message_format => [:message_format] || 'html', :color => [:color], :notify => [:notify] ? 1 : 0 } ) case response.code when 200; true when 404 raise UnknownRoom, "Unknown room: `#{room_id}'" when 401 raise , "Access denied to room `#{room_id}'" else raise UnknownResponseCode, "Unexpected #{response.code} for room `#{room_id}'" end end |
#topic(new_topic, options = {}) ⇒ Object
Change this room’s topic
Usage:
# Default
topic 'my awesome topic'
Options:
from-
the name of the person changing the topic
(default "API")
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/hipchat-chef.rb', line 123 def topic(new_topic, = {}) = { :from => 'API' }.merge response = self.class.post('/topic', :query => { :auth_token => @token }, :body => { :room_id => room_id, :from => [:from], :topic => new_topic } ) case response.code when 200; true when 404 raise UnknownRoom, "Unknown room: `#{room_id}'" when 401 raise , "Access denied to room `#{room_id}'" else raise UnknownResponseCode, "Unexpected #{response.code} for room `#{room_id}'" end end |