unnecessary with

This commit is contained in:
Alexander Strizhakov 2020-03-03 15:11:48 +03:00
parent d0e4d3ca3b
commit 05429730e4
No known key found for this signature in database
GPG Key ID: 022896A53AEF1381
1 changed files with 26 additions and 25 deletions

View File

@ -55,16 +55,20 @@ def post(url, body, headers \\ [], options \\ []),
@spec request(atom(), Request.url(), String.t(), Request.headers(), keyword()) :: @spec request(atom(), Request.url(), String.t(), Request.headers(), keyword()) ::
{:ok, Env.t()} | {:error, any()} {:ok, Env.t()} | {:error, any()}
def request(method, url, body, headers, options) when is_binary(url) do def request(method, url, body, headers, options) when is_binary(url) do
with uri <- URI.parse(url), uri = URI.parse(url)
received_adapter_opts <- Keyword.get(options, :adapter, []), received_adapter_opts = Keyword.get(options, :adapter, [])
adapter_opts <- Connection.options(uri, received_adapter_opts), adapter_opts = Connection.options(uri, received_adapter_opts)
options <- put_in(options[:adapter], adapter_opts), options = put_in(options[:adapter], adapter_opts)
params <- Keyword.get(options, :params, []), params = Keyword.get(options, :params, [])
request <- build_request(method, headers, options, url, body, params), request = build_request(method, headers, options, url, body, params)
client <- Tesla.client([Tesla.Middleware.FollowRedirects], tesla_adapter()),
pid <- Process.whereis(adapter_opts[:pool]) do adapter = Application.get_env(:tesla, :adapter)
client = Tesla.client([Tesla.Middleware.FollowRedirects], adapter)
pid = Process.whereis(adapter_opts[:pool])
pool_alive? = pool_alive? =
if tesla_adapter() == Tesla.Adapter.Gun && pid do if adapter == Tesla.Adapter.Gun && pid do
Process.alive?(pid) Process.alive?(pid)
else else
false false
@ -82,7 +86,6 @@ def request(method, url, body, headers, options) when is_binary(url) do
response response
end end
end
@spec request(Client.t(), keyword(), map()) :: {:ok, Env.t()} | {:error, any()} @spec request(Client.t(), keyword(), map()) :: {:ok, Env.t()} | {:error, any()}
def request(%Client{} = client, request, %{env: :test}), do: request_try(client, request) def request(%Client{} = client, request, %{env: :test}), do: request_try(client, request)
@ -138,6 +141,4 @@ defp build_request(method, headers, options, url, body, params) do
|> Builder.add_param(:query, :query, params) |> Builder.add_param(:query, :query, params)
|> Builder.convert_to_keyword() |> Builder.convert_to_keyword()
end end
defp tesla_adapter, do: Application.get_env(:tesla, :adapter)
end end