1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
defmodule MatrixAppService.Client do
@moduledoc """
"""
@type client_options :: {:base_url, String.t()} | MatrixAppService.Client.LowLevel.create_opts()
@doc """
"""
@spec client([client_options()]) ::
Polyjuice.Client.LowLevel.t()
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 \\ [], 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, client_options \\ []) do
client(client_options)
|> Polyjuice.Client.Room.create_alias(room_id, room_alias)
end
@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
|