Class: ComplyanceSDK::Config::SDKConfig
- Inherits:
-
Object
- Object
- ComplyanceSDK::Config::SDKConfig
- Defined in:
- lib/complyance_sdk/config/sdk_config.rb
Overview
Configuration class for the Complyance SDK
Instance Attribute Summary collapse
-
#api_key ⇒ Object
API key for authentication.
-
#auto_generate_tax_destination ⇒ Object
Auto-generate tax destination flag.
-
#correlation_id ⇒ Object
Correlation ID for request tracking.
-
#environment ⇒ Object
Environment (sandbox, production).
-
#log_level ⇒ Object
Log level.
-
#logging_enabled ⇒ Object
Logging configuration.
-
#retry_config ⇒ Object
Retry configuration.
-
#sources ⇒ Object
Array of sources.
Class Method Summary collapse
-
.from_env ⇒ SDKConfig
Create a configuration from environment variables.
-
.from_file(path) ⇒ SDKConfig
Create a configuration from a YAML file.
-
.from_rails(environment = nil) ⇒ SDKConfig
Create a configuration from Rails credentials.
Instance Method Summary collapse
-
#add_source(source) ⇒ Array<ComplyanceSDK::Models::Source>
Add a source to the configuration.
-
#auto_generate_tax_destination? ⇒ Boolean
Check if auto-generate tax destination is enabled.
-
#errors ⇒ Hash
Get validation errors.
-
#initialize(options = {}) ⇒ SDKConfig
constructor
Initialize a new configuration.
-
#valid? ⇒ Boolean
Check if the configuration is valid.
Constructor Details
#initialize(options = {}) ⇒ SDKConfig
Initialize a new configuration
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/complyance_sdk/config/sdk_config.rb', line 43 def initialize( = {}) @api_key = [:api_key] @environment = parse_environment([:environment]) @sources = [:sources] || [] @retry_config = [:retry_config] || RetryConfig.default @logging_enabled = .fetch(:logging_enabled, true) @log_level = .fetch(:log_level, :info) @auto_generate_tax_destination = .fetch(:auto_generate_tax_destination, true) @correlation_id = [:correlation_id] @errors = {} end |
Instance Attribute Details
#api_key ⇒ Object
API key for authentication
11 12 13 |
# File 'lib/complyance_sdk/config/sdk_config.rb', line 11 def api_key @api_key end |
#auto_generate_tax_destination ⇒ Object
Auto-generate tax destination flag
29 30 31 |
# File 'lib/complyance_sdk/config/sdk_config.rb', line 29 def auto_generate_tax_destination @auto_generate_tax_destination end |
#correlation_id ⇒ Object
Correlation ID for request tracking
32 33 34 |
# File 'lib/complyance_sdk/config/sdk_config.rb', line 32 def correlation_id @correlation_id end |
#environment ⇒ Object
Environment (sandbox, production)
14 15 16 |
# File 'lib/complyance_sdk/config/sdk_config.rb', line 14 def environment @environment end |
#log_level ⇒ Object
Log level
26 27 28 |
# File 'lib/complyance_sdk/config/sdk_config.rb', line 26 def log_level @log_level end |
#logging_enabled ⇒ Object
Logging configuration
23 24 25 |
# File 'lib/complyance_sdk/config/sdk_config.rb', line 23 def logging_enabled @logging_enabled end |
#retry_config ⇒ Object
Retry configuration
20 21 22 |
# File 'lib/complyance_sdk/config/sdk_config.rb', line 20 def retry_config @retry_config end |
#sources ⇒ Object
Array of sources
17 18 19 |
# File 'lib/complyance_sdk/config/sdk_config.rb', line 17 def sources @sources end |
Class Method Details
.from_env ⇒ SDKConfig
Create a configuration from environment variables
74 75 76 77 78 79 80 81 |
# File 'lib/complyance_sdk/config/sdk_config.rb', line 74 def self.from_env new( api_key: ENV["COMPLYANCE_API_KEY"], environment: ENV["COMPLYANCE_ENVIRONMENT"], logging_enabled: ENV.fetch("COMPLYANCE_LOGGING_ENABLED", "true") == "true", log_level: ENV.fetch("COMPLYANCE_LOG_LEVEL", "info").to_sym ) end |
.from_file(path) ⇒ SDKConfig
Create a configuration from a YAML file
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/complyance_sdk/config/sdk_config.rb', line 111 def self.from_file(path) require "erb" # Process ERB templates in YAML files erb_content = ERB.new(File.read(path)).result config = YAML.safe_load(erb_content, symbolize_names: true) # Handle sources array if config[:sources].is_a?(Array) config[:sources] = config[:sources].map do |source_config| ComplyanceSDK::Models::Source.new(source_config) end end # Handle retry_config hash if config[:retry_config].is_a?(Hash) config[:retry_config] = RetryConfig.new(config[:retry_config]) end # Convert log_level to symbol if it's a string if config[:log_level].is_a?(String) config[:log_level] = config[:log_level].to_sym end new(config) end |
.from_rails(environment = nil) ⇒ SDKConfig
Create a configuration from Rails credentials
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/complyance_sdk/config/sdk_config.rb', line 87 def self.from_rails(environment = nil) return unless defined?(Rails) env = environment || Rails.env.to_sym credentials = Rails.application.credentials config = if credentials.dig(:complyance, env) credentials.dig(:complyance, env) else credentials.dig(:complyance) || {} end new( api_key: config[:api_key], environment: config[:environment], logging_enabled: config.fetch(:logging_enabled, true), log_level: config.fetch(:log_level, :info).to_sym ) end |
Instance Method Details
#add_source(source) ⇒ Array<ComplyanceSDK::Models::Source>
Add a source to the configuration
142 143 144 145 |
# File 'lib/complyance_sdk/config/sdk_config.rb', line 142 def add_source(source) @sources << source @sources end |
#auto_generate_tax_destination? ⇒ Boolean
Check if auto-generate tax destination is enabled
150 151 152 |
# File 'lib/complyance_sdk/config/sdk_config.rb', line 150 def auto_generate_tax_destination? @auto_generate_tax_destination end |
#errors ⇒ Hash
Get validation errors
67 68 69 |
# File 'lib/complyance_sdk/config/sdk_config.rb', line 67 def errors @errors ||= {} end |
#valid? ⇒ Boolean
Check if the configuration is valid
58 59 60 61 62 |
# File 'lib/complyance_sdk/config/sdk_config.rb', line 58 def valid? @errors = {} validate @errors.empty? end |