# 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}".freeze 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.fetch(SLACK_WORKSPACE_KEY, nil), channel: ENV.fetch(SLACK_CHANNEL_KEY, nil), token: ENV.fetch(SLACK_TOKEN_KEY, nil))) end def credentials? !ENV.fetch(SLACK_WORKSPACE_KEY, "").empty? && !ENV.fetch(SLACK_CHANNEL_KEY, "").empty? && !ENV.fetch(SLACK_TOKEN_KEY, "").empty? end end end