class SlackErrorNotifier::SlackConfiguration
Attributes
slack_token[R]
target_channel[R]
Public Class Methods
new()
click to toggle source
# File lib/slack_error_notifier/slack_configuration.rb, line 5 def initialize @slack_token = SlackErrorNotifier.access_token @target_channel = SlackErrorNotifier.target_channel configure_slack_client check_authentication check_target_channel_validity end
Public Instance Methods
slack_client()
click to toggle source
# File lib/slack_error_notifier/slack_configuration.rb, line 13 def slack_client @slack_client ||= Slack::Web::Client.new end
Private Instance Methods
channel_is_user?()
click to toggle source
# File lib/slack_error_notifier/slack_configuration.rb, line 28 def channel_is_user? target_channel.start_with?('@') end
check_authentication()
click to toggle source
# File lib/slack_error_notifier/slack_configuration.rb, line 19 def check_authentication slack_client.auth_test end
check_channel_exists()
click to toggle source
# File lib/slack_error_notifier/slack_configuration.rb, line 38 def check_channel_exists channels = slack_client.channels_list.channels channels.detect { |c| c.name == target_channel.gsub('#', '') } end
check_target_channel_validity()
click to toggle source
# File lib/slack_error_notifier/slack_configuration.rb, line 23 def check_target_channel_validity valid_channel = channel_is_user? ? check_user_exists : check_channel_exists raise ConfigurationError::InvalidChannel unless valid_channel end
check_user_exists()
click to toggle source
# File lib/slack_error_notifier/slack_configuration.rb, line 32 def check_user_exists slack_client.users_info(user: target_channel) rescue Slack::Web::Api::Error return false end
configure_slack_client()
click to toggle source
# File lib/slack_error_notifier/slack_configuration.rb, line 43 def configure_slack_client Slack.configure do |config| config.token = slack_token end end