Sha256: 75abd67765195e3a9a03cf252969593995d479e0c9ce00673648f0fad6b34d11

Contents?: true

Size: 518 Bytes

Versions: 1

Compression:

Stored size: 518 Bytes

Contents

require 'uri'
require 'open-uri'
require 'net/http'

module FeCoreExt::CoreExt
end

module URI
  def download(file)
    binary = OpenURI.open_uri(self).read
    ::File.open(file, 'wb') {|f| f.write(binary)}
  end

  def exists?
    req = Net::HTTP.new(host, port)
    req.use_ssl = true if scheme == 'https'
    res = req.request_head(path)
    return URI(res['location']).exists? if %w(301 302).include?(res.code)
    res.code == '200'
  end
end

class URI::Generic
  def basename
    ::File.basename(path)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fe_core_ext-0.12.1 lib/fe_core_ext/core_ext/uri.rb