Class: HipChat::User
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- HipChat::User
- Includes:
- HTTParty, FileHelper
- Defined in:
- lib/hipchat/user.rb
Constant Summary
Constants included from FileHelper
Instance Method Summary collapse
-
#delete(params = {}) ⇒ Object
Get private message history.
-
#history(params = {}) ⇒ Object
Get private message history.
-
#initialize(token, params) ⇒ User
constructor
A new instance of User.
-
#rooms ⇒ Object
Getting all rooms details in which user is present.
-
#send(message, options = {}) ⇒ Object
Send a private message to user.
-
#send_file(message, file) ⇒ Object
Send a private file to user.
-
#update(options = {}) ⇒ Object
User update.
-
#view ⇒ Object
Get a user’s details.
Constructor Details
#initialize(token, params) ⇒ User
Returns a new instance of User.
12 13 14 15 16 17 |
# File 'lib/hipchat/user.rb', line 12 def initialize(token, params) @token = token @api = HipChat::ApiVersion::User.new(params) self.class.base_uri(@api.base_uri) super(params) end |
Instance Method Details
#delete(params = {}) ⇒ Object
Get private message history
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/hipchat/user.rb', line 84 def delete(params = {}) case @api.version when 'v1' response = self.class.post(@api.delete_config[:url], :query => { :auth_token => @token }.merge(params), :headers => @api.headers ) when 'v2' response = self.class.delete(@api.delete_config[:url], :query => { :auth_token => @token }, :headers => @api.headers ) end ErrorHandler.response_code_to_exception_for :user, user_id, response true end |
#history(params = {}) ⇒ Object
Get private message history
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/hipchat/user.rb', line 69 def history(params = {}) params.select! { |key, _value| @api.history_config[:allowed_params].include? key } response = self.class.get(@api.history_config[:url], :query => { :auth_token => @token }.merge(params), :headers => @api.headers ) ErrorHandler.response_code_to_exception_for :user, user_id, response response.body end |
#rooms ⇒ Object
Getting all rooms details in which user is present
157 158 159 160 161 162 163 164 |
# File 'lib/hipchat/user.rb', line 157 def rooms response = self.class.get(@api.user_joined_rooms_config[:url], :query => { :auth_token => @token }.merge(@api.user_joined_rooms_config[:query_params]), :headers => @api.headers ) ErrorHandler.response_code_to_exception_for :user, user_id, response User.new(@token, response.merge(:api_version => @api.version)) end |
#send(message, options = {}) ⇒ Object
Send a private message to user.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/hipchat/user.rb', line 22 def send(, = {}) = [:message_format] ? [:message_format] : 'text' notify = [:notify] ? [:notify] : false response = self.class.post(@api.send_config[:url], :query => { :auth_token => @token }, :body => { :message => , :message_format => , :notify => notify }.send(@api.send_config[:body_format]), :headers => @api.headers ) ErrorHandler.response_code_to_exception_for :user, user_id, response true end |
#send_file(message, file) ⇒ Object
Send a private file to user.
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/hipchat/user.rb', line 42 def send_file(, file) response = self.class.post(@api.send_file_config[:url], :query => { :auth_token => @token }, :body => file_body({ :message => }.send(@api.send_config[:body_format]), file), :headers => file_body_headers(@api.headers) ) ErrorHandler.response_code_to_exception_for :user, user_id, response true end |
#update(options = {}) ⇒ Object
User update. API: www.hipchat.com/docs/apiv2/method/update_user Request body name - REQUIRED - User’s full name. Valid length range: 1-50 roles - The list of roles for the user. For example “owner”, “administrator”, “user”, “delegated administrator” title - User’s title status - string may be null show - REQUIRED - string - the status to show for the user. Available options ‘away’, ‘chat’, ‘dnd’, ‘xa’ mention_name - REQUIRED - User’s @mention name without the @ is_group_admin - Whether or not this user is an administrator timezone - User’s timezone. Must be a supported timezone. Defaults to ‘UTC’ password - User’s password. If not provided, the existing password is kept email - REQUIRED - User’s email
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/hipchat/user.rb', line 116 def update( = {}) name = [:name] roles = [:roles] ? [:roles] : nil title = [:title] ? [:title] : nil status = [:status] ? [:status] : nil show = [:show] ? [:show] : nil mention_name = [:mention_name] is_group_admin = [:is_group_admin] ? [:is_group_admin] : nil timezone = [:timezone] ? [:timezone] : 'UTC' password = [:password] ? [:password] : nil email = [:email] #create body format body = { } response = self.class.put(@api.user_update_config[:url], :query => { :auth_token => @token }, :body => { :name => name, :presence => {:status=>status, :show=>show}, :mention_name => mention_name, :timezone => timezone, :email => email } .merge(title ? {:title =>title} : {}) .merge(password ? {:password => password} : {}) .merge(is_group_admin ? {:is_group_admin => is_group_admin} : {}) .merge(roles ? {:roles => roles} : {}) .send(@api.user_update_config[:body_format]), :headers => @api.headers ) ErrorHandler.response_code_to_exception_for :user, user_id, response end |
#view ⇒ Object
Get a user’s details.
56 57 58 59 60 61 62 63 64 |
# File 'lib/hipchat/user.rb', line 56 def view response = self.class.get(@api.view_config[:url], :query => { :auth_token => @token }.merge(@api.view_config[:query_params]), :headers => @api.headers ) ErrorHandler.response_code_to_exception_for :user, user_id, response User.new(@token, response.merge(:api_version => @api.version, :server_url => server_url)) end |