Class: AriFetch::Engine

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ftp_url, username, password, options = {}) ⇒ Engine

Returns a new instance of Engine.



14
15
16
# File 'lib/ari_fetch.rb', line 14

def initialize(ftp_url, username, password, options = {})
  @ftp_url, @username, @password, @options = ftp_url, username, password, options
end

Instance Attribute Details

#ftp_filesObject

Returns the value of attribute ftp_files.



11
12
13
# File 'lib/ari_fetch.rb', line 11

def ftp_files
  @ftp_files
end

#ftp_instanceObject

Returns the value of attribute ftp_instance.



11
12
13
# File 'lib/ari_fetch.rb', line 11

def ftp_instance
  @ftp_instance
end

#ftp_urlObject

Returns the value of attribute ftp_url.



11
12
13
# File 'lib/ari_fetch.rb', line 11

def ftp_url
  @ftp_url
end

#optionsObject

Returns the value of attribute options.



11
12
13
# File 'lib/ari_fetch.rb', line 11

def options
  @options
end

#passwordObject

Returns the value of attribute password.



11
12
13
# File 'lib/ari_fetch.rb', line 11

def password
  @password
end

#read_filesObject

Returns the value of attribute read_files.



11
12
13
# File 'lib/ari_fetch.rb', line 11

def read_files
  @read_files
end

#unread_filesObject

Returns the value of attribute unread_files.



11
12
13
# File 'lib/ari_fetch.rb', line 11

def unread_files
  @unread_files
end

#usernameObject

Returns the value of attribute username.



11
12
13
# File 'lib/ari_fetch.rb', line 11

def username
  @username
end

Instance Method Details

#fetch_vehicles_from_files(how_many = 1) ⇒ Object



30
31
32
# File 'lib/ari_fetch.rb', line 30

def fetch_vehicles_from_files(how_many=1)
  unread_files.first(how_many).map {|file| AriFetch::AriReadFile.where(name: file).first_or_create(data_read: false).fetch_data(ftp_instance, include_cancel?) }.flatten!
end

#loginObject



34
35
36
37
38
39
# File 'lib/ari_fetch.rb', line 34

def 
  ftp_instance.connect(ftp_url, 21)
  ftp_instance.(username, password)
  ftp_instance.passive = true
  ftp_instance.chdir('/')
end