Class: LittleFinger::ServerFile
- Inherits:
-
Object
- Object
- LittleFinger::ServerFile
- Defined in:
- lib/little_finger/server_file.rb
Instance Attribute Summary collapse
-
#folder_name ⇒ Object
readonly
Returns the value of attribute folder_name.
-
#ftp_site ⇒ Object
readonly
Returns the value of attribute ftp_site.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Class Method Summary collapse
-
.fetch(file_name) ⇒ Object
Retrieves zipped files from the avatax servers.
Instance Method Summary collapse
- #connect ⇒ Object
- #fetch ⇒ Object
-
#initialize(username, password, ftp_site, file_name) ⇒ ServerFile
constructor
A new instance of ServerFile.
- #retrieve_file(filename) ⇒ Object
- #unzip(zip_file) ⇒ Object
Constructor Details
#initialize(username, password, ftp_site, file_name) ⇒ ServerFile
Returns a new instance of ServerFile.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/little_finger/server_file.rb', line 17 def initialize(username, password, ftp_site, file_name) @username = username @password = password @ftp_site = ftp_site portions = @ftp_site.split("/", 2) @host = portions[0] @folder_name = "" @folder_name = portions[1] if portions.count > 1 @ftp_iface = nil @file_name = file_name end |
Instance Attribute Details
#folder_name ⇒ Object (readonly)
Returns the value of attribute folder_name.
6 7 8 |
# File 'lib/little_finger/server_file.rb', line 6 def folder_name @folder_name end |
#ftp_site ⇒ Object (readonly)
Returns the value of attribute ftp_site.
7 8 9 |
# File 'lib/little_finger/server_file.rb', line 7 def ftp_site @ftp_site end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
5 6 7 |
# File 'lib/little_finger/server_file.rb', line 5 def host @host end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
4 5 6 |
# File 'lib/little_finger/server_file.rb', line 4 def password @password end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
3 4 5 |
# File 'lib/little_finger/server_file.rb', line 3 def username @username end |
Class Method Details
.fetch(file_name) ⇒ Object
Retrieves zipped files from the avatax servers
11 12 13 14 15 |
# File 'lib/little_finger/server_file.rb', line 11 def self.fetch(file_name) settings = LittleFinger::Configuration.configuration[:avatax][:ftp] obj = LittleFinger::ServerFile.new(settings[:username], settings[:password], settings[:ftp_site], file_name) obj.fetch end |
Instance Method Details
#connect ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/little_finger/server_file.rb', line 35 def connect @ftp_iface = ftp = Net::FTP.new(@host) # This HAS to be done when we are connecting to the Windows FTP server for some reason. @ftp_iface.passive = true @ftp_iface.login(@username, @password) @ftp_iface.chdir(@folder_name) if @folder_name.present? end |
#fetch ⇒ Object
29 30 31 32 33 |
# File 'lib/little_finger/server_file.rb', line 29 def fetch() connect zip_file = retrieve_file(@file_name) unzip(zip_file) end |
#retrieve_file(filename) ⇒ Object
43 44 45 46 47 |
# File 'lib/little_finger/server_file.rb', line 43 def retrieve_file(filename) out_file ="/tmp/#{filename}" @ftp_iface.getbinaryfile(filename, out_file) out_file end |
#unzip(zip_file) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/little_finger/server_file.rb', line 49 def unzip(zip_file) file_names = [] zip_obj = Zip::File.open(zip_file) zip_obj.each do |one_file| file_name = File.join(File.dirname(zip_file), one_file.name) # force override one_file.extract(file_name) { true } file_names << file_name end file_names end |