Class: MsTeamsNotification::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/ms_teams_notification/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**kwargs) ⇒ Base

Returns a new instance of Base.



10
11
12
13
14
15
# File 'lib/ms_teams_notification/base.rb', line 10

def initialize **kwargs
  @log = MsTeamsNotification::Logger.instance

  setup_configuration(**kwargs)
  configure_ms_teams
end

Instance Attribute Details

#default_subjectObject (readonly)

Returns the value of attribute default_subject.



8
9
10
# File 'lib/ms_teams_notification/base.rb', line 8

def default_subject
  @default_subject
end

Instance Method Details

#send_ms_teams_notice(text) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ms_teams_notification/base.rb', line 17

def send_ms_teams_notice text
  return unless @webhook_url.present?

  @log.msg "#{self_name}: sending ms teams notification."

  request = Net::HTTP::Post.new @webhook_url.request_uri
  request["Content-Type"] = "application/json"
  request.body = {title: message_subject, text: text}.to_json

  http = Net::HTTP.new @webhook_url.host, @webhook_url.port
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE

  body = http.request(request)&.body
  @log.msg "#{self_name}: ms teams notification is sent."
  body
rescue => e
  @log.msg "#{self_name}: ms teams notification failed.", level: :error
  @log.msg "#{self_name}: #{e.message}.", level: :error
end