Sha256: fd759292977eb0a8689ffeb8c9bb64ef3a7ce9b9270fbec5dbbfeb124740fd41

Contents?: true

Size: 1.52 KB

Versions: 12

Compression:

Stored size: 1.52 KB

Contents

require "httpi/auth/ssl"

module HTTPI
  module Auth

    # = HTTPI::Auth::Config
    #
    # Manages HTTP and SSL auth configuration. Currently supports HTTP basic/digest
    # and SSL client authentication.
    class Config

      # Supported authentication types.
      TYPES = [:basic, :digest, :ssl]

      # Accessor for the HTTP basic auth credentials.
      def basic(*args)
        return @basic if args.empty?

        self.type = :basic
        @basic = args.flatten.compact
      end

      # Returns whether to use HTTP basic auth.
      def basic?
        type == :basic
      end

      # Accessor for the HTTP digest auth credentials.
      def digest(*args)
        return @digest if args.empty?

        self.type = :digest
        @digest = args.flatten.compact
      end

      # Returns whether to use HTTP digest auth.
      def digest?
        type == :digest
      end

      # Returns whether to use HTTP basic or dihest auth.
      def http?
        type == :basic || type == :digest
      end

      # Returns the <tt>HTTPI::Auth::SSL</tt> object.
      def ssl
        @ssl ||= SSL.new
      end

      # Returns whether to use SSL client auth.
      def ssl?
        ssl.present?
      end

      # Shortcut method for returning the credentials for the authentication specified.
      # Returns +nil+ unless any authentication credentials were specified.
      def credentials
        return unless type
        send type
      end

      # Accessor for the authentication type in use.
      attr_accessor :type

    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
httpi-0.7.9 lib/httpi/auth/config.rb
httpi-0.7.8 lib/httpi/auth/config.rb
httpi-0.7.7 lib/httpi/auth/config.rb
httpi-0.7.6 lib/httpi/auth/config.rb
httpi-0.7.5 lib/httpi/auth/config.rb
httpi-0.7.4 lib/httpi/auth/config.rb
httpi-0.7.3 lib/httpi/auth/config.rb
httpi-0.7.2 lib/httpi/auth/config.rb
httpi-0.7.1 lib/httpi/auth/config.rb
httpi-0.7.0 lib/httpi/auth/config.rb
httpi-0.6.1 lib/httpi/auth/config.rb
httpi-0.6.0 lib/httpi/auth/config.rb