Class: Airwallex::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/airwallex/configuration.rb

Constant Summary collapse

SANDBOX_API_URL =
"https://api-demo.airwallex.com"
PRODUCTION_API_URL =
"https://api.airwallex.com"
SANDBOX_FILES_URL =
"https://files-demo.airwallex.com"
PRODUCTION_FILES_URL =
"https://files.airwallex.com"
VALID_ENVIRONMENTS =
%i[sandbox production].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

api_version is nil by default. Airwallex stores a version on your account and applies it automatically; the x-api-version header is only for exceptional per-call overrides (testing/migrating), not a permanent pin — see https://www.airwallex.com/docs/api/versioning. Set this explicitly if you want reproducible, pinned behavior instead.



20
21
22
23
24
# File 'lib/airwallex/configuration.rb', line 20

def initialize
  @environment = :sandbox
  @api_version = nil
  @log_level = :info
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



5
6
7
# File 'lib/airwallex/configuration.rb', line 5

def api_key
  @api_key
end

#api_versionObject

Returns the value of attribute api_version.



5
6
7
# File 'lib/airwallex/configuration.rb', line 5

def api_version
  @api_version
end

#client_idObject

Returns the value of attribute client_id.



5
6
7
# File 'lib/airwallex/configuration.rb', line 5

def client_id
  @client_id
end

#environmentObject

Returns the value of attribute environment.



6
7
8
# File 'lib/airwallex/configuration.rb', line 6

def environment
  @environment
end

#log_levelObject

Returns the value of attribute log_level.



5
6
7
# File 'lib/airwallex/configuration.rb', line 5

def log_level
  @log_level
end

#loggerObject

Returns the value of attribute logger.



5
6
7
# File 'lib/airwallex/configuration.rb', line 5

def logger
  @logger
end

Instance Method Details

#api_urlObject



26
27
28
29
30
31
32
33
34
35
# File 'lib/airwallex/configuration.rb', line 26

def api_url
  case environment
  when :sandbox
    SANDBOX_API_URL
  when :production
    PRODUCTION_API_URL
  else
    raise ConfigurationError, "Invalid environment: #{environment}. Must be :sandbox or :production"
  end
end

#configured?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/airwallex/configuration.rb', line 67

def configured?
  !api_key.nil? && !client_id.nil? && VALID_ENVIRONMENTS.include?(environment)
end

#files_urlObject



37
38
39
40
41
42
43
44
45
46
# File 'lib/airwallex/configuration.rb', line 37

def files_url
  case environment
  when :sandbox
    SANDBOX_FILES_URL
  when :production
    PRODUCTION_FILES_URL
  else
    raise ConfigurationError, "Invalid environment: #{environment}. Must be :sandbox or :production"
  end
end

#validate!Object

Raises:



56
57
58
59
60
61
62
63
64
65
# File 'lib/airwallex/configuration.rb', line 56

def validate!
  errors = []
  errors << "api_key is required" if api_key.nil? || api_key.empty?
  errors << "client_id is required" if client_id.nil? || client_id.empty?
  errors << "environment must be :sandbox or :production" unless VALID_ENVIRONMENTS.include?(environment)

  raise ConfigurationError, errors.join(", ") unless errors.empty?

  true
end