lib/slacked/slack_post.rb in slacked-0.7.0 vs lib/slacked/slack_post.rb in slacked-0.8.0
- old
+ new
@@ -1,9 +1,29 @@
module Slacked
+ SLACK_PROFILE_IMAGE=':robot_face:'
+ SLACK_WEBHOOK_URL_KEY='SLACK_WEBHOOK'
+ SLACK_DEFAULT_MESSAGE_KEY='SLACK_DEFAULT_MESSAGE'
+ SLACK_CONFIG= {
+ icon_emoji: SLACK_PROFILE_IMAGE
+ }
+
class << self
+ def post message = ENV[SLACK_DEFAULT_MESSAGE_KEY]
+ return false if message.nil? || message.empty?
+ notifier = slack_notifier
+ notifier.ping message, SLACK_CONFIG
+ end
- def post message = ENV["SLACK_MESSAGE"]
- send = Slack::Notifier.new ENV["SLACK_WEBHOOK"]
- send.ping message, icon_emoji: ":ghost:"
- end
+ def post_async message
+ Thread.start do
+ result = post(message)
+ defined?(ActiveRecord) ? ActiveRecord::Base.connection.close : nil
+ result
+ end
+ end
+
+ private
+ def slack_notifier webhook_url = ENV[SLACK_WEBHOOK_URL_KEY]
+ Slack::Notifier.new webhook_url
+ end
end
end