Module: Zencoder::CLI::Auth

Extended by:
Helpers
Defined in:
lib/zencoder-cli/auth.rb

Class Method Summary collapse

Methods included from Helpers

ask, confirm, display, error, format_date, home_directory, running_on_a_mac?, running_on_windows?, truncate

Class Method Details

.require_authentication(env) ⇒ Object



8
9
10
# File 'lib/zencoder-cli/auth.rb', line 8

def require_authentication(env)
  Zencoder.api_key ||= retrieve_api_key(env)
end

.retrieve_api_key(env) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/zencoder-cli/auth.rb', line 12

def retrieve_api_key(env)
  env = "production" if !env || env.blank?
  if File.exist?("#{home_directory}/.zencoder/api-key")
    keys = YAML.load_file("#{home_directory}/.zencoder/api-key")
    if keys[env].present?
      keys[env]
    else
      error "No API found for the #{env} environment. Either set the environment variable ZENCODER_API_KEY or run `zencoder setup`."
    end
  else
    error "No API keys found. Either set the environment variable ZENCODER_API_KEY or run `zencoder setup`."
  end
end