class Komonjo::Connection::SlackConnection

Connection for slack

Attributes

client[R]

Public Class Methods

new(api_token) click to toggle source
# File lib/komonjo/connections/slack_connection.rb, line 8
def initialize(api_token)
  @client = Slack::Client.new(token: api_token)
end

Public Instance Methods

auth_test() click to toggle source
# File lib/komonjo/connections/slack_connection.rb, line 42
def auth_test
  ret = client.auth_test
  ret['ok']
end
channels_history(opts) click to toggle source
# File lib/komonjo/connections/slack_connection.rb, line 12
def channels_history(opts)
  channel_name = opts.delete(:channel_name)
  unless opts[:channel]
    channel_name[0] = '' if channel_name[0] == '#'
    channel_id = channel_id channel_name
    opts[:channel] = channel_id
  end
  ret = client.channels_history(opts)
  raise 'error' unless ret['ok']
  ret['messages']
end
channels_list() click to toggle source
# File lib/komonjo/connections/slack_connection.rb, line 36
def channels_list
  ret = client.channels_list
  raise 'error' unless ret['ok']
  ret['channels']
end
emoji_list(opts = {}) click to toggle source

returns an object, whose key is emoji-name and whose value is url.

# File lib/komonjo/connections/slack_connection.rb, line 50
def emoji_list(opts = {})
  ret = client.emoji_list
  raise 'error' unless ret['ok']
  ret['emoji']
end
users_info(user_id) click to toggle source
# File lib/komonjo/connections/slack_connection.rb, line 24
def users_info(user_id)
  ret = client.users_info(user: user_id)
  raise 'error' unless ret['ok']
  ret['user']
end
users_list() click to toggle source
# File lib/komonjo/connections/slack_connection.rb, line 30
def users_list
  ret = client.users_list
  raise 'error' unless ret['ok']
  ret['members']
end

Private Instance Methods

channel_id(channel_name) click to toggle source
# File lib/komonjo/connections/slack_connection.rb, line 58
def channel_id(channel_name)
  channel_list = client.channels_list
  raise 'error' unless channel_list['ok']
  target_channel = channel_list['channels'].select do |e|
    e['name'] == channel_name
  end
  raise "unknown channel name: #{channel_name}" if target_channel.empty?
  target_channel.first['id']
end