Class: Rake::GemMaintenance::RubyGemsApiKeyCreator

Inherits:
Object
  • Object
show all
Defined in:
lib/rake/gem/maintenance/ruby_gems_api_key_creator.rb

Overview

Creates a new scoped API key on rubygems.org via the v2 API. Handles OTP header injection and maps HTTP error codes to actionable messages.

Instance Method Summary collapse

Constructor Details

#initialize(host: "https://rubygems.org") ⇒ RubyGemsApiKeyCreator

Returns a new instance of RubyGemsApiKeyCreator.



8
9
10
# File 'lib/rake/gem/maintenance/ruby_gems_api_key_creator.rb', line 8

def initialize(host: "https://rubygems.org")
  @host = host
end

Instance Method Details

#create(username, password, otp: nil) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/rake/gem/maintenance/ruby_gems_api_key_creator.rb', line 12

def create(username, password, otp: nil)
  require "net/http"

  request = build_request(username, password, otp)
  response = http_client.request(request)
  parse_response(response)
end