Class: LiveQA::Config

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

Overview

LiveQA Config

Represent the LiveQA configuration for the API

Constant Summary collapse

ASYNC_HANDLERS =
{
  sidekiq: {
    class:   'LiveQA::AsyncHandlers::Sidekiq',
    require: 'liveqa/async_handlers/sidekiq'
  }
}.freeze
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})


68
69
70
71
72
73
74
75
76
77
78
# File 'lib/liveqa/config.rb', line 68

def initialize(options = {})
  self.api_key           = options[:api_key]
  self.api_host          = options[:api_host] || 'api.liveqa.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.async_handler     = options[:async_handler]
  self.async_options     = options[:async_options] || {}
end

Instance Attribute Details

#api_hostString

Returns API host.

Returns:

  • (String)

    API host



35
36
37
# File 'lib/liveqa/config.rb', line 35

def api_host
  @api_host
end

#api_keyString

Returns API key.

Returns:

  • (String)

    API key



31
32
33
# File 'lib/liveqa/config.rb', line 31

def api_key
  @api_key
end

#api_versionString

Returns API version.

Returns:

  • (String)

    API version



39
40
41
# File 'lib/liveqa/config.rb', line 39

def api_version
  @api_version
end

#async_handlerNull|Symbol|Proc

Returns asynchronous handler.

Returns:

  • (Null|Symbol|Proc)

    asynchronous handler



59
60
61
# File 'lib/liveqa/config.rb', line 59

def async_handler
  @async_handler
end

#async_optionsHash

Returns options for asynchronous handler.

Returns:

  • (Hash)

    options for asynchronous handler



63
64
65
# File 'lib/liveqa/config.rb', line 63

def async_options
  @async_options
end

#enabledBoolean

Returns service is enable.

Returns:

  • (Boolean)

    service is enable



51
52
53
# File 'lib/liveqa/config.rb', line 51

def enabled
  @enabled
end

#http_secureBoolean

Returns http secure.

Returns:

  • (Boolean)

    http secure



47
48
49
# File 'lib/liveqa/config.rb', line 47

def http_secure
  @http_secure
end

#obfuscated_fieldsArray[String]

Returns fields to obfuscate.

Returns:

  • (Array[String])

    fields to obfuscate



55
56
57
# File 'lib/liveqa/config.rb', line 55

def obfuscated_fields
  @obfuscated_fields
end

#proxy_urlString

Returns proxy url.

Returns:

  • (String)

    proxy url



43
44
45
# File 'lib/liveqa/config.rb', line 43

def proxy_url
  @proxy_url
end

Instance Method Details

#valid!Boolean

validate the configuration Raise when configuration are not valid

Returns:

  • (Boolean)

    true



84
85
86
87
88
89
90
91
92
# File 'lib/liveqa/config.rb', line 84

def valid!
  format!

  %i[api_key api_host api_version].each do |field|
    validate_presence(field)
  end

  true
end