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

@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

Link to this function

get_room_by_name_or_id(room_name_or_id)

View Source
@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

See Teiserver.Account.UserLib.get_user_by_id/1.

@spec get_user_by_name(String.t()) :: User.t() | nil

See Teiserver.Account.UserLib.get_user_by_name/1.

Link to this function

list_recent_room_messages(room_name_or_id)

View Source
@spec list_recent_room_messages(Teiserver.Communication.Room.id()) :: [
  Teiserver.Communication.RoomMessage.t()
]

See Teiserver.Communication.RoomMessageLib.list_recent_room_messages/1.

Link to this function

maybe_authenticate_user(name, password)

View Source
@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}
Link to this function

register_user(name, email, password)

View Source
@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{}}
Link to this function

send_direct_message(from_id, to_id, content)

View Source
@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.

Link to this function

send_room_message(sender_id, room_id, content)

View Source

See Teiserver.Communication.RoomMessageLib.send_room_message/3.

Link to this function

subscribe_to_room(room_id_or_name)

View Source
@spec subscribe_to_room(
  Teiserver.Communication.Room.id()
  | Teiserver.Communication.Room.t()
  | String.t()
) :: :ok

See Teiserver.Communication.RoomLib.subscribe_to_room/1.

Link to this function

unsubscribe_from_room(room_id_or_name)

View Source
@spec unsubscribe_from_room(
  Teiserver.Communication.Room.id()
  | Teiserver.Communication.Room.t()
  | String.t()
) :: :ok

See Teiserver.Communication.RoomLib.unsubscribe_from_room/1.