Sha256: 190a1bdc921dc7243184e46f1448214af173b0ecaf2a2de2ec0d2e22ae362f1c

Contents?: true

Size: 744 Bytes

Versions: 16

Compression:

Stored size: 744 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)
      @quiet ? logger.debug(msg) : logger.bullet(msg)
    end

  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
dply-0.3.15 lib/dply/curl.rb
dply-0.3.14 lib/dply/curl.rb
dply-0.3.13 lib/dply/curl.rb
dply-0.3.12 lib/dply/curl.rb
dply-0.3.11 lib/dply/curl.rb
dply-0.3.10 lib/dply/curl.rb
dply-0.3.9 lib/dply/curl.rb
dply-0.3.8 lib/dply/curl.rb
dply-0.3.7 lib/dply/curl.rb
dply-0.3.6 lib/dply/curl.rb
dply-0.3.5 lib/dply/curl.rb
dply-0.3.4 lib/dply/curl.rb
dply-0.3.3 lib/dply/curl.rb
dply-0.3.2 lib/dply/curl.rb
dply-0.3.1 lib/dply/curl.rb
dply-0.3.0 lib/dply/curl.rb