architex/lib/matrix_server_web/federation_client.ex
Pim Kunis 1e53776a8d Add federation API
Add signing keys fed API request
2021-08-06 22:03:34 +02:00

23 lines
661 B
Elixir

defmodule MatrixServerWeb.FederationClient do
use Tesla
alias MatrixServerWeb.Endpoint
alias MatrixServerWeb.Router.Helpers, as: RouteHelpers
# TODO: Maybe create database-backed homeserver struct to pass to client function.
@middleware [
{Tesla.Middleware.Headers, [{"Content-Type", "application/json"}]},
Tesla.Middleware.JSON
]
@adapter {Tesla.Adapter.Finch, name: MatrixServerWeb.HTTPClient}
def client(server_name) do
Tesla.client([{Tesla.Middleware.BaseUrl, server_name} | @middleware], @adapter)
end
def get_signing_keys(client) do
Tesla.get(client, RouteHelpers.key_path(Endpoint, :get_signing_keys))
end
end