class GeminaboxClient
def extract_username_and_password_from_url!(url)
def extract_username_and_password_from_url!(url) uri = URI.parse(url.to_s) @username, @password = uri.user, uri.password uri.user = uri.password = nil uri.path = uri.path + "/" unless uri.path.end_with?("/") @url = uri.to_s end
def initialize(url)
def initialize(url) extract_username_and_password_from_url!(url) @http_client = HTTPClient.new @http_client.set_auth(url_for(:upload), @username, @password) if @username or @password @http_client.www_auth.basic_auth.challenge(url_for(:upload)) # Workaround: https://github.com/nahi/httpclient/issues/63 @http_client.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE end
def push(gemfile)
def push(gemfile) response = http_client.post(url_for(:upload), {'file' => File.open(gemfile, "rb")}, {'Accept' => 'text/plain'}) if response.status < 400 response.body else raise GeminaboxClient::Error, "Error (#{response.code} received)\n\n#{response.body}" end end
def url_for(path)
def url_for(path) url + path.to_s end