Sha256: 4130bcea662fd2c68a164aee6d2a63c49868ca6f14471ea5650b40ee61bf8858

Contents?: true

Size: 1.36 KB

Versions: 16

Compression:

Stored size: 1.36 KB

Contents

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 if defined?(Picky)

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
slack-ruby-client-0.10.0 lib/slack/web/api/mixins/users.search.rb
slack-ruby-client-0.9.1 lib/slack/web/api/mixins/users.search.rb
slack-ruby-client-0.9.0 lib/slack/web/api/mixins/users.search.rb
slack-ruby-client-0.8.1 lib/slack/web/api/mixins/users.search.rb
slack-ruby-client-0.8.0 lib/slack/web/api/mixins/users.search.rb
slack-ruby-client-0.7.9 lib/slack/web/api/mixins/users.search.rb
slack-ruby-client-0.7.8 lib/slack/web/api/mixins/users.search.rb
slack-ruby-client-0.7.7 lib/slack/web/api/mixins/users.search.rb
slack-ruby-client-0.7.6 lib/slack/web/api/mixins/users.search.rb
slack-ruby-client-0.7.5 lib/slack/web/api/mixins/users.search.rb
slack-ruby-client-0.7.4 lib/slack/web/api/mixins/users.search.rb
slack-ruby-client-0.7.3 lib/slack/web/api/mixins/users.search.rb
slack-ruby-client-0.7.2 lib/slack/web/api/mixins/users.search.rb
slack-ruby-client-0.7.1 lib/slack/web/api/mixins/users.search.rb
slack-ruby-client-0.7.0 lib/slack/web/api/mixins/users.search.rb
slack-ruby-client-0.6.0 lib/slack/web/api/mixins/users.search.rb