Merge branch 'develop' into issue/1276
[akkoma] / lib / pleroma / gun / gun.ex
index da82983b1eed79db5c31f163956b4365e9e4571a..4043e488047a0716db3fa6f1b2250e529fe30106 100644 (file)
@@ -1,48 +1,31 @@
 # Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Gun do
-  @behaviour Pleroma.Gun.API
+  @callback open(charlist(), pos_integer(), map()) :: {:ok, pid()}
+  @callback info(pid()) :: map()
+  @callback close(pid()) :: :ok
+  @callback await_up(pid, pos_integer()) :: {:ok, atom()} | {:error, atom()}
+  @callback connect(pid(), map()) :: reference()
+  @callback await(pid(), reference()) :: {:response, :fin, 200, []}
+  @callback set_owner(pid(), pid()) :: :ok
 
-  alias Pleroma.Gun.API
+  @api Pleroma.Config.get([Pleroma.Gun], Pleroma.Gun.API)
 
-  @gun_keys [
-    :connect_timeout,
-    :http_opts,
-    :http2_opts,
-    :protocols,
-    :retry,
-    :retry_timeout,
-    :trace,
-    :transport,
-    :tls_opts,
-    :tcp_opts,
-    :socks_opts,
-    :ws_opts
-  ]
+  defp api, do: @api
 
-  @impl API
-  def open(host, port, opts \\ %{}), do: :gun.open(host, port, Map.take(opts, @gun_keys))
+  def open(host, port, opts), do: api().open(host, port, opts)
 
-  @impl API
-  defdelegate info(pid), to: :gun
+  def info(pid), do: api().info(pid)
 
-  @impl API
-  defdelegate close(pid), to: :gun
+  def close(pid), do: api().close(pid)
 
-  @impl API
-  defdelegate await_up(pid, timeout \\ 5_000), to: :gun
+  def await_up(pid, timeout \\ 5_000), do: api().await_up(pid, timeout)
 
-  @impl API
-  defdelegate connect(pid, opts), to: :gun
+  def connect(pid, opts), do: api().connect(pid, opts)
 
-  @impl API
-  defdelegate await(pid, ref), to: :gun
+  def await(pid, ref), do: api().await(pid, ref)
 
-  @spec flush(pid() | reference()) :: :ok
-  defdelegate flush(pid), to: :gun
-
-  @impl API
-  defdelegate set_owner(pid, owner), to: :gun
+  def set_owner(pid, owner), do: api().set_owner(pid, owner)
 end