Sha256: 755a0133d4356dc1b4b32d0952b8521673e9b96e894791f53f815663bb93c338

Contents?: true

Size: 621 Bytes

Versions: 2

Compression:

Stored size: 621 Bytes

Contents

module Dl
  def self.download(url, raw = false)
    session = Patron::Session.new

    output "Downloading #{url}..."

    begin
      response = session.get url
    rescue Patron::Error => e
      $stderr.puts e.message
      exit 1
    end

    if raw == true
      puts response.body
    else
      if Dl::file != nil
        filename = Dl::file
      else
        filename = response.url.split('/').pop
      end
      output "Downloaded to file #{filename}!"
      File.new(filename, 'w').write(response.body)
    end
  end

  private

  def self.output(string)
    puts string unless Dl::be_quiet == true
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dl-1.2.3 lib/dl/dl.rb
dl-1.2.2 lib/dl/dl.rb