Skip to main content

lib/salemove/http_client/adapter.ex

defmodule Salemove.HttpClient.Adapter do
  @moduledoc """
  Custom Tesla adapter which allows to specify adapter in request options.
  It also allows configuring adapter at runtime, using, for example, environment variables.

  ## Example

      defmodule Search do
        use Salemove.HttpClient, base_url: "http://www.google.com/"
      end

      Search.get("/", adapter: Tesla.Adapter.Finch)
  """

  @doc false
  def call(%{opts: opts} = env, _opts) do
    adapter = Keyword.fetch!(opts, :__adapter)
    adapter_options = Keyword.get(opts, :__adapter_options, [])

    adapter.call(env, adapter_options)
  end
end