Sha256: 521a0987fbe7a5a02b8f4d88e7adeebd1c3a218e0716fe81367cbeb0f7b64126

Contents?: true

Size: 764 Bytes

Versions: 10

Compression:

Stored size: 764 Bytes

Contents

require 'rest-client'

module Bukkit
	class Server
		# Download a file from a URI.
		def self.download(uri, options = {}) # Options: { :filename => "filename.ext" }
			# Get the filename. If it isn't defined, derive it from the URI.
			if options[:filename]
				filename = options[:filename]
			else
				filename = uri.split("\/").last
			end

			# Give some friendly output.
			puts "Downloading: ".yellow + filename
			puts "       From: ".yellow + uri
			puts "(This may take a while depending on your internet connection.)".light_yellow

			# Download the file.
			data = RestClient.get(uri)
			File.open(filename, "wb") do |file|
				file.write(data)
			end
			# => filename.ext

			puts filename.light_green + " successfully downloaded!".green
		end
	end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
bukkit-2.4.2 lib/bukkit/download.rb
bukkit-2.4.0 lib/bukkit/download.rb
bukkit-2.3.2 lib/bukkit/download.rb
bukkit-2.3.1 lib/bukkit/download.rb
bukkit-2.3.0 lib/bukkit/download.rb
bukkit-2.2.0 lib/bukkit/download.rb
bukkit-2.1.3 lib/bukkit/download.rb
bukkit-2.1.2 lib/bukkit/download.rb
bukkit-2.1.1 lib/bukkit/download.rb
bukkit-2.1.0 lib/bukkit/download.rb