Polyjuice Client v0.4.4 Polyjuice.Client.LowLevel View Source

A lower-level client than Polyjuice.Client.

Compared to Polyjuice.Client, this module:

  • does not manage the access token, user ID, or device ID; whenever these change (e.g. after logging in), the application must create a new client to use the new values
  • does not provide a process for syncing with the server
  • does not ensure that room requests (such as sending messages) are run in a queue
  • does not start any processes

This module would be suitable, for example, for a bot that only sends messages and does not respond to messages.

Link to this section Summary

Link to this section Types

Link to this type

t()

View Source
t() :: %Polyjuice.Client.LowLevel{
  access_token: String.t() | nil,
  application_service: boolean(),
  base_url: URI.t(),
  device_id: String.t() | nil,
  hackney_opts: list(),
  storage: Polyjuice.Client.Storage.t() | nil,
  test: boolean(),
  user_id: String.t() | nil
}

Link to this section Functions

Link to this function

create(base_url, opts \\ [])

View Source
create(base_url :: String.t(), opts :: Keyword.t()) :: t()
This function is deprecated. use `Polyjuice.Client.LowLevel.new/2` instead.
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

new(base_url, opts \\ [])

View Source
new(base_url :: String.t(), opts :: Keyword.t()) :: t()

Create a client.

opts may contain:

  • access_token: (required to make calls that require authorization) the access token to use.
  • user_id: (required by some endpoints) the ID of the user
  • device_id: the device ID
  • storage: (required by sync) the storage backend to use (see Polyjuice.Client.Storage)
  • application_service: whether the client belongs to an Application Service and should make requests as the user specified in the user_id parameter, rather than as the Application Service's user.
  • 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

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"]