# frozen_string_literal: true module Groundskeeper # Posts to the RADD #general channel. class Slack COMMAND = "curl" SLACK_WORKSPACE_KEY = "SLACK_WORKSPACE" SLACK_CHANNEL_KEY = "SLACK_CHANNEL" SLACK_TOKEN_KEY = "SLACK_TOKEN" URL = "https://hooks.slack.com/services/" \ "%s/%s/%s" SEND_MESSAGE = "-X POST -H 'Content-type: application/json' " \ "--data '{\"text\":\"%s\"}' #{URL}" attr_reader :slack def self.build new Executable.new(COMMAND) end def initialize(slack) @slack = slack end def send_message(message) slack.execute(format(SEND_MESSAGE, message: message, workspace: ENV[SLACK_WORKSPACE_KEY], channel: ENV[SLACK_CHANNEL_KEY], token: ENV[SLACK_TOKEN_KEY])) end def credentials? ENV[SLACK_WORKSPACE_KEY].present? && ENV[SLACK_CHANNEL_KEY].present? && ENV[SLACK_TOKEN_KEY].present? end end end