Sha256: 2631f504c4781191ab04168d6e0e5ac082b7e27a644d2c34509d10420f5259cd

Contents?: true

Size: 1.68 KB

Versions: 2

Compression:

Stored size: 1.68 KB

Contents

require 'open-uri'
require 'logging'

module Spigoter
	class PluginCurse
		def initialize(website)
			@url = website # Url of the plugin
			@main_page     # Mainpage content
			@name          # Name of the plugin
			@download_page # Content of the download page
			@download_url  # Download url of the plugin

			raise "Bad URL #{@url}" if @url.match(/^http:\/\/mods.curse.com\/bukkit-plugins\/minecraft\/[a-z\-]+$/).nil?
		end
		def main_page
			return @main_page unless @main_page.nil?
			Log.info "Downloading main page"
			begin
				@main_page = open(@url).read
			rescue
				raise "404 Error, that plugin URL doesn't exists"
			end
			return @main_page
		end
		def download_page
			return @download_page unless @download_page.nil?
			Log.info "Downloading download page"
			begin
				@download_page = open(@url+'/download').read
			rescue
				raise "404 Error, that plugin URL doesn't exists"
			end
			return @download_page
		end
		def download_url
			return @download_url unless @download_url.nil?
			download_page
			Log.info "Parsing download url"
			@download_url = /(?<download_url>http:\/\/addons.curse.cursecdn.com.+\.jar)/.match(@download_page)[:download_url]
		end
		def version
			return @version unless @version.nil?
			main_page
			Log.info "Getting version"
			@version = /Newest File: (?<version>.+)</.match(@main_page)[:version]
		end
		def name
			return @name unless @name.nil?
			Log.info "Getting name"
			@name = /minecraft\/(?<name>.+)/.match(@url)[:name]
		end
		def download
			download_url
			Log.info "Downloading"
			begin
				file = open(@download_url).read
			rescue
				raise "Can't download file for #{name}, #{@download_url}, check internet?"
			end
			return file
		end
	end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
spigoter-0.2.0 lib/spigoter/webapi/curse.rb
spigoter-0.1.2 lib/spigoter/webapi/curse.rb