Sha256: b40ab21770f88e4c1d5b1bb79e2185967474b8712183b695a348cc5537dac139

Contents?: true

Size: 1.8 KB

Versions: 9

Compression:

Stored size: 1.8 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, :ntlm]

      # 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

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

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

      # Returns whether to use NTLM auth.
      def ntlm?
        type == :ntlm
      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

9 entries across 9 versions & 4 rubygems

Version Path
regenersis-httpi-0.9.6 lib/httpi/auth/config.rb
httpi-ntlm-0.9.6 lib/httpi/auth/config.rb
search_biomodel-1.0.0 search_biomodel/ruby/1.8/gems/httpi-0.9.4/lib/httpi/auth/config.rb
httpi-0.9.4 lib/httpi/auth/config.rb
httpi-0.9.3 lib/httpi/auth/config.rb
httpi-0.9.2 lib/httpi/auth/config.rb
httpi-0.9.1 lib/httpi/auth/config.rb
httpi-0.9.0 lib/httpi/auth/config.rb
httpi-0.8.0 lib/httpi/auth/config.rb