class Hawkei::Config
Hawkei
Config¶ ↑
Represent the Hawkei
configuration for the API
Constants
- DEFAULT_OBFUSCATED_FIELDS
Attributes
api_host[RW]
@return [String] API host
api_key[RW]
@return [String] API account token
api_version[RW]
@return [String] API version
domain[RW]
@return [String] domain
enabled[RW]
@return [Boolean] service is enable
environment_name[RW]
@return [String] API environment name
http_secure[RW]
@return [Boolean] http secure
log[RW]
@return [Boolean] enable the logger
logger[RW]
@return [Logger] logger
metadata[RW]
@return [Hash] metadata to be attach to the payload
obfuscated_fields[RW]
@return [Array] fields to obfuscate
proxy_url[RW]
@return [String] proxy url
space_name[RW]
@return [String] API space name
Public Class Methods
new(options = {})
click to toggle source
@param [Hash{Symbol=>Object}] Initialize and validate the configuration
# File lib/hawkei/config.rb, line 77 def initialize(options = {}) self.api_key = options[:api_key] self.space_name = options[:space_name] self.environment_name = options[:environment_name] self.api_host = options[:api_host] || 'api.hawkei.io' self.api_version = options[:api_version] || 'v1' self.proxy_url = options[:proxy_url] self.http_secure = options[:http_secure] || true self.enabled = options[:enabled] || true self.obfuscated_fields = options[:obfuscated_fields] || [] self.metadata = options[:metadata] self.log = options[:log] || true self.logger = FormatedLogger.build(options[:logger]) self.domain = options[:domain] end
Public Instance Methods
valid!()
click to toggle source
validate the configuration Raise when configuration are not valid @return [Boolean] true
# File lib/hawkei/config.rb, line 97 def valid! format! %i[api_key space_name environment_name api_host api_version].each do |field| validate_presence(field) end true end
Private Instance Methods
format!()
click to toggle source
Format configuration fields
-
Set
obfuscated_fields
to string
# File lib/hawkei/config.rb, line 114 def format! self.obfuscated_fields = (obfuscated_fields.map(&:to_s) + DEFAULT_OBFUSCATED_FIELDS).uniq end
validate_presence(field)
click to toggle source
# File lib/hawkei/config.rb, line 118 def validate_presence(field) raise Hawkei::ConfigurationError, "#{field} can't be blank" if send(field).nil? || send(field).empty? end