Class: Notifier

Inherits:
Object
  • Object
show all
Defined in:
lib/notifier.rb

Instance Method Summary collapse

Constructor Details

#initialize(message) ⇒ Notifier

Returns a new instance of Notifier.



3
4
5
# File 'lib/notifier.rb', line 3

def initialize(message)
  @message = message
end

Instance Method Details

#notifierObject



7
8
9
10
11
# File 'lib/notifier.rb', line 7

def notifier
  @notifier ||= Slack::Notifier.new ENV['SLACK_WEBHOOK_URL']
  @notifier.username = "Ping My Site"
  @notifier
end

#performObject



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/notifier.rb', line 13

def perform
  unless $TESTING
    notification = notifier.ping(@message)
    
    if notification.response.code.to_i == 200
      puts "Successfully notified to Slack"
    else
      puts "Something went wrong when trying to notify Slack"
    end
  else
    return "Successfully notified to Slack"
  end
end