Sha256: 2862bdd5238e96a7cdff4fc253fe5691ec171e65e3ac8761761aa6ef694eb63c

Contents?: true

Size: 788 Bytes

Versions: 1

Compression:

Stored size: 788 Bytes

Contents

require 'rest_client'

module GembankClient
  class Resource
    def initialize(key, file, url)
      @key, @file, @url = key, file, url
    end

    def release
      RestClient.post(url, :gem => File.new(@file)) do |response, request, result, &block|
        handle(response, request, result, &block)
      end
    end

    private

    def url
      "#{@url}/push/#{@key}"
    end

    def handle(response, request, result, &block)
      case response.code
      when 200, 202
        puts(response.body)
      when 403, 404, 412
        puts("Server responded with status code #{response.code}")
        puts(response.body) if response.body and response.body.size > 0
        exit response.code
      else
        response.return!(request, result, &block)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gembank_client-0.0.3 lib/gembank_client/resource.rb