Cauldron2D.Net.Remote (Cauldron2D.Net v0.1.2)

Copy Markdown View Source

What a client asks a server it does not run in: a token for a name and password over HTTP (Cauldron2D.Net.Api), the arenas, the server's stats and boards; and the same from a node it is connected to.

{:ok, token} = Cauldron2D.Net.Remote.login("http://arcade:2280", "alice", "secret", false)
{:ok, arenas} = Cauldron2D.Net.Remote.arenas("http://arcade:2280")
{:ok, arenas} = Cauldron2D.Net.Remote.node_arenas(:"my_game@arcade")
{:ok, world} = Cauldron2D.Net.Remote.node_world(:"my_game@arcade", :pit)

url is the server's base URL with the API's path, http://host:port/api for an API forwarded at /api.

Summary

Functions

The arenas from GET <url>/arenas.

A board from GET <url>/leaders, as Cauldron2D.Ledger.board/4 gives it, accounts as strings.

A token from POST <url>/token; register? makes the account first. {:error, text} with the server's reason.

The arenas of a connected node, as its Cauldron2D.Arenas.list/0 gives them.

A board of a connected node's ledger.

The pid of arena id's world on node, started there if it was not running.

How the server is keeping up, from GET <url>/stats, with atom keys.

Types

arena()

@type arena() :: %{
  id: String.t(),
  name: String.t(),
  map: String.t() | nil,
  note: String.t() | nil,
  players: non_neg_integer(),
  teams: list(),
  kind: {String.t(), {byte(), byte(), byte()}} | nil
}

Functions

arenas(url)

@spec arenas(String.t()) :: {:ok, [arena()]} | {:error, String.t()}

The arenas from GET <url>/arenas.

leaders(url, period, metric, opts \\ [])

@spec leaders(String.t(), atom(), atom(), keyword()) ::
  {:ok, [map()]} | {:error, String.t()}

A board from GET <url>/leaders, as Cauldron2D.Ledger.board/4 gives it, accounts as strings.

login(url, username, password, register?)

@spec login(String.t(), String.t(), String.t(), boolean()) ::
  {:ok, String.t()} | {:error, String.t()}

A token from POST <url>/token; register? makes the account first. {:error, text} with the server's reason.

node_arenas(node)

@spec node_arenas(node()) :: {:ok, [map()]} | {:error, String.t()}

The arenas of a connected node, as its Cauldron2D.Arenas.list/0 gives them.

node_leaders(node, ledger, period, metric, opts \\ [])

@spec node_leaders(node(), GenServer.name(), atom(), atom(), keyword()) ::
  {:ok, [map()]} | {:error, String.t()}

A board of a connected node's ledger.

node_world(node, id)

@spec node_world(node(), term()) :: {:ok, pid()} | {:error, String.t()}

The pid of arena id's world on node, started there if it was not running.

stats(url)

@spec stats(String.t()) ::
  {:ok, %{arenas: [map()], node: map()}} | {:error, String.t()}

How the server is keeping up, from GET <url>/stats, with atom keys.