Class: Ruboty::SlackTakeTurns::SlackClient
- Inherits:
-
Object
- Object
- Ruboty::SlackTakeTurns::SlackClient
- Defined in:
- lib/ruboty/slack_take_turns/slack_client.rb
Instance Attribute Summary collapse
-
#channel ⇒ Object
readonly
Returns the value of attribute channel.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #all_users ⇒ Object
-
#all_users_hash ⇒ Object
ユーザを取得しやすくするためにユーザIDとユーザオブジェクトのハッシュテーブルを作る.
-
#channel_user_ids ⇒ Object
チャンネル内の全ユーザid.
- #channels_info ⇒ Object
- #groups_list ⇒ Object
-
#initialize(channel) ⇒ SlackClient
constructor
A new instance of SlackClient.
- #private_channel? ⇒ Boolean
- #private_channel_user_ids ⇒ Object
- #public_channel_user_ids ⇒ Object
Constructor Details
#initialize(channel) ⇒ SlackClient
7 8 9 10 |
# File 'lib/ruboty/slack_take_turns/slack_client.rb', line 7 def initialize(channel) @client ||= Slack::Client.new(token: ENV['SLACK_TOKEN']) @channel = channel end |
Instance Attribute Details
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
5 6 7 |
# File 'lib/ruboty/slack_take_turns/slack_client.rb', line 5 def channel @channel end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
5 6 7 |
# File 'lib/ruboty/slack_take_turns/slack_client.rb', line 5 def client @client end |
Instance Method Details
#all_users ⇒ Object
12 13 14 |
# File 'lib/ruboty/slack_take_turns/slack_client.rb', line 12 def all_users @all_users ||= client.users_list['members'] end |
#all_users_hash ⇒ Object
ユーザを取得しやすくするためにユーザIDとユーザオブジェクトのハッシュテーブルを作る
17 18 19 20 21 |
# File 'lib/ruboty/slack_take_turns/slack_client.rb', line 17 def all_users_hash @all_users_hash ||= {}.tap do |h| all_users.each{|u| h[u['id']] = u} end end |
#channel_user_ids ⇒ Object
チャンネル内の全ユーザid
24 25 26 27 28 29 30 31 |
# File 'lib/ruboty/slack_take_turns/slack_client.rb', line 24 def channel_user_ids unless @channel_user_ids&.dig(channel) @channel_user_ids = {} unless @channel_user_ids ids = private_channel? ? private_channel_user_ids : public_channel_user_ids @channel_user_ids[channel] = ids.sort end @channel_user_ids[channel] end |
#channels_info ⇒ Object
33 34 35 |
# File 'lib/ruboty/slack_take_turns/slack_client.rb', line 33 def channels_info @channels_info ||= client.channels_info(channel: channel) end |
#groups_list ⇒ Object
47 48 49 |
# File 'lib/ruboty/slack_take_turns/slack_client.rb', line 47 def groups_list @groups_list ||= client.groups_list['groups'] end |
#private_channel? ⇒ Boolean
51 52 53 |
# File 'lib/ruboty/slack_take_turns/slack_client.rb', line 51 def private_channel? channels_info['error'] == "channel_not_found" end |
#private_channel_user_ids ⇒ Object
41 42 43 44 45 |
# File 'lib/ruboty/slack_take_turns/slack_client.rb', line 41 def private_channel_user_ids private_channels = groups_list current_channel = private_channels.find{|c| c['id'] == channel} current_channel['members'] end |
#public_channel_user_ids ⇒ Object
37 38 39 |
# File 'lib/ruboty/slack_take_turns/slack_client.rb', line 37 def public_channel_user_ids channels_info['channel']['members'] end |