Sha256: 2c6675e6652818f49539d65a6754460ad3abb0120643132bea386a99bc0255a3

Contents?: true

Size: 1.85 KB

Versions: 110

Compression:

Stored size: 1.85 KB

Contents

# frozen_string_literal: true

module Appsignal
  # Class used to perform a Push API validation / authentication check against
  # the AppSignal Push API.
  #
  # @example
  #   config = Appsignal::Config.new(Dir.pwd, "production")
  #   auth_check = Appsignal::AuthCheck.new(config)
  #   # Valid push_api_key
  #   auth_check.perform # => "200"
  #   # Invalid push_api_key
  #   auth_check.perform # => "401"
  #
  # @!attribute [r] config
  #   @return [Appsignal::Config] config to use in the authentication request.
  # @api private
  class AuthCheck
    # Path used on the AppSignal Push API
    # https://push.appsignal.com/1/auth
    ACTION = "auth".freeze

    attr_reader :config

    def initialize(config)
      @config = config
    end

    # Perform push api validation request and return response status code.
    #
    # @return [String] response status code.
    # @raise [StandardError] see {Appsignal::Transmitter#transmit}.
    def perform
      Appsignal::Transmitter.new(ACTION, config).transmit({}).code
    end

    # Perform push api validation request and return a descriptive response
    # tuple.
    #
    # @return [Array<String/nil, String>] response tuple.
    #   - First value is the response status code.
    #   - Second value is a description of the response and the exception error
    #     message if an exception occured.
    def perform_with_result
      status = perform
      result =
        case status
        when "200"
          "AppSignal has confirmed authorization!"
        when "401"
          "API key not valid with AppSignal..."
        else
          "Could not confirm authorization: " \
            "#{status.nil? ? "nil" : status}"
        end
      [status, result]
    rescue => e
      result = "Something went wrong while trying to "\
               "authenticate with AppSignal: #{e}"
      [nil, result]
    end
  end
end

Version data entries

110 entries across 110 versions & 1 rubygems

Version Path
appsignal-3.3.11-java lib/appsignal/auth_check.rb
appsignal-3.3.11 lib/appsignal/auth_check.rb
appsignal-3.4.0-java lib/appsignal/auth_check.rb
appsignal-3.4.0 lib/appsignal/auth_check.rb
appsignal-3.3.10-java lib/appsignal/auth_check.rb
appsignal-3.3.10 lib/appsignal/auth_check.rb
appsignal-3.3.9-java lib/appsignal/auth_check.rb
appsignal-3.3.9 lib/appsignal/auth_check.rb
appsignal-3.3.8-java lib/appsignal/auth_check.rb
appsignal-3.3.8 lib/appsignal/auth_check.rb
appsignal-3.3.7-java lib/appsignal/auth_check.rb
appsignal-3.3.7 lib/appsignal/auth_check.rb
appsignal-3.3.6-java lib/appsignal/auth_check.rb
appsignal-3.3.6 lib/appsignal/auth_check.rb
appsignal-3.3.5-java lib/appsignal/auth_check.rb
appsignal-3.3.5 lib/appsignal/auth_check.rb
appsignal-3.3.4-java lib/appsignal/auth_check.rb
appsignal-3.3.4 lib/appsignal/auth_check.rb
appsignal-3.3.3-java lib/appsignal/auth_check.rb
appsignal-3.3.3 lib/appsignal/auth_check.rb