module Eco module API module Common module Session class Environment include Common::People attr_reader :config, :session attr_reader :api #, :host, :version attr_reader :file_manager, :logger attr_reader :mailer, :sftp, :s3uploader alias_method :fm, :file_manager #@param init [Eco::API::Common::Session::Environment] object to ini the session environment #@param session [Eco::API::Session, nil] the current session def initialize(init = {}, session:) init = init.conf if init.is_a?(Environment) msg = "Expected object Eco::API::Session::Config or Environment. Given: #{init}" raise msg unless init.is_a?(Eco::API::Session::Config) raise "Expected an Eco::API::Session object. Given: #{session}" if session && !session.is_a?(Eco::API::Session) @config = init @session = session @file_manager = Eco::API::Common::Session::FileManager.new(enviro: self) @logger = Eco::API::Common::Session::Logger.new(enviro: self) end def mailer @mailer ||= Eco::API::Common::Session::Mailer.new(enviro: self) end def sftp @sftp ||= Eco::API::Common::Session::SFTP.new(enviro: self) end def s3upoader @s3uploader ||= Eco::API::Common::Session::S3Uploader.new(enviro: self) end def api @api || new_api end def new_api return nil unless config.apis.active_api log_connection = config.logger.log_connection? logg = log_connection ? logger : ::Logger.new(IO::NULL) api = config.api(logg) unless log_connection logger.info("Created connection pointing to '#{config.apis.active_api.host}' in '#{config.apis.active_api.mode}' mode") api.logger.level = ::Logger::UNKNOWN end @api = api api end end end end end end