Class: Komonjo::Connection::SlackConnection
- Inherits:
-
Object
- Object
- Komonjo::Connection::SlackConnection
- Defined in:
- lib/komonjo/connections/slack_connection.rb
Overview
Connection for slack
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #auth_test ⇒ Object
- #channels_history(opts) ⇒ Object
- #channels_list ⇒ Object
-
#emoji_list(opts = {}) ⇒ Object
returns an object, whose key is emoji-name and whose value is url.
-
#initialize(api_token) ⇒ SlackConnection
constructor
A new instance of SlackConnection.
- #users_info(user_id) ⇒ Object
- #users_list ⇒ Object
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
#client ⇒ Object (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_test ⇒ Object
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_list ⇒ Object
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_list ⇒ Object
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 |