Class: SlackbotFrd::SlackMethods::ChannelsList

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/slackbot_frd/slack_methods/channels_list.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token) ⇒ ChannelsList

Returns a new instance of ChannelsList.



12
13
14
# File 'lib/slackbot_frd/slack_methods/channels_list.rb', line 12

def initialize(token)
  @token = token
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



10
11
12
# File 'lib/slackbot_frd/slack_methods/channels_list.rb', line 10

def response
  @response
end

Instance Method Details

#connectObject



16
17
18
19
20
# File 'lib/slackbot_frd/slack_methods/channels_list.rb', line 16

def connect
  @response = JSON.parse(self.class.post('', :body => { token: @token } ).body)
  ValidateSlack.response(@response)
  self
end

#ids_to_namesObject



22
23
24
25
26
27
28
# File 'lib/slackbot_frd/slack_methods/channels_list.rb', line 22

def ids_to_names
  retval = {}
  @response['channels'].each do |channel|
    retval[channel['id']] = channel['name']
  end
  retval
end

#names_to_idsObject



30
31
32
33
34
35
36
# File 'lib/slackbot_frd/slack_methods/channels_list.rb', line 30

def names_to_ids
  retval = {}
  @response['channels'].each do |channel|
    retval[channel['name']] = channel['id']
  end
  retval
end