Crate gotify

Source
Expand description

An idiomatic Rust client for Gotify.

§Overview

By default, this crate only exposes the Client::health(), Client::version() methods. All other categories of endpoints must be enabled by the corresponding feature flags.

Table of available feature flags
Feature flagEnabled methodsNote
appClient::create_message()
manage-applicationsClient::get_applications(), Client::create_application(), Client::update_application(), Client::delete_application(), Client::delete_application_image()
manage-clientsClient::get_clients(), Client::create_client(), Client::update_client(), Client::delete_client()
manage-messagesClient::get_application_messages(), Client::delete_application_messages(), Client::get_messages(), Client::delete_messages(), Client::delete_message()doesn’t include Client::create_message() and Client::stream_messages()
manage-pluginsClient::get_plugins(), Client::get_plugin_config(), Client::update_plugin_config(), Client::disable_plugin(), Client::get_plugin_display(), Client::enable_plugin()
manage-usersClient::get_current_user(), Client::update_current_user(), Client::get_users(), Client::get_user(), Client::update_user(), Client::delete_user()
websocketClient::stream_messages()enables additional dependencies (mainly tokio-tungstenite)

Most methods that send data to Gotify’s API use the builder pattern for a more readable API and better support of future additions to Gotify’s API. If an optional parameter is added to an endpoint, it can be be added as a builder method without causing to much breakage. All builders implement IntoFuture, so those methods can also be awaited directly, just as if they were regular async methods.

§Examples

§Creating a message

let client: gotify::AppClient = gotify::Client::new(GOTIFY_URL, GOTIFY_APP_TOKEN)?;

client.create_message("Lorem ipsum dolor sit amet").with_title("Lorem Ipsum").await?;

§Listening for new messages

use futures_util::StreamExt;

let client: gotify::ClientClient = gotify::Client::new(GOTIFY_URL, GOTIFY_CLIENT_TOKEN)?;

let mut messages = client.stream_messages().await?;

while let Some(result) = messages.next().await {
    let message = result?;

    println!("{message:#?}")
}

Modules§

builder
Builder structs used by some methods that send data to Gotify’s API.
models
JSON models returned by Gotify’s API.

Structs§

AppTokenapp
Marks a client as authenticated to create messages.
Client
A client for a specific Gotify server. The main entrypoint of this crate.
ClientTokenclient-core
Marks a client as authenticated to manage the server.
Unauthenticated
Marks a client as unauthenticated.

Enums§

Error
Errors that can occur when accessing an API endpoint.
InitError
Errors that can occur when creating or authenticating a Client.
WebsocketConnectErrorwebsocket
Errors that can occur when initializing the websocket connection.
WebsocketErrorwebsocket
Errors that can occur when the websocket is established.

Traits§

TokenType
Sealed trait to represent an AppToken or ClientToken.

Type Aliases§

AppClientapp
A client that is authenticated to create messages.
ClientClientclient-core
A client that is authenticated to manage the server.
Result
Alias for the Result returned when accessing an API endpoint.
UnauthenticatedClient
A client that is unauthenticated.