View Source Teiserver.Api (Teiserver v0.0.3)
A set of functions for a basic usage of Teiserver. The purpose is to allow you to start with importing only this module and then import others as your needs grow more complex.
Summary
Functions
Makes use of Teiserver.Connections.ClientLib.connect_user/1
to connect
and then also subscribes you to the following pubsubs
Takes a name and password, tries to authenticate the user.
Takes a name, email and password. Creates a user with them.
Functions
@spec connect_user(Teiserver.user_id()) :: :ok
Makes use of Teiserver.Connections.ClientLib.connect_user/1
to connect
and then also subscribes you to the following pubsubs:
Always returns :ok
@spec get_room_by_name_or_id(Teiserver.Communication.Room.name_or_id()) :: Teiserver.Communication.Room.t() | nil
See Teiserver.Communication.RoomLib.get_room_by_name_or_id/1
.
@spec get_user_by_id(Teiserver.user_id()) :: User.t() | nil
@spec get_user_by_name(String.t()) :: User.t() | nil
@spec list_recent_room_messages(Teiserver.Communication.Room.id()) :: [ Teiserver.Communication.RoomMessage.t() ]
See Teiserver.Communication.RoomMessageLib.list_recent_room_messages/1
.
@spec maybe_authenticate_user(String.t(), String.t()) :: {:ok, Teiserver.Account.User.t()} | {:error, :no_user | :bad_password}
Takes a name and password, tries to authenticate the user.
Examples
iex> maybe_authenticate_user("Alice", "password1")
{:ok, %User{}}
iex> maybe_authenticate_user("Bob", "bad password")
{:error, :bad_password}
iex> maybe_authenticate_user("Chris", "password1")
{:error, :no_user}
@spec register_user(String.t(), String.t(), String.t()) :: {:ok, User.t()} | {:error, Ecto.Changeset.t()}
Takes a name, email and password. Creates a user with them.
Examples
iex> register_user("Alice", "alice@alice", "password1")
{:ok, %User{}}
iex> register_user("Bob", "bob@bob", "1")
{:error, %Ecto.Changeset{}}
@spec send_direct_message(Teiserver.user_id(), Teiserver.user_id(), String.t()) :: {:ok, Teiserver.Communication.DirectMessage.t()} | {:error, Ecto.Changeset.t()}
See Teiserver.Communication.DirectMessageLib.send_direct_message/3
.
@spec send_room_message( Teiserver.user_id(), Teiserver.Communication.Room.id(), String.t() ) :: {:ok, Teiserver.Communication.RoomMessage.t()} | {:error, Ecto.Changeset.t()}
See Teiserver.Communication.RoomMessageLib.send_room_message/3
.
@spec subscribe_to_room( Teiserver.Communication.Room.id() | Teiserver.Communication.Room.t() | String.t() ) :: :ok
@spec unsubscribe_from_room( Teiserver.Communication.Room.id() | Teiserver.Communication.Room.t() | String.t() ) :: :ok
See Teiserver.Communication.RoomLib.unsubscribe_from_room/1
.