summaryrefslogtreecommitdiff
path: root/lib/matrix_app_service/client.ex
blob: b1a73caf4472dc90a154a21d1dd87b21ac05ee29 (plain) (blame)
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
defmodule MatrixAppService.Client do
  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
    })
  end

  def create_room(options) do
    client_with_options(options)
    |> Polyjuice.Client.Room.create_room(options)
  end

  def create_alias(room_id, room_alias, options \\ []) do
    client_with_options(options)
    |> Polyjuice.Client.Room.create_alias(room_id, room_alias)
  end

  defp client_with_options(options) do
    user_id = Keyword.get(options, :user_id, nil)
    storage = Keyword.get(options, :storage, nil)
    client(user_id, storage)
  end
end