Class: Auspaynet::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/auspaynet/client.rb

Constant Summary collapse

MONTHS =
%w[Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec].freeze

Instance Method Summary collapse

Constructor Details

#initialize(host) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
14
# File 'lib/auspaynet/client.rb', line 9

def initialize(host)
  @host = host
  @ftp = Net::FTP.new(@host)
  @ftp.
  @ftp.passive = true
end

Instance Method Details

#get(dir, filename) ⇒ Object



16
17
18
19
20
21
# File 'lib/auspaynet/client.rb', line 16

def get(dir, filename)
  @ftp.chdir(dir)
  @ftp.gettextfile(filename, nil)
ensure
  @ftp.chdir('/')
end

#list(dir:, matching_filename:, file_format: 'csv') ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/auspaynet/client.rb', line 23

def list(dir:, matching_filename:, file_format: 'csv')
  @ftp.chdir(dir)
  files = @ftp.nlst.select do |f|
    f.include?(matching_filename) &&
      f.include?(file_format) &&
      f.include?(current_year)
  end

  extract_latest_files(files: files, file_format: file_format)
ensure
  @ftp.chdir('/')
end