Class: Certynix::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/certynix/config.rb

Constant Summary collapse

API_KEY_REGEX =
/\Acnx_(live|test)_sk_[a-zA-Z0-9]{32,}\z/
PRODUCTION_URL =
'https://api.certynix.com'
SANDBOX_URL =
'https://sandbox.certynix.com'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key:, base_url: nil, timeout: 30, max_retries: 3, access_token: nil) ⇒ Config

Returns a new instance of Config.

Raises:



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/certynix/config.rb', line 11

def initialize(api_key:, base_url: nil, timeout: 30, max_retries: 3, access_token: nil)
  raise ConfigurationError, 'api_key is required' if api_key.nil? || api_key.empty?
  unless api_key.match?(API_KEY_REGEX)
    # NUNCA incluir a API key na mensagem de erro
    raise ConfigurationError, 'Invalid API key format. Expected cnx_live_sk_... or cnx_test_sk_...'
  end

  @api_key      = api_key
  @sandbox      = api_key.start_with?('cnx_test_')
  @base_url     = base_url || (@sandbox ? SANDBOX_URL : PRODUCTION_URL)
  @timeout      = timeout
  @max_retries  = max_retries
  @access_token = access_token
end

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



9
10
11
# File 'lib/certynix/config.rb', line 9

def access_token
  @access_token
end

#api_keyObject (readonly)

Returns the value of attribute api_key.



9
10
11
# File 'lib/certynix/config.rb', line 9

def api_key
  @api_key
end

#base_urlObject (readonly)

Returns the value of attribute base_url.



9
10
11
# File 'lib/certynix/config.rb', line 9

def base_url
  @base_url
end

#max_retriesObject (readonly)

Returns the value of attribute max_retries.



9
10
11
# File 'lib/certynix/config.rb', line 9

def max_retries
  @max_retries
end

#sandboxObject (readonly) Also known as: sandbox?

Returns the value of attribute sandbox.



9
10
11
# File 'lib/certynix/config.rb', line 9

def sandbox
  @sandbox
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



9
10
11
# File 'lib/certynix/config.rb', line 9

def timeout
  @timeout
end

Instance Method Details

#mask_api_keyObject

Mascara a API key para logs — nunca expõe o valor completo



29
30
31
32
# File 'lib/certynix/config.rb', line 29

def mask_api_key
  return '***' if api_key.length <= 12
  "#{api_key[0..11]}***"
end