Polyjuice Util v0.2.2 Polyjuice.Util.URI View Source

Link to this section Summary

Types

t()

For users, room IDs and room aliases, identifier is a string. For events, it is of the form {room_id_or_alias, event_id}. And for media, it is of the form {server, id}.

Functions

Functions for using Matrix URIs

Parse a Matrix URI.

Generate a Matrix URI.

Link to this section Types

Link to this type

t()

View Source
t() :: %Polyjuice.Util.URI{
  identifier: String.t() | {String.t(), String.t()},
  query_params: [{String.t(), String.t()}],
  type: :user | :event | :event_by_room_alias | :room_id | :room_alias | :media
}

For users, room IDs and room aliases, identifier is a string. For events, it is of the form {room_id_or_alias, event_id}. And for media, it is of the form {server, id}.

Link to this section Functions

Link to this function

%Polyjuice.Util.URI{}

View Source (struct)

Functions for using Matrix URIs

Supports matrix.to, matrix:, and mxc: URIs, and supports referencing users, rooms (by ID or alias), events (using room ID or room alias), and media (mxc: URIs only).

Link to this function

parse(uri)

View Source
parse(uri :: String.t() | URI.t()) :: {:ok, t()} | {:error, atom()}

Parse a Matrix URI.

Examples

iex> Polyjuice.Util.URI.parse("matrix:u/hubert:uhoreg.ca")
{:ok, %Polyjuice.Util.URI{
   type: :user,
   identifier: "@hubert:uhoreg.ca",
   query_params: []
}}

iex> Polyjuice.Util.URI.parse("https://matrix.to/#/%40hubert:uhoreg.ca")
{:ok, %Polyjuice.Util.URI{
   type: :user,
   identifier: "@hubert:uhoreg.ca",
   query_params: []
}}
Link to this function

to_string(uri, format \\ :matrix_to)

View Source
to_string(uri :: t(), format :: :matrix | :matrix_to | nil) :: String.t()

Generate a Matrix URI.

format indicates what URI format to generate. Currently, it defaults to matrix_to; in the future when the matrix format is supported by more clients, the default may change to that. If you require a certain format, you should specify it rather than relying on the default behaviour. :media URIs will always be mxc: URIs, regardless of the format.

Examples

iex> Polyjuice.Util.URI.to_string(
...>   %Polyjuice.Util.URI{type: :user, identifier: "@hubert:uhoreg.ca"},
...>   :matrix
...> )
"matrix:u/hubert%3Auhoreg.ca"

iex> Polyjuice.Util.URI.to_string(
...>   %Polyjuice.Util.URI{type: :user, identifier: "@hubert:uhoreg.ca"},
...>   :matrix_to
...> )
"https://matrix.to/#/%40hubert%3Auhoreg.ca"