Class: QueryTrack::Notifications::Slack

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code, duration) ⇒ Slack

Returns a new instance of Slack.



6
7
8
9
10
# File 'lib/query_track/notifications/slack.rb', line 6

def initialize(code, duration)
  @code = code.strip
  @duration = duration
  @webhook_url = QueryTrack::Settings.config.notifications.slack
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



4
5
6
# File 'lib/query_track/notifications/slack.rb', line 4

def code
  @code
end

#durationObject (readonly)

Returns the value of attribute duration.



4
5
6
# File 'lib/query_track/notifications/slack.rb', line 4

def duration
  @duration
end

#webhook_urlObject (readonly)

Returns the value of attribute webhook_url.



4
5
6
# File 'lib/query_track/notifications/slack.rb', line 4

def webhook_url
  @webhook_url
end

Instance Method Details

#callObject



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/query_track/notifications/slack.rb', line 12

def call
  return if webhook_url.nil? || webhook_url.empty?

  slack_hook = SlackHook::Incoming.new(webhook_url)

  trace = QueryTrack::Trace.new(caller).call

  payload = { blocks: blocks(trace) }

  Thread.new { slack_hook.post(payload) }
end