Class Limelight::Util::Downloader
In: lib/limelight/util/downloader.rb
Parent: Object

Methods

Public Class methods

[Source]

    # File lib/limelight/util/downloader.rb, line 16
16:       def self.download(resource)
17:         new.download(resource)
18:       end

[Source]

    # File lib/limelight/util/downloader.rb, line 20
20:       def initialize
21:         Data.establish_data_dirs
22:       end

Public Instance methods

[Source]

    # File lib/limelight/util/downloader.rb, line 24
24:       def download(resource)
25:         uri = URI.parse(resource)
26:         case uri.scheme
27:         when nil, "file"
28:           download_file(uri)
29:         when 'http', 'https'
30:           download_http(uri)
31:         else
32:           raise LimelightException.new("Download failed.  Unhandled URI scheme: #{uri.scheme}")
33:         end
34:       end

[Source]

    # File lib/limelight/util/downloader.rb, line 36
36:       def download_file(uri)
37:         raise LimelightException.new("Download failed.  Not found: #{uri.path}") if !File.exists?(uri.path)
38:         filename = File.basename(uri.path)
39:         destination = find_unused_downloads_filename(filename)
40:         File.copy(uri.path, destination)
41:         return destination
42:       end

[Source]

    # File lib/limelight/util/downloader.rb, line 44
44:       def download_http(uri)
45:         saved_filename = nil
46: 
47:         begin
48:           saved_filename = attempt_http_download(uri)
49:         rescue Exception => e
50:           raise LimelightException.new(e)
51:         end
52: 
53:         return saved_filename
54:       end

[Validate]