rubygems_api_request(method, path, host = nil, allowed_push_host = nil, &block)
public
Creates an RubyGems API to host and path
with the given HTTP
method.
If allowed_push_host metadata is present, then it will only allow
that host.
Show source
def rubygems_api_request(method, path, host = nil, allowed_push_host = nil, &block)
require 'net/http'
self.host = host if host
unless self.host
alert_error "You must specify a gem server"
terminate_interaction 1
end
if allowed_push_host
allowed_host_uri = URI.parse(allowed_push_host)
host_uri = URI.parse(self.host)
unless (host_uri.scheme == allowed_host_uri.scheme) && (host_uri.host == allowed_host_uri.host)
alert_error "#{self.host.inspect} is not allowed by the gemspec, which only allows #{allowed_push_host.inspect}"
terminate_interaction 1
end
end
uri = URI.parse "#{self.host}/#{path}"
request_method = Net::HTTP.const_get method.to_s.capitalize
Gem::RemoteFetcher.fetcher.request(uri, request_method, &block)
end