summaryrefslogtreecommitdiff
path: root/lib/matrix_app_service/client.ex
diff options
context:
space:
mode:
Diffstat (limited to 'lib/matrix_app_service/client.ex')
-rw-r--r--lib/matrix_app_service/client.ex68
1 files changed, 46 insertions, 22 deletions
diff --git a/lib/matrix_app_service/client.ex b/lib/matrix_app_service/client.ex
index 5cb720d..d806666 100644
--- a/lib/matrix_app_service/client.ex
+++ b/lib/matrix_app_service/client.ex
@@ -1,37 +1,61 @@
defmodule MatrixAppService.Client do
- @type client_options :: [user_id: String.t(), storage: Polyjuice.Client.Storage.t()]
+ @moduledoc """
- @spec client(String.t() | nil, Polyjuice.Client.Storage.t() | nil) ::
+ """
+
+ @type client_options :: {:base_url, String.t()} | MatrixAppService.Client.LowLevel.create_opts()
+
+ @doc """
+
+ """
+ @spec client([client_options()]) ::
Polyjuice.Client.LowLevel.t()
- def client(user_id \\ nil, storage \\ nil) do
- base_url = Application.get_env(:matrix_app_service, :base_url)
- access_token = Application.get_env(:matrix_app_service, :access_token)
-
- Polyjuice.Client.LowLevel.create(base_url,
- access_token: access_token,
- # "@alice:matrix.imago.local",
- user_id: user_id,
- device_id: "Application service",
- storage: storage
- )
+ def client(opts \\ []) do
+ base_url =
+ Keyword.get(opts, :base_url, Application.fetch_env!(:matrix_app_service, :base_url))
+
+ default_opts = [
+ access_token: Application.fetch_env!(:matrix_app_service, :access_token),
+ device_id: "APP_SERVICE"
+ ]
+
+ opts = Keyword.merge(default_opts, opts)
+
+ Polyjuice.Client.LowLevel.create(base_url, opts)
end
+ @doc """
+
+ """
@spec create_room(Keyword.t()) :: {:ok, String.t()} | Any
- def create_room(options) do
- client_with_options(options)
+ def create_room(options \\ [], client_options \\ []) do
+ client(client_options)
|> Polyjuice.Client.Room.create_room(options)
end
+ @doc """
+
+ """
@spec create_alias(String.t(), String.t(), client_options()) :: {:ok, String.t()} | Any
- def create_alias(room_id, room_alias, options \\ []) do
- client_with_options(options)
+ def create_alias(room_id, room_alias, client_options \\ []) do
+ client(client_options)
|> Polyjuice.Client.Room.create_alias(room_id, room_alias)
end
- @spec client(client_options(), Polyjuice.Client.Storage.t()) :: Polyjuice.Client.LowLevel.t()
- defp client_with_options(options) do
- user_id = Keyword.get(options, :user_id, nil)
- storage = Keyword.get(options, :storage, nil)
- client(user_id, storage)
+ @doc """
+
+ """
+ @spec register(Polyjuice.Client.LowLevel.register_opts(), client_options()) :: {:ok, String.t()} | Any
+ def register(opts \\ [], client_options \\ []) do
+ default_opts = [
+ inhibit_login: true,
+ device_id: "APP_SERVICE",
+ initial_device_display_name: "Application Service"
+ ]
+
+ opts = Keyword.merge(default_opts, opts)
+
+ client(client_options)
+ |> Polyjuice.Client.LowLevel.register(opts)
end
end