summaryrefslogtreecommitdiff
path: root/lib/rubygems/gemcutter_utilities.rb
diff options
context:
space:
mode:
-rw-r--r--lib/rubygems/gemcutter_utilities.rb111
1 files changed, 71 insertions, 40 deletions
@@ -1,11 +1,17 @@
require 'rubygems/remote_fetcher'
module Gem::GemcutterUtilities
# TODO: move to Gem::Command
OptionParser.accept Symbol do |value|
value.to_sym
end
##
# Add the --key option
@@ -17,6 +23,9 @@ module Gem::GemcutterUtilities
end
end
def api_key
if options[:key] then
verify_api_key options[:key]
@@ -27,6 +36,47 @@ module Gem::GemcutterUtilities
end
end
def sign_in sign_in_host = self.host
return if Gem.configuration.rubygems_api_key
@@ -55,47 +105,36 @@ module Gem::GemcutterUtilities
end
end
- attr_writer :host
- def host
- configured_host = Gem.host unless
- Gem.configuration.disable_default_gem_server
-
- @host ||=
- begin
- env_rubygems_host = ENV['RUBYGEMS_HOST']
- env_rubygems_host = nil if
- env_rubygems_host and env_rubygems_host.empty?
-
- env_rubygems_host|| configured_host
- end
- end
-
- def rubygems_api_request(method, path, 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 # TODO: question this
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
- def with_response resp, error_prefix = nil
- case resp
when Net::HTTPSuccess then
if block_given? then
- yield resp
else
- say resp.body
end
else
- message = resp.body
message = "#{error_prefix}: #{message}" if error_prefix
say message
@@ -103,13 +142,5 @@ module Gem::GemcutterUtilities
end
end
- def verify_api_key(key)
- if Gem.configuration.api_keys.key? key then
- Gem.configuration.api_keys[key]
- else
- alert_error "No such API key. Please add it to your configuration (done automatically on initial `gem push`)."
- terminate_interaction 1 # TODO: question this
- end
- end
-
end