diff options
author | Pierre de Lacroix <pierre@pdelacroix.com> | 2020-12-01 13:08:29 +0000 |
---|---|---|
committer | Pierre de Lacroix <pierre@pdelacroix.com> | 2020-12-01 13:08:29 +0000 |
commit | 407d202f4c5a094c5a2e991ab81064e060673905 (patch) | |
tree | 2656048c6d4eb0ea134779a85bb6bd41a1466207 /lib/matrix_app_service.ex | |
parent | Update README.md (diff) | |
parent | add endpoint handled by the library (diff) |
Merge branch 'choose_endpoint' into 'master'
add endpoint handled by the libraryCloses #23
See merge request kazarma/matrix_app_service.ex!12
Diffstat (limited to 'lib/matrix_app_service.ex')
-rw-r--r-- | lib/matrix_app_service.ex | 70 |
1 files changed, 58 insertions, 12 deletions
diff --git a/lib/matrix_app_service.ex b/lib/matrix_app_service.ex index 37697a0..a14fdc6 100644 --- a/lib/matrix_app_service.ex +++ b/lib/matrix_app_service.ex @@ -9,23 +9,13 @@ defmodule MatrixAppService do ``` defp deps do - [...] + # ..., {:matrix_app_service, "~> 0.1.0"} end ``` ## Usage - ### Inject routes - - In your Phoenix Router: - - ``` - require MatrixAppServiceWeb.Router - - MatrixAppServiceWeb.Router.routes() - ``` - ### Write adapters Create one or multiple modules that implement the following modules: @@ -59,10 +49,66 @@ defmodule MatrixAppService do end ``` - ### Write configuration + ### Configure + + #### Option 1: Using the :matrix_app_service supervision tree + + Configuration: ``` config :matrix_app_service, + internal_supervisor: true, + transaction_adapter: App.Matrix.Transaction, + room_adapter: App.Matrix.Room, + user_adapter: App.Matrix.User, + path: "/matrix" + base_url: "http://synapse:8008", + access_token: "access token", + homeserver_token: "homeserver token" + ``` + + #### Option 2: Using the :matrix_app_service endpoint in your own supervision tree + + In your application module: + + ``` + children = [ + # ..., + {MatrixAppServiceWeb.Endpoint, app_service_config()} + ] + + # ... + + defp app_service_config(), do: Application.get_env(:app, :app_service) + ``` + + Configuration: + + ``` + config :app, :app_service, + transaction_adapter: App.Matrix.Transaction, + room_adapter: App.Matrix.Room, + user_adapter: App.Matrix.User, + path: "/matrix" + base_url: "http://synapse:8008", + access_token: "access token", + homeserver_token: "homeserver token" + ``` + + #### Option 3: Using your own endpoint + + In your Phoenix Router: + + ``` + use MatrixAppServiceWeb.Routes + + MatrixAppServiceWeb.Routes.routes(Application.get_env(:app, :app_service)) + ``` + + Configuration: + + ``` + config :app, :app_service, transaction_adapter: App.Matrix.Transaction, room_adapter: App.Matrix.Room, user_adapter: App.Matrix.User, |