Class: Appsignal::AuthCheck
- Inherits:
-
Object
- Object
- Appsignal::AuthCheck
- Defined in:
- lib/appsignal/auth_check.rb
Constant Summary collapse
- ACTION =
'auth'.freeze
Instance Attribute Summary collapse
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#transmitter ⇒ Object
Returns the value of attribute transmitter.
Instance Method Summary collapse
- #config ⇒ Object
-
#initialize(*args) ⇒ AuthCheck
constructor
A new instance of AuthCheck.
- #perform ⇒ Object
- #perform_with_result ⇒ Object
- #uri ⇒ Object
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 = args.empty? ? {} : args.last @config = [:config] @logger = [:logger] end |
Instance Attribute Details
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
5 6 7 |
# File 'lib/appsignal/auth_check.rb', line 5 def environment @environment end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
5 6 7 |
# File 'lib/appsignal/auth_check.rb', line 5 def logger @logger end |
#transmitter ⇒ Object
Returns the value of attribute transmitter.
6 7 8 |
# File 'lib/appsignal/auth_check.rb', line 6 def transmitter @transmitter end |
Instance Method Details
#config ⇒ Object
19 20 21 |
# File 'lib/appsignal/auth_check.rb', line 19 def config @config ||= Appsignal::Config.new(Rails.root, environment, logger).load end |
#perform ⇒ Object
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_result ⇒ Object
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 |
#uri ⇒ Object
15 16 17 |
# File 'lib/appsignal/auth_check.rb', line 15 def uri transmitter.uri end |