libduvet/http/client

Types

A client for the API: the session’s tokens, the router, the transport and the throttles for read acks.

pub opaque type RestClient

Values

pub fn ack_conversation(
  client: RestClient,
  conversation_id: String,
  message_id: String,
) -> Nil

Marks the conversation read up to [message_id], as [ack_room] does.

pub fn ack_room(
  client: RestClient,
  room_id: String,
  message_id: String,
) -> Nil

Marks the room read up to [message_id]. Acks go out at most once per room every [ack.ack_interval], with the newest message ID; failures are ignored.

pub fn auth_mode(client: RestClient) -> core.AuthMode

How the client authenticates its requests and its gateway socket.

pub fn commands_cache(client: RestClient) -> commands.Cache
pub fn default_meta(client: RestClient) -> core.Meta(a)
pub fn dispose(client: RestClient) -> Nil
pub fn is_authenticated(client: RestClient) -> Bool
pub fn is_bot(client: RestClient) -> Bool

Whether this client authenticates as a bot.

pub fn log_in(
  client: RestClient,
  email: String,
  password: String,
) -> Result(sign_in.SignIn, error.DuvetError)
pub fn log_out(client: RestClient) -> Nil

Ends the session. Best effort: the tokens are forgotten either way.

pub fn new(
  transport: fn(transport.Request, fn(Int) -> Nil, fn() -> Nil) -> Result(
    transport.Response,
    transport.ExchangeError,
  ),
  router: api_router.ApiRouter,
  token: String,
  session_token: String,
  timeout_ms: Int,
) -> RestClient

A client for the API; the tokens resume a session a login started before. A request fails once the timeout passes without progress.

pub fn new_bot(
  transport: fn(transport.Request, fn(Int) -> Nil, fn() -> Nil) -> Result(
    transport.Response,
    transport.ExchangeError,
  ),
  router: api_router.ApiRouter,
  token: String,
  timeout_ms: Int,
) -> RestClient

A client for a bot: its token goes as Authorization: Bot <token>, and a 401 ends the request instead of renewing a session a bot has none of.

pub fn refresh_session(
  client: RestClient,
) -> Result(sign_in.SignIn, error.DuvetError)

Rotates the session’s tokens.

pub fn renew_session(client: RestClient) -> Bool

Renews the session’s tokens, answering whether it did.

pub fn request(
  client: RestClient,
  method: String,
  path: String,
  action: String,
  body: core.Body,
  meta: core.Meta(a),
) -> Result(transport.Response, error.DuvetError)
pub fn session_token(client: RestClient) -> String
pub fn token(client: RestClient) -> String
✨ Search Document