class Airenv::Downloader

Public Class Methods

new(uri, simple_name) click to toggle source
# File lib/airenv/downloader.rb, line 9
def initialize(uri, simple_name)
  @uri = URI.parse(uri)
  @simple_name = simple_name
end

Public Instance Methods

archive_exists?() click to toggle source
# File lib/airenv/downloader.rb, line 44
def archive_exists?
  File.exists?(temporary_sdk_file_path)
end
start() click to toggle source
# File lib/airenv/downloader.rb, line 14
def start
  FileUtils.mkdir_p Settings.temporary_sdk_file_directory

  bar = nil

  Net::HTTP.start(@uri.host, @uri.port) do |http|
    request = Net::HTTP::Get.new(@uri.request_uri)

    http.request(request) do |response|
      size = response["Content-Length"].to_f
      bar = ProgressBar.new(@simple_name, size) if bar.blank?

      File.open(temporary_sdk_file_path, "wb") do |file|
        response.read_body do |data|
          file.write data
          bar.set(file.tell)
        end

        if file.tell == size
          bar.finish
        end
      end
    end
  end
end
temporary_sdk_file_path() click to toggle source
# File lib/airenv/downloader.rb, line 40
def temporary_sdk_file_path
  Settings.temporary_sdk_file_path(@simple_name)
end