Polyjuice Client v0.4.4 Polyjuice.Client View Source

Matrix client functions.

The client created by this module, or any client that implements the Polyjuice.Client.API protocol, can be used to connect to a Matrix server using the functions from submodules.

The client defined in this module should work for most cases. If you want more control, you can use Polyjuice.Client.LowLevel instead.

To start a client with this module, create a process using start/2 or start_link/2, and then call get_client/1 to get a struct that can be used with the above modules. To stop the client, use Polyjuice.Client.API.stop/3.

Link to this section Summary

Types

t()

Matrix client.

Functions

Returns a specification to start this under a supervisor.

Get a struct that implements Polyjuice.Client.API from the pid given by start/2 or start_link/2.

Log out an existing session.

Register a user.

Start a client.

Start the client process and return both the PID and the client struct.

Synchronize messages from the server.

Get the spec versions supported by the server.

Link to this section Types

Matrix client.

This struct can be obtained by calling get_client/1 after the client process has been started with start/2 or start_link/2, and implements Polyjuice.Client.API protocol.

Link to this section Functions

Returns a specification to start this under a supervisor.

arg is a list where the first element is the server's base URL, and the remainder of the list are options as document in start_link/2.

Link to this function

get_client(pid)

View Source
get_client(pid :: pid()) :: t()

Get a struct that implements Polyjuice.Client.API from the pid given by start/2 or start_link/2.

Link to this function

log_in_with_password(client, identifier, password, opts \\ [])

View Source
log_in_with_password(
  client :: t(),
  identifier :: String.t() | tuple() | map(),
  password :: String.t(),
  opts :: list()
) :: {:ok, map()} | any()

Log in with a password.

identifier may be a single string (in which case it represents a username -- either just the localpart or the full MXID), a tuple of the form {:email, "email@address"}, a tuple of the form {:phone, "country_code", "phone_number"}, or a map that is passed directly to the login endpoint.

opts is a keyword list of options:

  • device_id: (string) the device ID to use
  • initial_device_display_name: (string) the display name to use for the device
Link to this function

log_out(client)

View Source
log_out(client :: t()) :: :ok | any()

Log out an existing session.

Link to this function

register(client, opts \\ [])

View Source
register(client :: t(), opts :: list()) :: {:ok, map()} | any()

Register a user.

opts is a keyword list of options:

  • username: (string) the basis for the localpart of the desired Matrix ID
  • auth is the authentication map containing the type of authentication type and sometime the session key
  • password: (string) the desired password for the account
  • device_id: (string) the device ID to use
  • initial_device_display_name: (string) the display name to use for the device
  • inhibit_login: (boolean) don't login after successful register
  • kind: (atom) kind of account to register. Defaults to user. One of: ["guest", "user"]
Link to this function

start(base_url, opts \\ [])

View Source
start(base_url :: String.t(), opts :: Keyword.t()) :: {:ok, pid()}

Start a client.

See start_link/2.

Link to this function

start_link(base_url, opts \\ [])

View Source
start_link(base_url :: String.t(), opts :: Keyword.t()) ::
  {:ok, pid()} | {:error, any()}

Start a client.

opts may contain:

  • access_token: (required to make calls that require authorization, but may be omitted if using a storage that was previously used when logging in and contains the access token) the access token to use.
  • user_id: (required by some endpoints, but may be omitted if using a storage that was previously used when logging in and contains the user ID) the ID of the user
  • device_id: (required by some endpoints, but may be omitted if using a storage that was previously used when logging in and contains the device ID) the device ID
  • storage: (required for sync) the storage backend to use (see Polyjuice.Client.Storage)
  • handler: (required for sync) an event handler (see Polyjuice.Client.Handler)
  • sync: whether to start a sync process (defaults to true). The sync process will not start if there is no storage or handler provided.
  • sync_filter: the filter to use for the sync. Defaults to no filter.
  • proxy: use a proxy to connect to the homeserver. This may be of the form {:http, host, port} or {:http, host, port, user, pass} for HTTP proxies, or {:socks5, host, port} or {:socks5, host, port, user, pass} for SOCKS5 proxies.
  • ssl_options: SSL/TLS options. This is a list of tls_client_options as defined at https://erlang.org/doc/man/ssl.html
  • follow_redirect: whether redirects should be automatically followed. May either a number indicating the maximum number of redirects to follow, or true, meaning that redirects should be followed up to a default maximum number.
Link to this function

sync(client_api, opts \\ [])

View Source
sync(client_api :: Polyjuice.Client.API.t(), opts :: list()) ::
  {:ok, map()} | any()

Synchronize messages from the server.

Normally, you should use Polyjuice.Client's built-in sync process rather than calling this function, but this function may be used where more control is needed.

opts is a keyword list of options:

  • filter: (string or map) a filter to apply to the sync. May be either the ID of a previously uploaded filter, or a new filter.
  • since: (string) where to start the sync from. Should be a token obtained from the next_batch of a previous sync.
  • full_state: (boolean) whether to return the full room state instead of just the state that has changed since the last sync
  • set_presence: (one of :online, :offline, or :unavailable) the user's presence to set with this sync
  • timeout: (integer) the number of milliseconds to wait before the server returns
Link to this function

versions(client_api)

View Source
versions(client_api :: Polyjuice.Client.API.t()) :: {:ok, map()} | any()

Get the spec versions supported by the server.