class InformantSinatra::Diagnostic

Public Class Methods

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

Public Instance Methods

run() click to toggle source
# File lib/informant-sinatra/diagnostic.rb, line 7
def run
  if Config.enabled?
    response = InformantCommon::Client.transmit(test_form_submission).join.value
    display_response_message(response)
  else
    puts missing_api_token_message
  end

  puts assistance_message
end

Private Instance Methods

assistance_message() click to toggle source
# File lib/informant-sinatra/diagnostic.rb, line 42
def assistance_message
  "If you need assistance or have any questions, send an email to support@informantapp.com or tweet @informantapp and we'll help you out!"
end
bad_response_message(server_message) click to toggle source
# File lib/informant-sinatra/diagnostic.rb, line 34
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-sinatra/diagnostic.rb, line 58
def display_response_message(response)
  if response.code == '204'
    puts success_message
  else
    puts bad_response_message(response.body)
  end
end
missing_api_token_message() click to toggle source
# File lib/informant-sinatra/diagnostic.rb, line 20
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 in your application setup

        InformantSinatra::Config.api_token = 'your token'
  )
end
success_message() click to toggle source
# File lib/informant-sinatra/diagnostic.rb, line 38
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-sinatra/diagnostic.rb, line 46
def test_form_submission
  InformantCommon::Event::FormSubmission.new.tap do |form_submission|
    form_submission.handler = 'Connectivity#test'
    form_submission.process_model(
      InformantCommon::Model::Base.new(
        name: 'TestClass',
        field_errors: [InformantCommon::FieldError.new('field_name', nil, "can't be blank")]
      )
    )
  end
end