lib/bukin/providers/bukget.rb in bukin-0.5.0 vs lib/bukin/providers/bukget.rb in bukin-0.6.0
- old
+ new
@@ -1,50 +1,54 @@
-require 'bukin/utils'
require 'json'
require 'cgi'
# BukGet api
# Docs: http://bukget.org/pages/docs/API3.html
class Bukin::Bukget
- attr_reader :url
+ DEFAULT_URL = 'http://api.bukget.org'
+ attr_reader :data
- def initialize(url = 'http://api.bukget.org')
- @url = url
+ def initialize(data)
+ @data = data
end
- def api_url
- "#{url}/3"
- end
-
- def resolve_info(data)
- return data if data[:download]
-
- name = data[:name]
- version = data[:version] || 'latest'
- server = data[:server]
- server = 'bukkit' if server == 'craftbukkit'
-
- url = "#{api_url}/plugins/#{CGI.escape(server)}/#{CGI.escape(name)}/#{CGI.escape(version)}"
+ def resolve_info
info = JSON.parse(open(url).read)
-
versions = info['versions']
if versions.empty?
raise Bukin::InstallError, "The plugin #{name} (#{version}) has no available downloads from BukGet."
end
- version_data = versions.find {|version_data| jar_extension?(version_data)}
- if version_data
- data[:version] = version_data['version']
- data[:download] = version_data['download']
+ # Some people release two of the same version on bukkit
+ # dev, one as a zip package and one with the jar only.
+ # This downloads the jar only version by default.
+ version_data = versions.find {|version_data| jar_extension?(version_data)} || versions.first
+ data[:version] = version_data['version']
+ data[:download] = version_data['download']
+ data
+ end
+
+ def url
+ "#{data[:bukget]}/3/plugins/#{CGI.escape(server)}/#{CGI.escape(name)}/#{CGI.escape(version)}"
+ end
+
+ def name
+ data[:name]
+ end
+
+ def version
+ data[:version] || 'latest'
+ end
+
+ def server
+ if data[:server].nil? || data[:server] == 'craftbukkit'
+ 'bukkit'
else
- data[:version] = versions.first['version']
- data[:download] = versions.first['download']
+ data[:server]
end
-
- data
end
+private
def jar_extension?(version_data)
File.extname(version_data['filename']) == '.jar'
end
-
end