Sha256: 7ebe092eefb5231cef28c513e0e730c9269077c782ebdf86a235f9483db77e47

Contents?: true

Size: 846 Bytes

Versions: 6

Compression:

Stored size: 846 Bytes

Contents

module HTTP
  # Authorization header value builders
  module AuthorizationHeader
    class << self
      # Associate type with given builder.
      # @param [#to_sym] type
      # @param [Class] klass
      # @return [void]
      def register(type, klass)
        builders[type.to_sym] = klass
      end

      # Builds Authorization header value with associated builder.
      # @param [#to_sym] type
      # @param [Object] opts
      # @return [String]
      def build(type, opts)
        klass = builders[type.to_sym]

        fail Error, "Unknown authorization type #{type}" unless klass

        klass.new opts
      end

    private

      # :nodoc:
      def builders
        @builders ||= {}
      end
    end
  end
end

# built-in builders
require 'http/authorization_header/basic_auth'
require 'http/authorization_header/bearer_token'

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
http-0.6.4 lib/http/authorization_header.rb
http-0.6.3 lib/http/authorization_header.rb
http-0.6.2 lib/http/authorization_header.rb
http-0.6.1 lib/http/authorization_header.rb
http-0.6.0 lib/http/authorization_header.rb
http-0.6.0.pre lib/http/authorization_header.rb