Class: CodeBuildNotifier::SlackSender

Inherits:
Object
  • Object
show all
Defined in:
lib/codebuild-notifier/slack_sender.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ SlackSender

Returns a new instance of SlackSender.



25
26
27
# File 'lib/codebuild-notifier/slack_sender.rb', line 25

def initialize(config)
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



23
24
25
# File 'lib/codebuild-notifier/slack_sender.rb', line 23

def config
  @config
end

Instance Method Details

#send(message) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/codebuild-notifier/slack_sender.rb', line 29

def send(message)
  Slack.configure { |slack_config| slack_config.token = app_token }
  channel = message.additional_channel
  if channel
    channel = "##{channel}" unless /\A#/.match?(channel)
    post_message(message, channel)
  end

  message.recipients.each do |email|
    slack_user_id = find_slack_user(email)
    slack_user_id && post_message(message, slack_user_id)
  end
end