Class: Usps::Imis::Config

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

Overview

API Configuration

Constant Summary collapse

IMIS_ROOT_URL_PROD =
'https://portal.americasboatingclub.org'
IMIS_ROOT_URL_DEV =
'https://abcdev.imiscloud.com'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Config

Returns a new instance of Config.

Yields:

  • (_self)

Yield Parameters:



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/usps/imis/config.rb', line 18

def initialize
  @environment = default_environment
  @imis_id_query_name = ENV.fetch('IMIS_ID_QUERY_NAME', nil)
  @username = ENV.fetch('IMIS_USERNAME', nil)
  @password = ENV.fetch('IMIS_PASSWORD', nil)
  @base_logger = Logger.new($stdout, level: :info)
  @logger = ActiveSupport::TaggedLogging.new(@base_logger)

  yield self if block_given?

  @logger_level = logger.class::SEV_LABEL[logger.level].downcase.to_sym
end

Instance Attribute Details

#environmentObject

Returns the value of attribute environment.



16
17
18
# File 'lib/usps/imis/config.rb', line 16

def environment
  @environment
end

#imis_id_query_nameObject

Returns the value of attribute imis_id_query_name.



15
16
17
# File 'lib/usps/imis/config.rb', line 15

def imis_id_query_name
  @imis_id_query_name
end

#loggerObject

Returns the value of attribute logger.



16
17
18
# File 'lib/usps/imis/config.rb', line 16

def logger
  @logger
end

#logger_levelObject (readonly)

Returns the value of attribute logger_level.



16
17
18
# File 'lib/usps/imis/config.rb', line 16

def logger_level
  @logger_level
end

#passwordObject

Returns the value of attribute password.



15
16
17
# File 'lib/usps/imis/config.rb', line 15

def password
  @password
end

#usernameObject

Returns the value of attribute username.



15
16
17
# File 'lib/usps/imis/config.rb', line 15

def username
  @username
end

Instance Method Details

#filtered_parametersObject

Parameters to filter out of logging



62
# File 'lib/usps/imis/config.rb', line 62

def filtered_parameters = %i[password]

#hostnameObject

Environment-specific API endpoint hostname

Returns:

  • The API hostname for the current environment

Raises:



49
50
51
52
53
54
# File 'lib/usps/imis/config.rb', line 49

def hostname
  return IMIS_ROOT_URL_PROD if environment.production?
  return IMIS_ROOT_URL_DEV if environment.development?

  raise Errors::ConfigError, "Unexpected API environment: #{environment}"
end

#instance_variables_to_inspectObject

Ruby 3.5 instance variable filter



58
# File 'lib/usps/imis/config.rb', line 58

def instance_variables_to_inspect = instance_variables - %i[@password @base_logger @logger]

#silence!Object



41
42
43
# File 'lib/usps/imis/config.rb', line 41

def silence!
  self.logger = Logger.new(nil)
end