class InformantRails::Diagnostic

Public Class Methods

run() click to toggle source
# File lib/informant-rails/diagnostic.rb, line 11
def self.run
  new.run
end

Public Instance Methods

run() click to toggle source
# File lib/informant-rails/diagnostic.rb, line 15
def run
  if Config.api_token.blank?
    Rails.logger.info missing_api_token_message
  else
    response = InformantCommon::Client.transmit(test_form_submission).join.value
    display_response_message(response)
  end

  Rails.logger.info assistance_message
end

Private Instance Methods

assistance_message() click to toggle source
# File lib/informant-rails/diagnostic.rb, line 50
def assistance_message
  "If you need assistance or have any questions, send an email to support@informantapp.com and we'll help you out!"
end
bad_response_message(server_message) click to toggle source
# File lib/informant-rails/diagnostic.rb, line 42
def bad_response_message(server_message)
  "Seems like we have a problem. \"#{server_message}\" in this case."
end
display_response_message(response) click to toggle source
# File lib/informant-rails/diagnostic.rb, line 61
def display_response_message(response)
  if response.code == '204'
    Rails.logger.info success_message
  else
    Rails.logger.info bad_response_message(response.body)
  end
end
missing_api_token_message() click to toggle source
# File lib/informant-rails/diagnostic.rb, line 28
def missing_api_token_message
  %<
    Your API token could not be found in the configuration.
    You can retrieve it from your Informantapp.com dashboard.

      Then add it to your server's environment as `INFORMANT_API_KEY`

      OR

      Set it manually with an initializer (config/informant.rb)
        InformantRails::Config.api_token = 'your token'
  >
end
success_message() click to toggle source
# File lib/informant-rails/diagnostic.rb, line 46
def success_message
  'Everything looks good. You should see a test request on your dashboard.'
end
test_form_submission() click to toggle source
# File lib/informant-rails/diagnostic.rb, line 54
def test_form_submission
  InformantCommon::Event::FormSubmission.new.tap do |form_submission|
    form_submission.handler = 'Connectivity#test'
    form_submission.process_model(InformantCommon::Model::ActiveModel.new(TestClass.new.tap(&:valid?)))
  end
end