Sha256: 118ac96b05584b5a8ef60cf2fc3a83f3d101d4b877b44239e286f52506699ccf

Contents?: true

Size: 858 Bytes

Versions: 2

Compression:

Stored size: 858 Bytes

Contents

# encoding: utf-8

require "desi/http_client"

module Desi
  class Upstream

    class Release < Struct.new(:name, :description, :release_date, :download_url)
      def to_s
        self.name
      end
    end

    def initialize
      @client = Desi::HttpClient.new('https://api.github.com/')
    end

    def releases
      @releases ||= fetch_releases.
        select {|v| v['content_type'] == 'application/gzip' }.
        sort {|a,b| b["name"] <=> a['name'] }.
        map {|v| Release.new(v['name'], v['description'], v['created_at'], v['html_url']) }
    end

    def latest_release
      releases.first
    end

    def find_release(name)
      releases.detect {|r| r.name == name || r.version == name }
    end

    private

    def fetch_releases
      JSON.parse @client.get('/repos/elasticsearch/elasticsearch/downloads').body
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
desi-0.1.0 lib/desi/upstream.rb
desi-0.0.2 lib/desi/upstream.rb