Class: Upcloudify::Notifiers::Slack

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

Instance Method Summary collapse

Constructor Details

#initialize(to: nil, url: nil) ⇒ Slack

Returns a new instance of Slack.



8
9
10
11
12
# File 'lib/notifiers/slack.rb', line 8

def initialize(to: nil, url: nil)
  raise ArgumentError "url cannot be nil" unless url
  @url = url
  @to = to
end

Instance Method Details

#notify(text: nil) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/notifiers/slack.rb', line 14

def notify(text: nil)
  HTTParty.post(
    @url,
    headers: {"Content-Type" => content_type},
    body: payload.merge(text: text).to_json
  )
end

#payloadObject



22
23
24
# File 'lib/notifiers/slack.rb', line 22

def payload
  { channel: @to }
end