Class: Zanders::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/zanders/base.rb

Direct Known Subclasses

Catalog, Inventory, SoapClient

Class Method Summary collapse

Class Method Details

.connect(options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/zanders/base.rb', line 4

def self.connect(options = {})
  requires!(options, :username, :password)

  Net::FTP.open(Zanders.config.ftp_host, options[:username], options[:password]) do |ftp|
    ftp.debug_mode = Zanders.config.debug_mode
    ftp.passive = true

    yield ftp
  end
rescue Net::FTPPermError
  raise Zanders::NotAuthenticated
end

.requires!(hash, *params) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/zanders/base.rb', line 24

def self.requires!(hash, *params)
  params.each do |param|
    if param.is_a?(Array)
      raise ArgumentError.new("Missing required parameter: #{param.first}") unless hash.has_key?(param.first)

      valid_options = param[1..-1]
      raise ArgumentError.new("Parameter: #{param.first} must be one of: #{valid_options.join(', ')}") unless valid_options.include?(hash[param.first])
    else
      raise ArgumentError.new("Missing required parameter: #{param}") unless hash.has_key?(param)
    end
  end
end