Class: Komonjo::Connection::SlackConnection

Inherits:
Object
  • Object
show all
Defined in:
lib/komonjo/connections/slack_connection.rb

Overview

Connection for slack

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_token) ⇒ SlackConnection

Returns a new instance of SlackConnection.



8
9
10
# File 'lib/komonjo/connections/slack_connection.rb', line 8

def initialize(api_token)
  @client = Slack::Client.new(token: api_token)
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



7
8
9
# File 'lib/komonjo/connections/slack_connection.rb', line 7

def client
  @client
end

Instance Method Details

#auth_testObject



42
43
44
45
# File 'lib/komonjo/connections/slack_connection.rb', line 42

def auth_test
  ret = client.auth_test
  ret['ok']
end

#channels_history(opts) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# 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_listObject



36
37
38
39
40
# 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 = {}) ⇒ Object

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



50
51
52
53
54
# 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) ⇒ Object



24
25
26
27
28
# 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_listObject



30
31
32
33
34
# File 'lib/komonjo/connections/slack_connection.rb', line 30

def users_list
  ret = client.users_list
  raise 'error' unless ret['ok']
  ret['members']
end