summaryrefslogtreecommitdiff
path: root/lib/matrix_app_service_web
diff options
context:
space:
mode:
Diffstat (limited to 'lib/matrix_app_service_web')
-rw-r--r--lib/matrix_app_service_web/auth_plug.ex3
-rw-r--r--lib/matrix_app_service_web/channels/user_socket.ex35
-rw-r--r--lib/matrix_app_service_web/controllers/v1/room_controller.ex8
-rw-r--r--lib/matrix_app_service_web/controllers/v1/third_party_controller.ex2
-rw-r--r--lib/matrix_app_service_web/controllers/v1/transaction_controller.ex8
-rw-r--r--lib/matrix_app_service_web/controllers/v1/user_controller.ex8
-rw-r--r--lib/matrix_app_service_web/router.ex25
-rw-r--r--lib/matrix_app_service_web/telemetry.ex46
-rw-r--r--lib/matrix_app_service_web/views/error_view.ex10
9 files changed, 51 insertions, 94 deletions
diff --git a/lib/matrix_app_service_web/auth_plug.ex b/lib/matrix_app_service_web/auth_plug.ex
index 2d2ae23..a06fd46 100644
--- a/lib/matrix_app_service_web/auth_plug.ex
+++ b/lib/matrix_app_service_web/auth_plug.ex
@@ -1,7 +1,6 @@
defmodule MatrixAppServiceWeb.AuthPlug do
@moduledoc """
- This Plug implements the Application Service authorization,
- as described here:
+ Implements the Application Service authorization as a Plug.
https://matrix.org/docs/spec/application_service/r0.1.2#authorization
"""
diff --git a/lib/matrix_app_service_web/channels/user_socket.ex b/lib/matrix_app_service_web/channels/user_socket.ex
deleted file mode 100644
index ec2e9fb..0000000
--- a/lib/matrix_app_service_web/channels/user_socket.ex
+++ /dev/null
@@ -1,35 +0,0 @@
-defmodule MatrixAppServiceWeb.UserSocket do
- use Phoenix.Socket
-
- ## Channels
- # channel "room:*", MatrixAppServiceWeb.RoomChannel
-
- # Socket params are passed from the client and can
- # be used to verify and authenticate a user. After
- # verification, you can put default assigns into
- # the socket that will be set for all channels, ie
- #
- # {:ok, assign(socket, :user_id, verified_user_id)}
- #
- # To deny connection, return `:error`.
- #
- # See `Phoenix.Token` documentation for examples in
- # performing token verification on connect.
- @impl true
- def connect(_params, socket, _connect_info) do
- {:ok, socket}
- end
-
- # Socket id's are topics that allow you to identify all sockets for a given user:
- #
- # def id(socket), do: "user_socket:#{socket.assigns.user_id}"
- #
- # Would allow you to broadcast a "disconnect" event and terminate
- # all active sockets and channels for a given user:
- #
- # MatrixAppServiceWeb.Endpoint.broadcast("user_socket:#{user.id}", "disconnect", %{})
- #
- # Returning `nil` makes this socket anonymous.
- @impl true
- def id(_socket), do: nil
-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 b236dd2..460bcbf 100644
--- a/lib/matrix_app_service_web/controllers/v1/room_controller.ex
+++ b/lib/matrix_app_service_web/controllers/v1/room_controller.ex
@@ -1,7 +1,13 @@
defmodule MatrixAppServiceWeb.V1.RoomController do
+ @moduledoc """
+ Controller for rooms.
+ """
use MatrixAppServiceWeb, :controller
- def show(conn, %{"room_alias" => room_alias}) do
+ @doc """
+ https://matrix.org/docs/spec/application_service/r0.1.2#get-matrix-app-v1-rooms-roomalias
+ """
+ def query(conn, %{"room_alias" => room_alias}) do
adapter = Application.fetch_env!(:matrix_app_service, :room_adapter)
with :ok <- adapter.query_alias(room_alias) do
diff --git a/lib/matrix_app_service_web/controllers/v1/third_party_controller.ex b/lib/matrix_app_service_web/controllers/v1/third_party_controller.ex
index 6ef00ee..f13d6ec 100644
--- a/lib/matrix_app_service_web/controllers/v1/third_party_controller.ex
+++ b/lib/matrix_app_service_web/controllers/v1/third_party_controller.ex
@@ -1,6 +1,8 @@
defmodule MatrixAppServiceWeb.V1.ThirdPartyController do
use MatrixAppServiceWeb, :controller
+ # TODO
+
def show(conn, _params) do
send_resp(conn, 200, "")
end
diff --git a/lib/matrix_app_service_web/controllers/v1/transaction_controller.ex b/lib/matrix_app_service_web/controllers/v1/transaction_controller.ex
index c2a47e3..b6210ba 100644
--- a/lib/matrix_app_service_web/controllers/v1/transaction_controller.ex
+++ b/lib/matrix_app_service_web/controllers/v1/transaction_controller.ex
@@ -1,4 +1,7 @@
defmodule MatrixAppServiceWeb.V1.TransactionController do
+ @moduledoc """
+ Controller for transactions.
+ """
use MatrixAppServiceWeb, :controller
# %{"access_token" => access_token,
@@ -75,7 +78,10 @@ defmodule MatrixAppServiceWeb.V1.TransactionController do
adapter.new_event(event)
end
- def create(conn, %{"events" => events}) do
+ @doc """
+ https://matrix.org/docs/spec/application_service/r0.1.2#put-matrix-app-v1-transactions-txnid
+ """
+ def push(conn, %{"events" => events}) do
Enum.each(events, &create_event(&1))
send_resp(conn, 200, "{}")
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 2f73ad7..9d00f63 100644
--- a/lib/matrix_app_service_web/controllers/v1/user_controller.ex
+++ b/lib/matrix_app_service_web/controllers/v1/user_controller.ex
@@ -1,7 +1,13 @@
defmodule MatrixAppServiceWeb.V1.UserController do
+ @moduledoc """
+ Controller for users.
+ """
use MatrixAppServiceWeb, :controller
- def show(conn, %{"user_id" => user_id}) do
+ @doc """
+ https://matrix.org/docs/spec/application_service/r0.1.2#get-matrix-app-v1-users-userid
+ """
+ def query(conn, %{"user_id" => user_id}) do
adapter = Application.fetch_env!(:matrix_app_service, :user_adapter)
with :ok <- adapter.query_user(user_id) do
diff --git a/lib/matrix_app_service_web/router.ex b/lib/matrix_app_service_web/router.ex
index 21ccc39..ca37fe0 100644
--- a/lib/matrix_app_service_web/router.ex
+++ b/lib/matrix_app_service_web/router.ex
@@ -1,4 +1,13 @@
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
@@ -11,16 +20,16 @@ defmodule MatrixAppServiceWeb.Router do
scope path, MatrixAppServiceWeb.V1 do
pipe_through :matrix_api
- put "/transactions/:txn_id", TransactionController, :create
+ put "/transactions/:txn_id", TransactionController, :push
- get "/users/:user_id", UserController, :show
- get "/rooms/:room_alias", RoomController, :show
+ get "/users/:user_id", UserController, :query
+ get "/rooms/:room_alias", RoomController, :query
- get "/thirdparty/protocol/:protocol", ThirdPartyController, :show
- get "/thirdparty/user/:protocol", ThirdPartyController, :show
- get "/thirdparty/location/:protocol", ThirdPartyController, :show
- get "/thirdparty/location", ThirdPartyController, :show
- get "/thirdparty/user", ThirdPartyController, :show
+ 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
diff --git a/lib/matrix_app_service_web/telemetry.ex b/lib/matrix_app_service_web/telemetry.ex
deleted file mode 100644
index de3ec2d..0000000
--- a/lib/matrix_app_service_web/telemetry.ex
+++ /dev/null
@@ -1,46 +0,0 @@
-defmodule MatrixAppServiceWeb.Telemetry do
- use Supervisor
- import Telemetry.Metrics
-
- def start_link(arg) do
- Supervisor.start_link(__MODULE__, arg, name: __MODULE__)
- end
-
- @impl true
- def init(_arg) do
- children = [
- {:telemetry_poller, measurements: periodic_measurements(), period: 10_000}
- # Add reporters as children of your supervision tree.
- # {Telemetry.Metrics.ConsoleReporter, metrics: metrics()}
- ]
-
- Supervisor.init(children, strategy: :one_for_one)
- end
-
- def metrics do
- [
- # Phoenix Metrics
- summary("phoenix.endpoint.stop.duration",
- unit: {:native, :millisecond}
- ),
- summary("phoenix.router_dispatch.stop.duration",
- tags: [:route],
- unit: {:native, :millisecond}
- ),
-
- # VM Metrics
- summary("vm.memory.total", unit: {:byte, :kilobyte}),
- summary("vm.total_run_queue_lengths.total"),
- summary("vm.total_run_queue_lengths.cpu"),
- summary("vm.total_run_queue_lengths.io")
- ]
- end
-
- defp periodic_measurements do
- [
- # A module, function and arguments to be invoked periodically.
- # This function must call :telemetry.execute/3 and a metric must be added above.
- # {MatrixAppServiceWeb, :count_users, []}
- ]
- end
-end
diff --git a/lib/matrix_app_service_web/views/error_view.ex b/lib/matrix_app_service_web/views/error_view.ex
index ab705e1..024273f 100644
--- a/lib/matrix_app_service_web/views/error_view.ex
+++ b/lib/matrix_app_service_web/views/error_view.ex
@@ -1,10 +1,19 @@
defmodule MatrixAppServiceWeb.ErrorView do
+ @moduledoc """
+ JSON views for errors.
+ """
use MatrixAppServiceWeb, :view
+ @doc """
+ JSON view for a 401 response status.
+ """
def render("401.json", _assigns) do
%{errcode: "EX.MAP.UNAUTHORIZED"}
end
+ @doc """
+ JSON view for a 403 response status.
+ """
def render("403.json", _assigns) do
%{errcode: "EX.MAP.FORBIDDEN"}
end
@@ -12,6 +21,7 @@ defmodule MatrixAppServiceWeb.ErrorView do
# By default, Phoenix returns the status message from
# the template name. For example, "404.json" becomes
# "Not Found".
+ @doc false
def template_not_found(template, _assigns) do
%{errors: %{detail: Phoenix.Controller.status_message_from_template(template)}}
end