Module: URI

Defined in:
lib/fe_core_ext/core_ext/uri.rb

Defined Under Namespace

Classes: Generic

Instance Method Summary collapse

Instance Method Details

#download(file) ⇒ Object



9
10
11
12
# File 'lib/fe_core_ext/core_ext/uri.rb', line 9

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

#exists?Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
20
# File 'lib/fe_core_ext/core_ext/uri.rb', line 14

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