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(*args) ⇒ AuthCheck

Returns a new instance of AuthCheck.



8
9
10
11
12
13
# File 'lib/appsignal/auth_check.rb', line 8

def initialize(*args)
  @environment = args.shift
  options = args.empty? ? {} : args.last
  @config = options[:config]
  @logger = options[:logger]
end

Instance Attribute Details

#environmentObject (readonly)

Returns the value of attribute environment.



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

def environment
  @environment
end

#loggerObject (readonly)

Returns the value of attribute logger.



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

def logger
  @logger
end

#transmitterObject

Returns the value of attribute transmitter.



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

def transmitter
  @transmitter
end

Instance Method Details

#configObject



19
20
21
# File 'lib/appsignal/auth_check.rb', line 19

def config
  @config ||= Appsignal::Config.new(Rails.root, environment, logger).load
end

#performObject



23
24
25
26
27
28
# File 'lib/appsignal/auth_check.rb', line 23

def perform
  self.transmitter = Appsignal::Transmitter.new(
    config[:endpoint], ACTION, config[:api_key]
  )
  transmitter.transmit({})
end

#perform_with_resultObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/appsignal/auth_check.rb', line 30

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

#uriObject



15
16
17
# File 'lib/appsignal/auth_check.rb', line 15

def uri
  transmitter.uri
end