lib/bukin/providers/bukkit_dl.rb in bukin-0.1.0 vs lib/bukin/providers/bukkit_dl.rb in bukin-0.2.0
- old
+ new
@@ -1,36 +1,30 @@
require 'bukin/utils'
require 'json'
-# Base url used for bukkit downloads
-BUKKIT_DL_BASE = "http://dl.bukkit.org"
-
# Bukkit download api
# Docs: http://dl.bukkit.org/about/
-BUKKIT_DL_API = "#{BUKKIT_DL_BASE}/api/1.0/downloads"
-
-
class Bukin::BukkitDl
- attr_accessor :api_url
+ attr_reader :url
- def initialize(url = BUKKIT_DL_API)
- @api_url = url
- end
+ def initialize(url = 'http://dl.bukkit.org')
+ @url = url
+ end
- def download(name, version)
- url = BUKKIT_DL_BASE + info(name, version)['file']['url']
- download_file(url)
- end
+ def api_url
+ "#{url}/api/1.0/downloads"
+ end
- def info(name, version)
- url = "#{@api_url}/projects/#{name}/view/#{version}/"
- JSON.parse(open(url).read)
- end
+ def download_url
+ url
+ end
- def resolve_build(name, version)
- "build-#{info(name, version)['build_number']}"
- end
+ def download(name, version)
+ url = download_url + info(name, version)['file']['url']
+ download_file(url)
+ end
- def resolve_version(name, version)
- info(name, version)['version']
- end
+ def info(name, version)
+ url = "#{api_url}/projects/#{name}/view/#{version}/"
+ JSON.parse(open(url).read)
+ end
end