Sha256: 1784e4226a7ed67535b368da6b49838be410bfc8025b5d4b34270fb9e7833290

Contents?: true

Size: 880 Bytes

Versions: 2

Compression:

Stored size: 880 Bytes

Contents

# encoding: utf-8

require "pathname"
require "desi/local_install"
require "desi/http_client"
require "uri"

module Desi
  class Downloader

    def initialize(opts = {})
      @destination_dir = Pathname(opts.fetch(:destination_dir, Desi::LocalInstall.new))
      @host = URI(opts.fetch(:host, 'http://cloud.github.com/'))
      @client = Desi::HttpClient.new(@host)
      @verbose = opts[:verbose]
    end

    def download!(version, opts = {})
      path = "/downloads/elasticsearch/elasticsearch/#{version.name}"
      destination_name = @destination_dir.join File.basename(version.name)

      raise "ERROR: File #{destination_name} already present!" if destination_name.exist?

      puts "  * fetching release #{version} from #{@host + path}" if @verbose

      File.open(destination_name, 'w') {|f| f << @client.get(path).body }

      destination_name
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
desi-0.1.0 lib/desi/downloader.rb
desi-0.0.2 lib/desi/downloader.rb