Sha256: 7acd89856934b610e51f79803280de2a703a21f117be4aaab8f3da7c9582d82a

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

require 'bukin/utils'
require 'json'
require 'cgi'

# BukGet api
# Docs: http://bukget.org/pages/docs/API3.html
class Bukin::Bukget
  attr_reader :url

  def initialize(url = 'http://api.bukget.org')
    @url = url
  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)}"
    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']
    else
      puts info
      raise Bukin::InstallError, "The plugin #{name} (#{version}) has no jar files available for download"
    end

    data
  end

  def jar_extension?(version_data)
    File.extname(version_data['filename']) == '.jar'
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bukin-0.3.0 lib/bukin/providers/bukget.rb