Sha256: fd85080dbafc7ebb2f9d3a5c979f4d0781dbc8fb09a24d8bc532a00181a9233b

Contents?: true

Size: 938 Bytes

Versions: 54

Compression:

Stored size: 938 Bytes

Contents

# frozen_string_literal: true

require "net/http"
require "uri"
require "openssl"

module Gemsmith
  module Authenticators
    # An authenticator for retrieving RubyGems authorization.
    class RubyGems
      def self.url
        "https://rubygems.org/api/v1/api_key"
      end

      def initialize login, password
        @login = login
        @password = password
        @uri = URI.parse self.class.url
        @client = configure_client
      end

      def authorization
        request = Net::HTTP::Get.new uri.request_uri
        request.basic_auth login, password
        response = client.request request
        String response.body
      end

      private

      attr_reader :login, :password, :uri, :client

      def configure_client
        Net::HTTP.new(uri.host, uri.port).tap do |client|
          client.use_ssl = true
          client.verify_mode = OpenSSL::SSL::VERIFY_PEER
        end
      end
    end
  end
end

Version data entries

54 entries across 54 versions & 1 rubygems

Version Path
gemsmith-15.5.0 lib/gemsmith/authenticators/ruby_gems.rb
gemsmith-15.4.0 lib/gemsmith/authenticators/ruby_gems.rb
gemsmith-15.3.0 lib/gemsmith/authenticators/ruby_gems.rb
gemsmith-15.2.0 lib/gemsmith/authenticators/ruby_gems.rb
gemsmith-15.1.1 lib/gemsmith/authenticators/ruby_gems.rb
gemsmith-15.1.0 lib/gemsmith/authenticators/ruby_gems.rb
gemsmith-15.0.0 lib/gemsmith/authenticators/ruby_gems.rb
gemsmith-14.11.0 lib/gemsmith/authenticators/ruby_gems.rb
gemsmith-14.10.1 lib/gemsmith/authenticators/ruby_gems.rb
gemsmith-14.10.0 lib/gemsmith/authenticators/ruby_gems.rb
gemsmith-14.9.0 lib/gemsmith/authenticators/ruby_gems.rb
gemsmith-14.8.0 lib/gemsmith/authenticators/ruby_gems.rb
gemsmith-14.7.0 lib/gemsmith/authenticators/ruby_gems.rb
gemsmith-14.6.0 lib/gemsmith/authenticators/ruby_gems.rb
gemsmith-14.5.0 lib/gemsmith/authenticators/ruby_gems.rb
gemsmith-14.4.0 lib/gemsmith/authenticators/ruby_gems.rb
gemsmith-14.3.0 lib/gemsmith/authenticators/ruby_gems.rb
gemsmith-14.2.0 lib/gemsmith/authenticators/ruby_gems.rb
gemsmith-14.1.3 lib/gemsmith/authenticators/ruby_gems.rb
gemsmith-14.1.2 lib/gemsmith/authenticators/ruby_gems.rb