Class: MicrosoftTeams::Notifier

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

Instance Method Summary collapse

Constructor Details

#initialize(webhook) ⇒ Notifier

Returns a new instance of Notifier.



5
6
7
8
# File 'lib/microsoft_teams/notifier.rb', line 5

def initialize(webhook)
  @webhook = webhook
  @header = { 'Content-type' => 'application/json' }
end

Instance Method Details

#ping(options = {}) ⇒ Object



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

def ping(options = {})
  result = false

  begin
    response = Gitlab::HTTP.post(
      @webhook.to_str,
      headers: @header,
      body: body(**options)
    )

    result = true if response
  rescue Gitlab::HTTP::Error, StandardError => error
    Gitlab::AppLogger.info("#{self.class.name}: Error while connecting to #{@webhook}: #{error.message}")
  end

  result
end