class HipChat::User

Public Class Methods

new(token, params) click to toggle source
Calls superclass method
# 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

Public Instance Methods

delete(params = {}) click to toggle source

Get private message history

# File lib/hipchat/user.rb, line 82
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 = {}) click to toggle source

Get private message history

# File lib/hipchat/user.rb, line 67
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
send(message, message_format='text', notify=false) click to toggle source

Send a private message to user.

# File lib/hipchat/user.rb, line 22
def send(message, message_format='text', notify=false)
  response = self.class.post(@api.send_config[:url],
                             :query => { :auth_token => @token },
                             :body => {
                                 :message => message,
                                 :message_format => 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) click to toggle source

Send a private file to user.

# File lib/hipchat/user.rb, line 40
def send_file(message, file)
  response = self.class.post(@api.send_file_config[:url],
    :query => { :auth_token => @token },
    :body => file_body({ :message => 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
view() click to toggle source

Get a user's details.

# File lib/hipchat/user.rb, line 54
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))
end