Sha256: 6669bbfc1130bc116096b0253b608479c4fc1825e2a2739c08fa71f614a069d3

Contents?: true

Size: 853 Bytes

Versions: 12

Compression:

Stored size: 853 Bytes

Contents

module Slack
  module Web
    module Api
      module Mixins
        module Users
          #
          # This method returns a user ID given a user name.
          #
          # @option options [user] :user
          #   User to get ID for, prefixed with '@'.
          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 Slack::Messages::Message.new('ok' => true, 'user' => { 'id' => user.id }) if user.name == name[1..-1]
              end
            end
            fail Slack::Web::Api::Error, 'user_not_found'
          end
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

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