class AlgoliaSearchCredentialChecker
Given an HTML file as input, will return an array of records to index
Attributes
config[RW]
logger[RW]
Public Class Methods
new(config)
click to toggle source
# File lib/credential_checker.rb, line 10 def initialize(config) @config = config @logger = AlgoliaSearchErrorHandler.new end
Public Instance Methods
api_key()
click to toggle source
Read the API key either from ENV or from an _algolia_api_key file in source folder
# File lib/credential_checker.rb, line 17 def api_key # First read in ENV return ENV['ALGOLIA_API_KEY'] if ENV['ALGOLIA_API_KEY'] # Otherwise from file in source directory key_file = File.join(@config['source'], '_algolia_api_key') if File.exist?(key_file) && File.size(key_file) > 0 return File.open(key_file).read.strip end nil end
application_id()
click to toggle source
Read the application id either from the config file or from ENV
# File lib/credential_checker.rb, line 43 def application_id get_key('ALGOLIA_APPLICATION_ID', 'application_id') end
assert_valid()
click to toggle source
Check that all credentials are present Stop with a helpful message if not
# File lib/credential_checker.rb, line 75 def assert_valid check_api_key check_application_id check_index_name Algolia.init( application_id: application_id, api_key: api_key ) nil end
check_api_key()
click to toggle source
Check that the API key is available
# File lib/credential_checker.rb, line 53 def check_api_key return if api_key @logger.display('api_key_missing') exit 1 end
check_application_id()
click to toggle source
Check that the application id is defined
# File lib/credential_checker.rb, line 60 def check_application_id return if application_id @logger.display('application_id_missing') exit 1 end
check_index_name()
click to toggle source
Check that the index name is defined
# File lib/credential_checker.rb, line 67 def check_index_name return if index_name @logger.display('index_name_missing') exit 1 end
get_key(env_name, config_key)
click to toggle source
Read key either from ENV or _config.yml
# File lib/credential_checker.rb, line 30 def get_key(env_name, config_key) # First read in ENV return ENV[env_name] if ENV[env_name] # Otherwise read from _config.yml if @config['algolia'] && @config['algolia'][config_key] return @config['algolia'][config_key] end nil end
index_name()
click to toggle source
Read the index name either from the config file or from ENV
# File lib/credential_checker.rb, line 48 def index_name get_key('ALGOLIA_INDEX_NAME', 'index_name') end