Class: Slack::Mail::Perform

Inherits:
Object
  • Object
show all
Defined in:
lib/slack/mail/delivery.rb

Instance Method Summary collapse

Constructor Details

#initialize(webhook_url:) ⇒ Perform

Returns a new instance of Perform.



10
11
12
# File 'lib/slack/mail/delivery.rb', line 10

def initialize webhook_url:
  @notifier = Slack::Notifier.new webhook_url
end

Instance Method Details

#deliver(message) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/slack/mail/delivery.rb', line 14

def deliver message
  opts = message.to_h.reject { |_,v| v.nil? }
  text = opts.delete(:text) || " "

  response = @notifier.ping text, opts
  unless response.code == "200"
    raise DeliveryFailure, "Failed to reach #{@notifier.endpoint} (#{response.code})"
  end
  true
end