Sha256: d8b449cad00e97a3bd41685d672b83ebfb2ad95fb48a9b7379affe1e3c2379d5

Contents?: true

Size: 514 Bytes

Versions: 6

Compression:

Stored size: 514 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

6 entries across 6 versions & 1 rubygems

Version Path
fe_core_ext-0.9.0 lib/fe_core_ext/core_ext/uri.rb
fe_core_ext-0.8.3 lib/fe_core_ext/core_ext/uri.rb
fe_core_ext-0.8.2 lib/fe_core_ext/core_ext/uri.rb
fe_core_ext-0.8.1 lib/fe_core_ext/core_ext/uri.rb
fe_core_ext-0.7.0 lib/fe_core_ext/core_ext/uri.rb
fe_core_ext-0.6.0 lib/fe_core_ext/core_ext/uri.rb