Class: HipChat::API
- Inherits:
-
Object
- Object
- HipChat::API
- Includes:
- HTTParty
- Defined in:
- lib/hipchat-api.rb,
lib/hipchat-api/version.rb
Constant Summary collapse
- DEFAULT_TIMEOUT =
Default timeout of 3 seconds
3
- DEFAULT_HEADERS =
Default headers for HTTP requests
{ 'User-Agent' => "HipChat gem #{VERSION}", }
- HIPCHAT_API_URL =
HipChat API URL
'https://api.hipchat.com/v1'
- VERSION =
'1.0.4'.freeze
Instance Attribute Summary collapse
-
#hipchat_api_url ⇒ Object
HipChat API URL.
-
#token ⇒ Object
HipChat access token.
Instance Method Summary collapse
-
#debug(location = $stderr) ⇒ Object
Turn on HTTParty debugging.
-
#initialize(token, hipchat_api_url = HIPCHAT_API_URL) ⇒ API
constructor
Create a new instance of the
HipChat::API
for interacting with HipChat. -
#rooms_create(name, owner_user_id, privacy = 'public', topic = '', guest_access = 0) ⇒ Object
Creates a new room.
-
#rooms_delete(room_id) ⇒ Object
Deletes a room and kicks the current participants.
-
#rooms_history(room_id, date, timezone) ⇒ Object
Fetch chat history for this room.
-
#rooms_list ⇒ Object
List rooms for this group.
-
#rooms_message(room_id, from, message, notify = 0, color = 'yellow', message_format = 'html') ⇒ Object
Send a message to a room.
-
#rooms_show(room_id) ⇒ Object
Get room details.
-
#set_http_headers(http_headers = {}) ⇒ Object
Set new HTTP headers for requests.
-
#set_timeout(timeout) ⇒ Object
Set new HTTP timeout for requests.
-
#users_create(email, name, title, is_group_admin = 0, password = nil, timezone = 'UTC') ⇒ Object
Create a new user in your group.
-
#users_delete(user_id) ⇒ Object
Delete a user.
-
#users_list ⇒ Object
List all users in the group.
-
#users_show(user_id) ⇒ Object
Get a user’s details.
-
#users_update(user_id, email = nil, name = nil, title = nil, is_group_admin = nil, password = nil, timezone = nil) ⇒ Object
Update a user.
Constructor Details
#initialize(token, hipchat_api_url = HIPCHAT_API_URL) ⇒ API
Create a new instance of the HipChat::API
for interacting with HipChat
33 34 35 36 |
# File 'lib/hipchat-api.rb', line 33 def initialize(token, hipchat_api_url = HIPCHAT_API_URL) @token = token @hipchat_api_url = hipchat_api_url end |
Instance Attribute Details
#hipchat_api_url ⇒ Object
HipChat API URL
24 25 26 |
# File 'lib/hipchat-api.rb', line 24 def hipchat_api_url @hipchat_api_url end |
#token ⇒ Object
HipChat access token
27 28 29 |
# File 'lib/hipchat-api.rb', line 27 def token @token end |
Instance Method Details
#debug(location = $stderr) ⇒ Object
Turn on HTTParty debugging
41 42 43 |
# File 'lib/hipchat-api.rb', line 41 def debug(location = $stderr) self.class.debug_output(location) end |
#rooms_create(name, owner_user_id, privacy = 'public', topic = '', guest_access = 0) ⇒ Object
Creates a new room.
69 70 71 72 |
# File 'lib/hipchat-api.rb', line 69 def rooms_create(name, owner_user_id, privacy = 'public', topic = '', guest_access = 0) self.class.post(hipchat_api_url_for('rooms/create'), :body => {:auth_token => @token, :name => name, :owner_user_id => owner_user_id, :topic => topic, :privacy => privacy, :guest_access => guest_access}) end |
#rooms_delete(room_id) ⇒ Object
Deletes a room and kicks the current participants.
79 80 81 |
# File 'lib/hipchat-api.rb', line 79 def rooms_delete(room_id) self.class.post(hipchat_api_url_for('rooms/delete'), :body => {:auth_token => @token, :room_id => room_id}) end |
#rooms_history(room_id, date, timezone) ⇒ Object
Fetch chat history for this room.
90 91 92 93 |
# File 'lib/hipchat-api.rb', line 90 def rooms_history(room_id, date, timezone) self.class.get(hipchat_api_url_for('rooms/history'), :query => {:auth_token => @token, :room_id => room_id, :date => date, :timezone => timezone}) end |
#rooms_list ⇒ Object
List rooms for this group.
98 99 100 |
# File 'lib/hipchat-api.rb', line 98 def rooms_list self.class.get(hipchat_api_url_for('rooms/list'), :query => {:auth_token => @token}) end |
#rooms_message(room_id, from, message, notify = 0, color = 'yellow', message_format = 'html') ⇒ Object
Send a message to a room.
111 112 113 114 |
# File 'lib/hipchat-api.rb', line 111 def (room_id, from, , notify = 0, color = 'yellow', = 'html') self.class.post(hipchat_api_url_for('rooms/message'), :body => {:auth_token => @token, :room_id => room_id, :from => from, :message => , :notify => notify, :color => color, :message_format => }) end |
#rooms_show(room_id) ⇒ Object
Get room details.
121 122 123 |
# File 'lib/hipchat-api.rb', line 121 def rooms_show(room_id) self.class.get(hipchat_api_url_for('rooms/show'), :query => {:auth_token => @token, :room_id => room_id}) end |
#set_http_headers(http_headers = {}) ⇒ Object
Set new HTTP headers for requests
48 49 50 51 |
# File 'lib/hipchat-api.rb', line 48 def set_http_headers(http_headers = {}) http_headers.merge!(DEFAULT_HEADERS) self.class.headers(http_headers) end |
#set_timeout(timeout) ⇒ Object
Set new HTTP timeout for requests
56 57 58 |
# File 'lib/hipchat-api.rb', line 56 def set_timeout(timeout) self.class.default_timeout(timeout) end |
#users_create(email, name, title, is_group_admin = 0, password = nil, timezone = 'UTC') ⇒ Object
Create a new user in your group.
135 136 137 138 |
# File 'lib/hipchat-api.rb', line 135 def users_create(email, name, title, is_group_admin = 0, password = nil, timezone = 'UTC') self.class.post(hipchat_api_url_for('users/create'), :body => {:auth_token => @token, :email => email, :name => name, :title => title, :is_group_admin => is_group_admin, :password => password, :timezone => timezone}.reject{|key, value| value.nil?}) end |
#users_delete(user_id) ⇒ Object
Delete a user.
145 146 147 |
# File 'lib/hipchat-api.rb', line 145 def users_delete(user_id) self.class.post(hipchat_api_url_for('users/delete'), :body => {:auth_token => @token, :user_id => user_id}) end |
#users_list ⇒ Object
List all users in the group.
152 153 154 |
# File 'lib/hipchat-api.rb', line 152 def users_list self.class.get(hipchat_api_url_for('users/list'), :query => {:auth_token => @token}) end |
#users_show(user_id) ⇒ Object
Get a user’s details.
161 162 163 |
# File 'lib/hipchat-api.rb', line 161 def users_show(user_id) self.class.get(hipchat_api_url_for('users/show'), :query => {:auth_token => @token, :user_id => user_id}) end |
#users_update(user_id, email = nil, name = nil, title = nil, is_group_admin = nil, password = nil, timezone = nil) ⇒ Object
Update a user.
175 176 177 178 |
# File 'lib/hipchat-api.rb', line 175 def users_update(user_id, email = nil, name = nil, title = nil, is_group_admin = nil, password = nil, timezone = nil) self.class.post(hipchat_api_url_for('users/update'), :body => {:auth_token => @token, :user_id => user_id, :email => email, :name => name, :title => title, :is_group_admin => is_group_admin, :password => password, :timezone => timezone}.reject{|key, value| value.nil?}) end |