| Module | Gem::GemcutterUtilities |
| In: |
lib/rubygems/gemcutter_utilities.rb
|
Add the —key option
# File lib/rubygems/gemcutter_utilities.rb, line 11
11: def add_key_option
12: add_option('-k', '--key KEYNAME', Symbol,
13: 'Use the given API key',
14: 'from ~/.gem/credentials') do |value,options|
15: options[:key] = value
16: end
17: end
# File lib/rubygems/gemcutter_utilities.rb, line 19
19: def api_key
20: if options[:key] then
21: verify_api_key options[:key]
22: else
23: Gem.configuration.rubygems_api_key
24: end
25: end
# File lib/rubygems/gemcutter_utilities.rb, line 47
47: def rubygems_api_request(method, path, host = Gem.host, &block)
48: require 'net/http'
49: host = ENV['RUBYGEMS_HOST'] if ENV['RUBYGEMS_HOST']
50: uri = URI.parse "#{host}/#{path}"
51:
52: say "Pushing gem to #{host}..."
53:
54: request_method = Net::HTTP.const_get method.to_s.capitalize
55:
56: Gem::RemoteFetcher.fetcher.request(uri, request_method, &block)
57: end
# File lib/rubygems/gemcutter_utilities.rb, line 27
27: def sign_in
28: return if Gem.configuration.rubygems_api_key
29:
30: say "Enter your RubyGems.org credentials."
31: say "Don't have an account yet? Create one at http://rubygems.org/sign_up"
32:
33: email = ask " Email: "
34: password = ask_for_password "Password: "
35: say "\n"
36:
37: response = rubygems_api_request :get, "api/v1/api_key" do |request|
38: request.basic_auth email, password
39: end
40:
41: with_response response do |resp|
42: say "Signed in."
43: Gem.configuration.rubygems_api_key = resp.body
44: end
45: end
# File lib/rubygems/gemcutter_utilities.rb, line 73
73: def verify_api_key(key)
74: if Gem.configuration.api_keys.key? key then
75: Gem.configuration.api_keys[key]
76: else
77: alert_error "No such API key. You can add it with gem keys --add #{key}"
78: terminate_interaction 1
79: end
80: end