module Rentabox
  DEFAULT_CREDENTIALS_STORE = 'Credential.actual'

  @@config = {}
  cattr_accessor :config

  %i(license_key corp_code user password auth_token).each do |name|
    define_method(name) { credentials_holder.send(name) }
  end

  def success_call
    credentials_holder.success_call if credentials_holder.respond_to?(__method__)
  end

  def failed_call(message, subject = nil)
    credentials_holder.failed_call(message, subject) if credentials_holder.respond_to?(__method__)
  end

  def update_token(new_token)
    credentials_holder.update_token(new_token) if credentials_holder.respond_to?(__method__)
  end

  def track_call(method, body, response)
    stats_holder.track_call(method, body, response) if Rentabox.config[:stats_holder] && stats_holder.respond_to?(__method__)
  end

private
  def credentials_holder
    eval(Rentabox.config[:credentials_holder] || DEFAULT_CREDENTIALS_STORE)
  end

  def stats_holder
    eval(Rentabox.config[:stats_holder])
  end
end

require 'unit_busy_exception'
require 'sl'
require 'ds'
require 'qs'
