Class: Bukin::Bukget
- Inherits:
-
Object
- Object
- Bukin::Bukget
- Defined in:
- lib/bukin/bukget.rb
Overview
BukGet api Docs: bukget.org/pages/docs/API3.html
Constant Summary collapse
- VERSION =
'release'- URL =
'http://api.bukget.org'- SERVER =
'bukkit'
Instance Attribute Summary collapse
-
#server ⇒ Object
readonly
Returns the value of attribute server.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #find(data) ⇒ Object
-
#initialize(url = URL, server = SERVER) ⇒ Bukget
constructor
A new instance of Bukget.
Constructor Details
Instance Attribute Details
#server ⇒ Object (readonly)
Returns the value of attribute server.
10 11 12 |
# File 'lib/bukin/bukget.rb', line 10 def server @server end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
10 11 12 |
# File 'lib/bukin/bukget.rb', line 10 def url @url end |
Instance Method Details
#find(data) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/bukin/bukget.rb', line 21 def find(data) name = data[:name] version = data[:version] || VERSION match = data[:file] ? FileMatch.new(data[:file]) : FileMatch.any info = Bukin.try_get_json("#{@url}/3/plugins/#{CGI.escape(@server)}/"\ "#{CGI.escape(name)}/#{CGI.escape(version)}") raise NoDownloadError.new(name, version) unless info versions = info['versions'] if versions.nil? || versions.empty? # A couple of plugins don't update the 'version' field correctly but # do update the 'dbo_version' field. This attempts to find a # downloadable version with the correct 'dbo_version' field info = Bukin.get_json("#{@url}/3/plugins/#{CGI.escape(@server)}/"\ "#{CGI.escape(name)}") versions = info['versions'].select do |data| data['dbo_version'] == version end raise NoDownloadError.new(name, version) if versions.empty? end # Filter out any plugins that don't match our file name versions = versions.select{|data| match =~ data['filename']} # 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 {|data| jar_filename(data)} || versions.first raise NoDownloadError.new(name, version) unless version_data return version_data['version'], version_data['download'] end |