diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/matrix_app_service.ex | 9 | ||||
-rw-r--r-- | lib/matrix_app_service/application.ex | 7 | ||||
-rw-r--r-- | lib/matrix_app_service_web/controllers/v1/room_controller.ex | 8 | ||||
-rw-r--r-- | lib/matrix_app_service_web/controllers/v1/user_controller.ex | 8 | ||||
-rw-r--r-- | lib/matrix_app_service_web/router.ex | 2 |
5 files changed, 26 insertions, 8 deletions
diff --git a/lib/matrix_app_service.ex b/lib/matrix_app_service.ex index 49acd1b..289d276 100644 --- a/lib/matrix_app_service.ex +++ b/lib/matrix_app_service.ex @@ -21,6 +21,7 @@ defmodule MatrixAppService do In your Phoenix Router: ``` + require MatrixAppServiceWeb.Router MatrixAppServiceWeb.Router.routes() ``` @@ -33,20 +34,26 @@ defmodule MatrixAppService do For instance: ``` + @behaviour MatrixAppService.Adapter.Room + @impl MatrixAppService.Adapter.Room def query_alias(room_alias) do # Do something with the room alias # If the room exists, return :ok end + @behaviour MatrixAppService.Adapter.User + @impl MatrixAppService.Adapter.User def query_user(user_id) do # Do something with the user ID # If the user exists, return :ok end + @behaviour MatrixAppService.Adapter.Transaction + @impl MatrixAppService.Adapter.Transaction - def new_event(%MatrixAppService.Event{type: type, content: content}) + def new_event(%MatrixAppService.Event{type: type, content: content}) do # Do something with the event end ``` diff --git a/lib/matrix_app_service/application.ex b/lib/matrix_app_service/application.ex index 57ce521..38f65be 100644 --- a/lib/matrix_app_service/application.ex +++ b/lib/matrix_app_service/application.ex @@ -18,8 +18,11 @@ defmodule MatrixAppService.Application do ] children = - if Application.get_env(:matrix_app_service, :standalone, false) do - [MatrixAppServiceWeb.Endpoint | children] + if Mix.env() == :test do + [ + MatrixAppServiceWeb.TestEndpoint + | children + ] else children end diff --git a/lib/matrix_app_service_web/controllers/v1/room_controller.ex b/lib/matrix_app_service_web/controllers/v1/room_controller.ex index 460bcbf..cc84c48 100644 --- a/lib/matrix_app_service_web/controllers/v1/room_controller.ex +++ b/lib/matrix_app_service_web/controllers/v1/room_controller.ex @@ -11,10 +11,14 @@ defmodule MatrixAppServiceWeb.V1.RoomController do adapter = Application.fetch_env!(:matrix_app_service, :room_adapter) with :ok <- adapter.query_alias(room_alias) do - send_resp(conn, 200, "{}") + conn + |> put_status(200) + |> json("{}") else _ -> - send_resp(conn, 404, "") + conn + |> put_status(404) + |> json("") end end end diff --git a/lib/matrix_app_service_web/controllers/v1/user_controller.ex b/lib/matrix_app_service_web/controllers/v1/user_controller.ex index 9d00f63..bf3aa1e 100644 --- a/lib/matrix_app_service_web/controllers/v1/user_controller.ex +++ b/lib/matrix_app_service_web/controllers/v1/user_controller.ex @@ -11,10 +11,14 @@ defmodule MatrixAppServiceWeb.V1.UserController do adapter = Application.fetch_env!(:matrix_app_service, :user_adapter) with :ok <- adapter.query_user(user_id) do - send_resp(conn, 200, "{}") + conn + |> put_status(200) + |> json("{}") else _ -> - send_resp(conn, 404, "") + conn + |> put_status(404) + |> json("") end end end diff --git a/lib/matrix_app_service_web/router.ex b/lib/matrix_app_service_web/router.ex index ca37fe0..2c2f0ca 100644 --- a/lib/matrix_app_service_web/router.ex +++ b/lib/matrix_app_service_web/router.ex @@ -17,7 +17,7 @@ defmodule MatrixAppServiceWeb.Router do path = Application.compile_env(:matrix_app_service, :path, "/") - scope path, MatrixAppServiceWeb.V1 do + scope path, MatrixAppServiceWeb.V1, as: :matrix do pipe_through :matrix_api put "/transactions/:txn_id", TransactionController, :push |