Sha256: be357be6b63d864d3fe1a97d5459e8e99938ca96e77c0d73d4ff026876fce932

Contents?: true

Size: 1.13 KB

Versions: 8

Compression:

Stored size: 1.13 KB

Contents

require "httpi/adapter/httpclient"
require "httpi/adapter/curb"
require "httpi/adapter/net_http"

module HTTPI

  # = HTTPI::Adapter
  #
  # Manages the adapter classes. Currently supports:
  #
  # * httpclient
  # * curb
  module Adapter

    # The default adapter.
    DEFAULT = :httpclient

    # Returns the adapter to use. Defaults to <tt>HTTPI::Adapter::DEFAULT</tt>.
    def self.use
      @use ||= DEFAULT
    end

    # Sets the +adapter+ to use. Raises an +ArgumentError+ unless the +adapter+ exists.
    def self.use=(adapter)
      validate_adapter! adapter
      @use = adapter
    end

    # Returns a memoized +Hash+ of adapters.
    def self.adapters
      @adapters ||= { :httpclient => HTTPClient, :curb => Curb, :net_http => NetHTTP }
    end

    # Returns an +adapter+. Raises an +ArgumentError+ unless the +adapter+ exists.
    def self.find(adapter)
      validate_adapter! adapter
      adapters[adapter]
    end

  private

    # Raises an +ArgumentError+ unless the +adapter+ exists.
    def self.validate_adapter!(adapter)
      raise ArgumentError, "Invalid HTTPI adapter: #{adapter}" unless adapters[adapter]
    end

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
httpi-0.7.4 lib/httpi/adapter.rb
httpi-0.7.3 lib/httpi/adapter.rb
httpi-0.7.2 lib/httpi/adapter.rb
httpi-0.7.1 lib/httpi/adapter.rb
httpi-0.7.0 lib/httpi/adapter.rb
httpi-0.6.1 lib/httpi/adapter.rb
httpi-0.6.0 lib/httpi/adapter.rb
httpi-0.5.0 lib/httpi/adapter.rb