summaryrefslogtreecommitdiff
path: root/lib/matrix_app_service_web/routes.ex
diff options
context:
space:
mode:
Diffstat (limited to 'lib/matrix_app_service_web/routes.ex')
-rw-r--r--lib/matrix_app_service_web/routes.ex77
1 files changed, 77 insertions, 0 deletions
diff --git a/lib/matrix_app_service_web/routes.ex b/lib/matrix_app_service_web/routes.ex
new file mode 100644
index 0000000..54f5c83
--- /dev/null
+++ b/lib/matrix_app_service_web/routes.ex
@@ -0,0 +1,77 @@
+defmodule MatrixAppServiceWeb.Routes do
+ @moduledoc """
+ Provides the Matrix Application Service API routes.
+
+ https://matrix.org/docs/spec/application_service/r0.1.2
+ """
+
+ @doc """
+
+ """
+ defmacro __using__(_env) do
+ quote do
+ require unquote(__MODULE__)
+
+ @matrix_app_services 0
+ end
+ end
+
+ @doc """
+ This macro injects the API routes in a Phoenix router.
+ """
+ # defmacro routes(opts \\ [])
+ defmacro routes(:no_config) do
+ quote do
+ pipeline :matrix_app_service do
+ plug :accepts, ["json"]
+ end
+
+ scope "/", MatrixAppServiceWeb.V1, as: :matrix do
+ pipe_through :matrix_app_service
+
+ 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
+
+ defmacro routes(opts) do
+ quote bind_quoted: [opts: opts] do
+ path = Keyword.get(opts, :path, "/")
+ namespace = Keyword.get(opts, :namespace, :matrix)
+ homeserver_token = Keyword.fetch!(opts, :homeserver_token)
+ pipeline_name = String.to_atom("matrix_api_#{@matrix_app_services}")
+
+ pipeline pipeline_name do
+ plug :accepts, ["json"]
+ plug MatrixAppServiceWeb.SetConfigPlug, opts
+ plug MatrixAppServiceWeb.AuthPlug, homeserver_token
+ end
+
+ scope path, MatrixAppServiceWeb.V1, as: namespace do
+ pipe_through pipeline_name
+
+ 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
+
+ @matrix_app_services @matrix_app_services + 1
+ end
+ end
+end