Verified Commit d76110a5 authored by Pierre de Lacroix's avatar Pierre de Lacroix
Browse files

define client behaviour

parent 006b2c12
Pipeline #234680672 passed with stages
in 3 minutes and 54 seconds
......@@ -5,6 +5,7 @@ defmodule MatrixAppService.Client do
Library users can use the wrapped functions or call `user/1` and pass the
returned struct to Polyjuice functions.
"""
@behaviour MatrixAppService.ClientBehaviour
@type client_options :: {:base_url, String.t()} | MatrixAppService.Client.LowLevel.create_opts()
......@@ -20,8 +21,6 @@ defmodule MatrixAppService.Client do
* `:user_id`: user ID
* `:storage`: a `t:Polyjuice.Client.Storage.t/0`
"""
@spec client([client_options()]) ::
Polyjuice.Client.LowLevel.t()
def client(opts \\ []) do
base_url =
Keyword.get(opts, :base_url) ||
......@@ -54,7 +53,6 @@ defmodule MatrixAppService.Client do
1. `options`: see `Polyjuice.Client.Room.create_room/2`
2. `client_options`: see `client/1`
"""
@spec create_room(Keyword.t()) :: {:ok, String.t()} | Any
def create_room(options \\ [], client_options \\ []) do
client(client_options)
|> Polyjuice.Client.Room.create_room(options)
......@@ -68,7 +66,6 @@ defmodule MatrixAppService.Client do
2. `room_alias`: room alias
3. `client_options`: see `client/1`
"""
@spec create_alias(String.t(), String.t(), client_options()) :: {:ok, String.t()} | Any
def create_alias(room_id, room_alias, client_options \\ []) do
client(client_options)
|> Polyjuice.Client.Room.create_alias(room_id, room_alias)
......@@ -82,7 +79,6 @@ defmodule MatrixAppService.Client do
2. `msg`: see `Polyjuice.Client.Room.send_message/3`
3. `client_options`: see `client/1`
"""
@spec send_message(String.t(), String.t(), client_options()) :: {:ok, String.t()} | Any
def send_message(room_id, msg, client_options \\ []) do
client(client_options)
|> Polyjuice.Client.Room.send_message(room_id, msg)
......@@ -101,8 +97,6 @@ defmodule MatrixAppService.Client do
`"guest"`
2. `client_options`: see `client/1`
"""
@spec register(Polyjuice.Client.LowLevel.register_opts(), client_options()) ::
{:ok, String.t()} | Any
def register(opts \\ [], client_options \\ []) do
default_opts = [
inhibit_login: true,
......
defmodule MatrixAppService.ClientBehaviour do
@moduledoc """
Behaviour defining callbacks implemented in `MatrixAppService.Client`. Can be used to mock the client, for instance with `mox`:
TODO: example
"""
@type client_options :: {:base_url, String.t()} | MatrixAppService.Client.LowLevel.create_opts()
@callback client() ::
Polyjuice.Client.LowLevel.t()
@callback client([client_options()]) ::
Polyjuice.Client.LowLevel.t()
@callback create_room(Keyword.t()) :: {:ok, String.t()} | Any
@callback create_alias(String.t(), String.t(), client_options()) :: {:ok, String.t()} | Any
@callback send_message(String.t(), String.t(), client_options()) :: {:ok, String.t()} | Any
@callback register(Polyjuice.Client.LowLevel.register_opts(), client_options()) ::
{:ok, String.t()} | Any
@callback get_profile(Polyjuice.Client.LowLevel.t(), String.t()) :: {:ok, map()} | any
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment