Class: FlimperNikita::Notifications::Send

Inherits:
Object
  • Object
show all
Defined in:
lib/flimper_nikita/notifications/send.rb

Instance Method Summary collapse

Constructor Details

#initialize(source:, severity:, message:, jwt_token:) ⇒ Send

Returns a new instance of Send.



7
8
9
10
11
12
# File 'lib/flimper_nikita/notifications/send.rb', line 7

def initialize(source:, severity:, message:, jwt_token:)
  @source = source
  @severity = severity
  @message = message
  @jwt_token = jwt_token
end

Instance Method Details

#issue!Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/flimper_nikita/notifications/send.rb', line 22

def issue!
  nikita_response = Faraday.new.post do |request|
    request.url(nikita_api_endpoint)
    request.headers['Content-Type'] = 'application/json'
    request.headers['Authorization'] = @jwt_token
    request.body = security_data
  end

  return unless nikita_response.success?
end

#nikita_api_endpointObject



14
15
16
# File 'lib/flimper_nikita/notifications/send.rb', line 14

def nikita_api_endpoint
  "#{ENV.fetch('NIKITA_API_URL')}/notifications"
end

#security_dataObject



18
19
20
# File 'lib/flimper_nikita/notifications/send.rb', line 18

def security_data
  { source: @source, severity: @severity, message: @message }.to_json
end