Class: TeamsConnector::Notification

Inherits:
Object
  • Object
show all
Defined in:
lib/teams_connector/notification.rb,
lib/teams_connector/notification/message.rb,
lib/teams_connector/notification/adaptive_card.rb

Direct Known Subclasses

AdaptiveCard, Message

Defined Under Namespace

Classes: AdaptiveCard, Message

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template: nil, channels: TeamsConnector.configuration.default) ⇒ Notification



12
13
14
15
# File 'lib/teams_connector/notification.rb', line 12

def initialize(template: nil, channels: TeamsConnector.configuration.default)
  @template = template
  @channels = channels.instance_of?(Array) ? channels : [channels]
end

Instance Attribute Details

#channelsObject

Returns the value of attribute channels.



10
11
12
# File 'lib/teams_connector/notification.rb', line 10

def channels
  @channels
end

#templateObject

Returns the value of attribute template.



10
11
12
# File 'lib/teams_connector/notification.rb', line 10

def template
  @template
end

Instance Method Details

#deliver_laterObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/teams_connector/notification.rb', line 17

def deliver_later
  template_path = find_template

  renderer = ERB.new(File.read(template_path))
  renderer.location = [template_path.to_s, 0]

  content = renderer.result(binding)

  channels = TeamsConnector.configuration.always_use_default ? [TeamsConnector.configuration.default] : @channels
  channels.each do |channel|
    deliver_channel(channel, content)
  end
end

#pretty_printObject



31
32
33
34
35
36
37
38
39
# File 'lib/teams_connector/notification.rb', line 31

def pretty_print
  template_path = find_template

  renderer = ERB.new(File.read(template_path))
  renderer.location = [template_path.to_s, 0]
  content = renderer.result(binding)

  puts JSON.pretty_generate(JSON.parse(content))
end