Class: Hawkei::Config

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

Overview

Hawkei Config

Represent the Hawkei configuration for the API

Constant Summary collapse

DEFAULT_OBFUSCATED_FIELDS =
%w[
  password
  password_confirmation
  secret
  secret_token
  authenticity_token
  token
  api_key
  access_token
  credit_card_number
  cvv
  ccv
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Config

Initialize and validate the configuration

Parameters:

  • (Hash{Symbol=>Object})


77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# 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. = options[:metadata]
  self.log = options[:log] || true
  self.logger = FormatedLogger.build(options[:logger])
  self.domain = options[:domain]
end

Instance Attribute Details

#api_hostString

Returns API host.

Returns:

  • (String)

    API host



36
37
38
# File 'lib/hawkei/config.rb', line 36

def api_host
  @api_host
end

#api_keyString

Returns API account token.

Returns:

  • (String)

    API account token



24
25
26
# File 'lib/hawkei/config.rb', line 24

def api_key
  @api_key
end

#api_versionString

Returns API version.

Returns:

  • (String)

    API version



40
41
42
# File 'lib/hawkei/config.rb', line 40

def api_version
  @api_version
end

#domainString

Returns domain.

Returns:

  • (String)

    domain



72
73
74
# File 'lib/hawkei/config.rb', line 72

def domain
  @domain
end

#enabledBoolean

Returns service is enable.

Returns:

  • (Boolean)

    service is enable



52
53
54
# File 'lib/hawkei/config.rb', line 52

def enabled
  @enabled
end

#environment_nameString

Returns API environment name.

Returns:

  • (String)

    API environment name



32
33
34
# File 'lib/hawkei/config.rb', line 32

def environment_name
  @environment_name
end

#http_secureBoolean

Returns http secure.

Returns:

  • (Boolean)

    http secure



48
49
50
# File 'lib/hawkei/config.rb', line 48

def http_secure
  @http_secure
end

#logBoolean

Returns enable the logger.

Returns:

  • (Boolean)

    enable the logger



64
65
66
# File 'lib/hawkei/config.rb', line 64

def log
  @log
end

#loggerLogger

Returns logger.

Returns:

  • (Logger)

    logger



68
69
70
# File 'lib/hawkei/config.rb', line 68

def logger
  @logger
end

#metadataHash

Returns metadata to be attach to the payload.

Returns:

  • (Hash)

    metadata to be attach to the payload



60
61
62
# File 'lib/hawkei/config.rb', line 60

def 
  @metadata
end

#obfuscated_fieldsArray[String]

Returns fields to obfuscate.

Returns:

  • (Array[String])

    fields to obfuscate



56
57
58
# File 'lib/hawkei/config.rb', line 56

def obfuscated_fields
  @obfuscated_fields
end

#proxy_urlString

Returns proxy url.

Returns:

  • (String)

    proxy url



44
45
46
# File 'lib/hawkei/config.rb', line 44

def proxy_url
  @proxy_url
end

#space_nameString

Returns API space name.

Returns:

  • (String)

    API space name



28
29
30
# File 'lib/hawkei/config.rb', line 28

def space_name
  @space_name
end

Instance Method Details

#valid!Boolean

validate the configuration Raise when configuration are not valid

Returns:

  • (Boolean)

    true



97
98
99
100
101
102
103
104
105
# 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