class Gems::BasicAuthenticator

Authenticator for HTTP basic authentication @api private

Attributes

The password @api private @return [String] the password @example Get the password

authenticator.password

The username @api private @return [String] the username @example Get the username

authenticator.username

Public Class Methods

Initialize a new BasicAuthenticator

@api private @param username [String] the username @param password [String] the password @return [BasicAuthenticator] a new instance @example Create a basic authenticator

authenticator = Gems::BasicAuthenticator.new(username: "nick@gemcutter.org", password: "schwwwwing")
# File lib/gems/basic_authenticator.rb, line 31
def initialize(username:, password:)
  @username = username
  @password = password
end

Public Instance Methods

Generate the authentication headers for a request

@api private @param _request [Net::HTTPRequest] the HTTP request @return [Hash{String => String}] the authentication headers with basic credentials @example Generate a basic authentication header

authenticator.header(request)
# File lib/gems/basic_authenticator.rb, line 43
def header(_request)
  {AUTHENTICATION_HEADER => "Basic #{["#{username}:#{password}"].pack("m0")}"}
end

Summarize the authenticator for the console

@api private @return [String] the summary, which includes the username but not the password @example Inspect a basic authenticator

authenticator.inspect # => #<Gems::BasicAuthenticator username="nick@gemcutter.org">
# File lib/gems/basic_authenticator.rb, line 53
def inspect
  "#<#{self.class} username=#{username.inspect}>"
end