summaryrefslogtreecommitdiff
path: root/lib/matrix_app_service_web/router.ex
blob: ca37fe0e03b689a901e61cffd83694e23e64806c (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
31
32
33
34
35
36
defmodule MatrixAppServiceWeb.Router do
  @moduledoc """
  Provides the Matrix Application Service API routes.

  https://matrix.org/docs/spec/application_service/r0.1.2
  """

  @doc """
  This macro injects the API routes in a Phoenix router.
  """
  defmacro routes() do
    quote do
      pipeline :matrix_api do
        plug :accepts, ["json"]
        plug MatrixAppServiceWeb.AuthPlug
      end

      path = Application.compile_env(:matrix_app_service, :path, "/")

      scope path, MatrixAppServiceWeb.V1 do
        pipe_through :matrix_api

        put "/transactions/:txn_id", TransactionController, :push

        get "/users/:user_id", UserController, :query
        get "/rooms/:room_alias", RoomController, :query

        get "/thirdparty/protocol/:protocol", ThirdPartyController, :query_protocol
        get "/thirdparty/user/:protocol", ThirdPartyController, :query_users
        get "/thirdparty/location/:protocol", ThirdPartyController, :query_locations
        get "/thirdparty/location", ThirdPartyController, :query_location_by_alias
        get "/thirdparty/user", ThirdPartyController, :query_user_by_id
      end
    end
  end
end