Module: Slack::Web::Api::Mixins::Users

Included in:
Endpoints
Defined in:
lib/slack/web/api/mixins/users.id.rb

Instance Method Summary collapse

Instance Method Details

#users_id(options = {}) ⇒ Object

This method returns a user ID given a user name.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :user (user)

    User to get ID for, prefixed with ‘@’.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/slack/web/api/mixins/users.id.rb', line 11

def users_id(options = {})
  name = options[:user]
  throw ArgumentError.new('Required arguments :user missing') if name.nil?
  return { 'ok' => true, 'user' => { 'id' => name } } unless name[0] == '@'
  users_list.tap do |list|
    list['members'].each do |user|
      return { 'ok' => true, 'user' => { 'id' => user['id'] } } if user['name'] == name[1..-1]
    end
  end
  fail Slack::Web::Api::Error, 'user_not_found'
end