lib/xftp.rb in xftp-0.2.0.pre.alpha vs lib/xftp.rb in xftp-0.2.1.pre.alpha
- old
+ new
@@ -2,25 +2,16 @@
require 'active_support/core_ext/hash'
require 'configuration'
require 'xftp/version'
require 'xftp/errors'
-require 'xftp/validator/settings'
-require 'xftp/session/ftp'
-require 'xftp/session/sftp'
+require 'xftp/client'
require_relative 'initializers/i18n'
-# The XFTP entry point (facade)
+# Interface unification for FTP/SFTP protocols
module XFTP
- include Errors
-
- SCHEME_ADAPTERS = {
- ftp: XFTP::Session::FTP,
- ftps: XFTP::Session::SFTP
- }
-
# Config accessor
def self.config
@configuration ||= Configuration.new
end
@@ -28,14 +19,10 @@
# @yield the (see #config)
def self.configure
yield config
end
- def self.validator
- @validator ||= Validator::Settings.new
- end
-
# Initiates a new session
#
# @param [String] :url the remote host url
# @param [Hash] settings the connection settings
# @option settings [Hash<Symbol, String>] :credentials the authentication credentials
@@ -44,24 +31,9 @@
# @raise [XFTP::MissingArgument] if some of the required settings are missing
# @raise [XFTP::NotSupportedProtocol] if protocol detected by schema is not supported
#
# @see Net::SSH
# @see Net::FTP
- #
- # @see XFTP::Validator::Settings
- def self.start(url, settings = {}, &block)
- uri = URI.parse(url)
- validator.call!(uri, settings)
- klass = adapter_class(uri.scheme)
- session = klass.new(uri, settings.deep_dup)
- session.start(&block)
- end
-
- private
-
- # Detects a session adapter class
- # @param [String, Symbol] scheme the uri scheme
- # @return [Class] session adapter class
- def self.adapter_class(scheme)
- SCHEME_ADAPTERS[scheme.to_sym] || not_supported_protocol!(scheme)
+ def self.start(url, settings = {}, &callback)
+ Client.start(url, settings, &callback)
end
end