Sha256: 907c9aa3d73f017112850c915652c5675c5422d25cbb9da88a1d7a7b76364157

Contents?: true

Size: 778 Bytes

Versions: 15

Compression:

Stored size: 778 Bytes

Contents

require 'dply/helper'
require 'fileutils'
require 'tmpdir'

module Dply
  class Curl

    include Helper

    def initialize(quiet = false)
      @quiet = quiet
    end

    def download(url, outfile)
      Dir.mktmpdir "tmp", "./" do |d|
        tmpfile = "#{d}/f"
        log "downloading #{url}"
        http_status = `curl -w "%{http_code}" -f -s -o '#{tmpfile}' '#{url}' `
        exit_status = $?.exitstatus
        if (http_status != "200" || exit_status != 0)
          error "failed to download #{outfile}, http status #{http_status}, exit_status #{exit_status}"
        end
        FileUtils.mv tmpfile, outfile
      end
    end

    private

    def log(msg)
      if @quiet
        logger.debug msg
      else
        logger.bullet msg
      end
    end

  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
dply-0.2.19 lib/dply/curl.rb
dply-0.2.18 lib/dply/curl.rb
dply-0.2.17 lib/dply/curl.rb
dply-0.2.16 lib/dply/curl.rb
dply-0.2.15 lib/dply/curl.rb
dply-0.2.14 lib/dply/curl.rb
dply-0.2.13 lib/dply/curl.rb
dply-0.2.11 lib/dply/curl.rb
dply-0.2.10 lib/dply/curl.rb
dply-0.2.9 lib/dply/curl.rb
dply-0.2.8 lib/dply/curl.rb
dply-0.2.7 lib/dply/curl.rb
dply-0.2.6 lib/dply/curl.rb
dply-0.2.5 lib/dply/curl.rb
dply-0.2.4 lib/dply/curl.rb