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"
DEFAULT_API_VERSION =
"2024-09-27"
VALID_ENVIRONMENTS =
%i[sandbox production].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



16
17
18
19
20
# File 'lib/airwallex/configuration.rb', line 16

def initialize
  @environment = :sandbox
  @api_version = DEFAULT_API_VERSION
  @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



22
23
24
25
26
27
28
29
30
31
# File 'lib/airwallex/configuration.rb', line 22

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)


63
64
65
# File 'lib/airwallex/configuration.rb', line 63

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

#files_urlObject



33
34
35
36
37
38
39
40
41
42
# File 'lib/airwallex/configuration.rb', line 33

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:



52
53
54
55
56
57
58
59
60
61
# File 'lib/airwallex/configuration.rb', line 52

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