Class: SidekiqVigil::Notifier::Webhook

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

Instance Attribute Summary

Attributes inherited from Base

#logger, #options

Instance Method Summary collapse

Methods inherited from Base

#inspect

Constructor Details

#initialize(options: {}, logger: SidekiqVigil.logger, transport: HttpTransport.new) ⇒ Webhook

Returns a new instance of Webhook.



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

def initialize(options: {}, logger: SidekiqVigil.logger, transport: HttpTransport.new)
  super(options:, logger:)
  @transport = transport
end

Instance Method Details

#notify(event) ⇒ Object

Raises:



13
14
15
16
17
18
# File 'lib/sidekiq_vigil/notifier/webhook.rb', line 13

def notify(event)
  response = transport.post(options.fetch(:url), JSON.generate(event.to_h), headers: options.fetch(:headers, {}))
  raise Error, "webhook returned HTTP #{response.code}" unless response.success?

  true
end