Sha256: 326c559462b6969c5b9e91e5539e217cc498882d242e0eec1ccb71558ff57737

Contents?: true

Size: 883 Bytes

Versions: 3

Compression:

Stored size: 883 Bytes

Contents

module Slack
  module Web
    module Api
      module Mixins
        module Channels
          #
          # This method returns a channel ID given a channel name.
          #
          # @option options [channel] :channel
          #   Channel to get ID for, prefixed with #.
          def channels_id(options = {})
            name = options[:channel]
            throw ArgumentError.new('Required arguments :channel missing') if name.nil?
            return { 'ok' => true, 'channel' => { 'id' => name } } unless name[0] == '#'
            channels_list.tap do |list|
              list['channels'].each do |channel|
                return { 'ok' => true, 'channel' => { 'id' => channel['id'] } } if channel['name'] == name[1..-1]
              end
            end
            fail Slack::Web::Api::Error, 'channel_not_found'
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
slack-ruby-client-bhe-0.5.5 lib/slack/web/api/mixins/channels.id.rb
slack-ruby-client-bhe-0.5.4 lib/slack/web/api/mixins/channels.id.rb
slack-ruby-client-0.5.4 lib/slack/web/api/mixins/channels.id.rb