Class: Miteru::Notifiers::Slack

Inherits:
Base
  • Object
show all
Defined in:
lib/miteru/notifiers/slack.rb

Instance Method Summary collapse

Instance Method Details

#notifiable?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/miteru/notifiers/slack.rb', line 24

def notifiable?
  Miteru.configuration.slack_webhook_url? && Miteru.configuration.post_to_slack?
end

#notify(website) ⇒ Object

Notifiy to Slack

Parameters:



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/miteru/notifiers/slack.rb', line 11

def notify(website)
  attachement = Attachement.new(website.url)
  kits = website.kits.select(&:downloaded?)

  if notifiable? && kits.any?
    notifier = Slack::Notifier.new(Miteru.configuration.slack_webhook_url, channel: Miteru.configuration.slack_channel)
    notifier.post(text: website.message.capitalize, attachments: attachement.to_a)
  end

  message = kits.any? ? website.message.colorize(:light_red) : website.message
  Miteru.logger.info "#{website.url}: #{message}"
end