Merge remote-tracking branch 'pleroma/develop' into alias-router-helpers
[akkoma] / lib / pleroma / gun.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Gun do
6 @callback open(charlist(), pos_integer(), map()) :: {:ok, pid()}
7 @callback info(pid()) :: map()
8 @callback close(pid()) :: :ok
9 @callback await_up(pid, pos_integer()) :: {:ok, atom()} | {:error, atom()}
10 @callback connect(pid(), map()) :: reference()
11 @callback await(pid(), reference()) :: {:response, :fin, 200, []}
12 @callback set_owner(pid(), pid()) :: :ok
13
14 @api Pleroma.Config.get([Pleroma.Gun], Pleroma.Gun.API)
15
16 defp api, do: @api
17
18 def open(host, port, opts), do: api().open(host, port, opts)
19
20 def info(pid), do: api().info(pid)
21
22 def close(pid), do: api().close(pid)
23
24 def await_up(pid, timeout \\ 5_000), do: api().await_up(pid, timeout)
25
26 def connect(pid, opts), do: api().connect(pid, opts)
27
28 def await(pid, ref), do: api().await(pid, ref)
29
30 def set_owner(pid, owner), do: api().set_owner(pid, owner)
31 end