Class: Factorix::APICredential

Inherits:
Data
  • Object
show all
Defined in:
lib/factorix/api_credential.rb,
lib/factorix/api_credential.rb

Overview

API credentials for Factorio MOD Portal management

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#api_keyString (readonly)

Returns API key for Factorio MOD Portal.

Returns:

  • (String)

    API key for Factorio MOD Portal



13
14
15
# File 'lib/factorix/api_credential.rb', line 13

def api_key
  @api_key
end

Class Method Details

.loadAPICredential

Load API credentials from environment variables

Returns:

Raises:



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/factorix/api_credential.rb', line 24

def self.load
  logger = Container["logger"]
  logger.debug "Loading API credentials from environment"

  api_key = ENV.fetch(ENV_API_KEY, nil)
  if api_key.nil?
    logger.error("Failed to load API credentials", reason: "#{ENV_API_KEY} not set")
    raise CredentialError, "#{ENV_API_KEY} environment variable is not set"
  end

  if api_key.empty?
    logger.error("Failed to load API credentials", reason: "#{ENV_API_KEY} is empty")
    raise CredentialError, "#{ENV_API_KEY} environment variable is empty"
  end

  logger.info("API credentials loaded successfully")
  new(api_key:)
end

Instance Method Details

#inspectString Also known as: to_s

Returns string representation with masked API key.

Returns:

  • (String)

    string representation with masked API key



46
# File 'lib/factorix/api_credential.rb', line 46

def inspect = %[#<#{self.class} api_key="*****">]

#pretty_print(pp) ⇒ void

This method returns an undefined value.

Parameters:

  • pp (PP)

    pretty printer



52
# File 'lib/factorix/api_credential.rb', line 52

def pretty_print(pp) = pp.text(inspect)