module LeapSalesforce::ExeHelpers

Helpers for LeapSalesforce executable

Public Instance Methods

input_for(query, color = nil) click to toggle source

Return input for query @param [String] query Query to ask on terminal @return [String] User input to store

# File lib/leap_salesforce/generator/exe_helpers.rb, line 13
def input_for(query, color = nil)
  if color
    puts query.colorize(color)
  else
    puts query
  end
  $stdin.gets.strip
end
query_for_parameters() click to toggle source

Ask user to enter parameters specific to their Salesforce environment

# File lib/leap_salesforce/generator/exe_helpers.rb, line 48
def query_for_parameters
  puts 'Please enter the following information to generate files for a new' \
  ' leap_salesforce testing repo'.colorize(:green)
  verify_environment
  verify_oauth
  @user_key = options[:user_key] || input_for('Enter a key to refer to this user (This will be stored as a Symbol)').delete(':')
end
verify_environment() click to toggle source

Retrieve environment and ensure that environment can be connected to

# File lib/leap_salesforce/generator/exe_helpers.rb, line 23
  def verify_environment
    unless LeapSalesforce.sfdx
      LeapSalesforce.environment = options[:environment] || input_for('Enter the environment you want to set things up for ' \
'(This will be parameterised so can be changed later). For production used "prod". Otherwise preference is to use the' \
' part of the URL that is unique for the environment')
    end
    LeapSalesforce.salesforce_reachable?
    puts "\u2713 Connection to #{LeapSalesforce.general_url} successful".colorize :green
  end
verify_oauth() click to toggle source

Retrieve OAuth credentials and verify that they're correct

# File lib/leap_salesforce/generator/exe_helpers.rb, line 34
  def verify_oauth
    unless LeapSalesforce.sfdx
      LeapSalesforce.client_id = options[:client_id] || input_for('Client id (Customer Id)')
      LeapSalesforce.client_secret = options[:client_secret] || $stdin.getpass('Client secret (Consumer Secret)')
      LeapSalesforce.password = options[:password] || $stdin.getpass('Password (Recommendation is that 1 password' \
' be shared across all test users to be easier to manage):')
    end
    LeapSalesforce.api_user = ERB.new(options[:username] || input_for('Salesforce username. It is ideal to start with a System admin' \
' so that any necessary metadata can be read. More users can be added later. You can use ERB to make name' \
' vary according to environment (e.g., test.user@<%= LeapSalesforce.environment %>.my.company.com)')).result(binding)
    LeapSalesforce.oauth_working?
  end