Created
April 25, 2017 13:54
-
-
Save neilmarion/3aaeb0cfa812c12763fb50e71ca78ff1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module HealthCheck | |
class SlackNotification | |
attr_accessor :health_check | |
def initialize(health_check) | |
@health_check = health_check | |
end | |
def send | |
if beyond_threshold? && activated? && !Rails.env.development? | |
HTTParty.post(webhook_url, | |
headers: {'Content-Type' => 'application/json'}, | |
body: request_body.to_json, | |
) | |
end | |
end | |
private | |
def request_body | |
{ | |
username: "g5dashboard", | |
text: health_check.display_item_list, | |
icon_emoji: ":white_check_mark:", | |
channel: health_check.slack_channel, | |
} | |
end | |
def beyond_threshold? | |
health_check.beyond_threshold? | |
end | |
def activated? | |
health_check.activated? | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment