class RestfulClientConfiguration

Constants

DEFAULT_RETRIES
DEFAULT_TIMEOUT
DEFAULT_USER_AGENT

Attributes

config_folder[RW]
data[RW]
env_name[RW]
legacy_postfix[RW]
report_method[RW]
retries[RW]
timeout[RW]
use_jynx[RW]
user_agent[RW]

Public Instance Methods

env() click to toggle source
# File lib/restful_client_configuration.rb, line 50
def env
  @env_name || 'default'
end
report_on() click to toggle source

Dummy method to test reporting phase

# File lib/restful_client_configuration.rb, line 46
def report_on
  @report_method.call('RestfulClientConfiguration', "Initialized at: #{Time.now.utc}.")
end
reset() click to toggle source
# File lib/restful_client_configuration.rb, line 36
def reset
  @report_method  =    nil
  @timeout        =    nil
  @user_agent     =    nil
  @retries        =    nil
  @use_jynx       =    nil
  @legacy_postfix =    nil
end
run!() click to toggle source
# File lib/restful_client_configuration.rb, line 9
def run!
  fail 'Configuration directory name must be provided' unless config_folder.class.to_s == 'String'
  file_name = ['restful_services.yml', 'rest_api.yml'].each do |name|
    locale_name = File.join(config_folder, name)
    break locale_name if File.file?(locale_name)
  end

  ## Set Default Values
  @report_method ||= proc { |*_args| nil }
  @timeout ||= DEFAULT_TIMEOUT
  @user_agent ||= DEFAULT_USER_AGENT
  @retries ||= DEFAULT_RETRIES
  @legacy_postfix ||= ''
  @use_jynx         = true if @use_jynx.nil?

  @data = YAML.load(ERB.new(File.read(file_name)).result)[env].each do |name, entry|
    next unless entry.key?('url')
    opts = {
      time_window_in_seconds: entry.fetch(:time_window_in_seconds, 20),
      max_errors: entry.fetch(:max_errors, 10),
      grace_period: entry.fetch(:grace_period, 120)
    }

    ServiceJynx.register!(name.gsub(@legacy_postfix, ''), opts) if @use_jynx
  end
end