Sha256: 13afaa01b50d44ec08b2805ff84ebe8a557affd9744a052ac719a067a490de81

Contents?: true

Size: 1.48 KB

Versions: 8

Compression:

Stored size: 1.48 KB

Contents

# frozen_string_literal: true
if defined?(Picky)
  module Slack
    module Web
      module Api
        module Mixins
          module Users
            Member = Struct.new :id, :name, :first_name, :last_name, :real_name, :email

            #
            # This method searches for users.
            #
            # @option options [user] :user
            #   Free-formed text to search for.
            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
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
slack-ruby-client-1.1.0 lib/slack/web/api/mixins/users.search.rb
slack-ruby-client-1.0.0 lib/slack/web/api/mixins/users.search.rb
slack-ruby-client-0.17.0 lib/slack/web/api/mixins/users.search.rb
slack-ruby-client-0.16.0 lib/slack/web/api/mixins/users.search.rb
slack-ruby-client-0.15.1 lib/slack/web/api/mixins/users.search.rb
slack-ruby-client-0.15.0 lib/slack/web/api/mixins/users.search.rb
slack-ruby-client-0.14.6 lib/slack/web/api/mixins/users.search.rb
slack-ruby-client-0.14.5 lib/slack/web/api/mixins/users.search.rb