Class: Appsignal::AuthCheck

Inherits:
Object
  • Object
show all
Defined in:
lib/appsignal/auth_check.rb

Constant Summary collapse

ACTION =
'auth'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, logger = Appsignal.logger) ⇒ AuthCheck

Returns a new instance of AuthCheck.



7
8
9
10
# File 'lib/appsignal/auth_check.rb', line 7

def initialize(config, logger=Appsignal.logger)
  @config = config
  @logger = logger
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



5
6
7
# File 'lib/appsignal/auth_check.rb', line 5

def config
  @config
end

#loggerObject (readonly)

Returns the value of attribute logger.



5
6
7
# File 'lib/appsignal/auth_check.rb', line 5

def logger
  @logger
end

Instance Method Details

#performObject



12
13
14
# File 'lib/appsignal/auth_check.rb', line 12

def perform
  Appsignal::Transmitter.new(ACTION, config).transmit({})
end

#perform_with_resultObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/appsignal/auth_check.rb', line 16

def perform_with_result
  begin
    status = perform
    case status
    when '200'
      result = 'AppSignal has confirmed authorization!'
    when '401'
      result = 'API key not valid with AppSignal...'
    else
      result = 'Could not confirm authorization: '\
               "#{status.nil? ? 'nil' : status}"
    end
    [status, result]
  rescue Exception => e
    result = 'Something went wrong while trying to '\
             "authenticate with AppSignal: #{e}"
    [nil, result]
  end
end