Class: Appsignal::AuthCheck Private
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Class used to perform a Push API validation / authentication check against the AppSignal Push API.
Constant Summary collapse
- ACTION =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Path used on the AppSignal Push API https://push.appsignal.com/1/auth
"auth".freeze
Instance Attribute Summary collapse
-
#config ⇒ Appsignal::Config
readonly
private
Config to use in the authentication request.
- #logger ⇒ Object readonly private
Instance Method Summary collapse
-
#initialize(config, logger = nil) ⇒ AuthCheck
constructor
private
A new instance of AuthCheck.
-
#perform ⇒ String
private
Perform push api validation request and return response status code.
-
#perform_with_result ⇒ Array<String/nil, String>
private
Perform push api validation request and return a descriptive response tuple.
Constructor Details
#initialize(config, logger = nil) ⇒ AuthCheck
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of AuthCheck.
25 26 27 28 29 30 31 |
# File 'lib/appsignal/auth_check.rb', line 25 def initialize(config, logger = nil) @config = config if logger # rubocop:disable Style/GuardClause warn "Deprecated: `logger` argument will be removed in the next " \ "major version." end end |
Instance Attribute Details
#config ⇒ Appsignal::Config (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns config to use in the authentication request.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/appsignal/auth_check.rb', line 18 class AuthCheck # Path used on the AppSignal Push API # https://push.appsignal.com/1/auth ACTION = "auth".freeze attr_reader :config, :logger def initialize(config, logger = nil) @config = config if logger # rubocop:disable Style/GuardClause warn "Deprecated: `logger` argument will be removed in the next " \ "major version." end 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 |
#logger ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
23 24 25 |
# File 'lib/appsignal/auth_check.rb', line 23 def logger @logger end |
Instance Method Details
#perform ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Perform push api validation request and return response status code.
37 38 39 |
# File 'lib/appsignal/auth_check.rb', line 37 def perform Appsignal::Transmitter.new(ACTION, config).transmit({}).code end |
#perform_with_result ⇒ Array<String/nil, String>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Perform push api validation request and return a descriptive response tuple.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/appsignal/auth_check.rb', line 48 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 |