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

Includes:
Ids
Included in:
Endpoints
Defined in:
lib/slack/web/api/mixins/users.id.rb,
lib/slack/web/api/mixins/users.search.rb

Defined Under Namespace

Classes: Member

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 ‘@’.



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

def users_id(options = {})
  name = options[:user]
  throw ArgumentError.new('Required arguments :user missing') if name.nil?

  id_for(:user, name, '@', :members, 'user_not_found') do
    users_list
  end
end

#users_search(options = {}) ⇒ Object

This method searches for users.

Parameters:

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

    a customizable set of options

Options Hash (options):

  • :user (user)

    Free-formed text to search for.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/slack/web/api/mixins/users.search.rb', line 14

def users_search(options = {})
  query = options[:user]
  throw ArgumentError.new('Required arguments :user missing') if query.nil?
  index = Picky::Index.new(:users) do
    category :name
    category :first_name
    category :last_name
    category :real_name
    category :email
  end
  members = users_list.members
  members.each_with_index do |member, id|
    user = Member.new(
      id,
      member.name,
      member.profile.first_name,
      member.profile.last_name,
      member.profile.real_name,
      member.profile.email
    )
    index.add(user)
  end
  ids = Picky::Search.new(index).search(query, 5, 0, unique: true).ids
  results = ids.map { |id| members[id] }
  Slack::Messages::Message.new('ok' => true, 'members' => results)
end