Sha256: 8d2f154f2995db6e46d3b3270cd3106fe63e6bb317d2e8f4723f757578d72f6e

Contents?: true

Size: 1.62 KB

Versions: 33

Compression:

Stored size: 1.62 KB

Contents

require 'net/http'
require 'fileutils'
require 'rubygems'
require 'zip/zip'


def fetch(uri_str, limit = 10)
  raise ArgumentError, 'HTTP redirect too deep' if limit == 0

  url = URI.parse(uri_str)
  http = Net::HTTP.new(url.host, url.port)
  http.open_timeout = 10
  http.read_timeout = 30
  http.use_ssl = true
  response = http.start do |http|
     puts "getting #{url.path}"
     http.request_get(url.path)
  end
  
  case response
  when Net::HTTPSuccess     then response
  when Net::HTTPRedirection then fetch(response['location'], limit - 1)
  else
    response.error!
  end
end

def install_from_github(user, project, ext_name, branch = "master", working_directory = Dir.pwd)
  download_link = "https://github.com/#{user}/#{project}/zipball/#{branch}"
  extdir = File.join(working_directory,'extensions')
  
  if !File.exists?("#{extdir}/#{ext_name}")
    begin
      puts "Downloading the #{ext_name} plugin into #{extdir}."
      FileUtils.mkdir_p("#{extdir}")
      zipfile = File.join(extdir, "#{ext_name}.zip")
      open(zipfile, "wb") do |tgz|
        tgz << fetch(download_link).body
      end
      puts "Unzipping the #{ext_name} plugin."
      Zip::ZipFile::open(zipfile) { |zf|
         zf.each { |e|
           fpath = File.join(extdir, e.name)
           FileUtils.mkdir_p(File.dirname(fpath))
           zf.extract(e, fpath)
         }
      }
      File.unlink(zipfile)
      funky_directory = Dir.glob(File.join(extdir,"#{user}-#{project}-*"))[0]
      FileUtils.mv(funky_directory, File.join(extdir, ext_name))
      puts "#{ext_name} installed."
    rescue Exception => e
      FileUtils.rm_rf(extdir)
      raise
    end
  end

end

Version data entries

33 entries across 32 versions & 4 rubygems

Version Path
compass-0.12.7 examples/downloader.rb
sadui-0.0.4 vendor/bundle/ruby/2.1.0/gems/compass-0.12.3/examples/downloader.rb
sadui-0.0.4 vendor/bundle/ruby/2.0.0/gems/compass-0.12.3/examples/downloader.rb
compass-0.12.6 examples/downloader.rb
compass-0.12.5 examples/downloader.rb
compass-0.12.4 examples/downloader.rb
compass-0.12.3 examples/downloader.rb
compass-0.13.alpha.12 examples/downloader.rb
compass-0.13.alpha.10 examples/downloader.rb
compass-0.13.alpha.9 examples/downloader.rb
compass-0.13.alpha.8 examples/downloader.rb
compass-0.13.alpha.7 examples/downloader.rb
compass-0.13.alpha.6 examples/downloader.rb
compass-0.13.alpha.5 examples/downloader.rb
compass-sourcemaps-0.12.4.sourcemaps.a4836f1 examples/downloader.rb
compass-0.13.alpha.4 examples/downloader.rb
compass-0.13.alpha.3 examples/downloader.rb
compass-0.13.alpha.2 examples/downloader.rb
compass_extension-0.2.1.rc1 lib/downloader.rb
compass_extension-0.2.1 lib/downloader.rb