Sha256: 9f1e9361a06d297a3b4e1ff258f4d328b8109fa55ff19d78547de19dea00fc25

Contents?: true

Size: 879 Bytes

Versions: 61

Compression:

Stored size: 879 Bytes

Contents

module Appsignal
  class AuthCheck
    ACTION = 'auth'.freeze

    attr_reader :config, :logger

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

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

    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
  end
end

Version data entries

61 entries across 61 versions & 1 rubygems

Version Path
appsignal-1.1.0.beta.13 lib/appsignal/auth_check.rb