pub struct GotifyClient { /* private fields */ }Expand description
HTTP REST client for Gotify push-notification servers.
Authentication uses the X-Gotify-Key header with one of two distinct
token kinds: a client token for management operations (messages,
applications, clients, current user) and an app token for sending
messages. health/version need no token at all.
Builds and holds one pooled [reqwest::Client] for its lifetime — clone
and share a GotifyClient rather than constructing a new one per
request, so requests reuse connections instead of paying a fresh TLS
handshake each time.
Debug redacts both tokens, same as GotifyConfig.
Implementations§
Source§impl GotifyClient
impl GotifyClient
Sourcepub fn new(cfg: &GotifyConfig) -> Result<Self>
pub fn new(cfg: &GotifyConfig) -> Result<Self>
Builds a client from cfg.
Unlike client_token/app_token (each validated lazily, only by the
specific calls that need them), url is required upfront — every
call needs it, so failing fast here is strictly more useful than
deferring to the first request.
§Errors
Returns GotifyError::MissingUrl if cfg.url is empty, or
GotifyError::ClientBuild if the underlying HTTP client fails to
construct.
Sourcepub fn config(&self) -> GotifyConfig
pub fn config(&self) -> GotifyConfig
Reconstructs the GotifyConfig this client was built from.
Sourcepub async fn me(&self) -> Result<Value>
pub async fn me(&self) -> Result<Value>
Authenticated user info. Requires a client token.
§Errors
Returns GotifyError::MissingClientToken if no client token is
configured; see GotifyError for the other failure cases this can
return.
Sourcepub async fn messages(
&self,
app_id: Option<i64>,
limit: Option<i64>,
since: Option<i64>,
) -> Result<Value>
pub async fn messages( &self, app_id: Option<i64>, limit: Option<i64>, since: Option<i64>, ) -> Result<Value>
Lists messages, optionally scoped to one application. Requires a client token.
limit defaults to 50 server-side if None.
§Errors
Returns GotifyError::MissingClientToken if no client token is
configured; see GotifyError for the other failure cases this can
return.
Sourcepub async fn send_message(
&self,
message: &str,
title: Option<&str>,
priority: Option<i64>,
extras: Option<Value>,
) -> Result<Value>
pub async fn send_message( &self, message: &str, title: Option<&str>, priority: Option<i64>, extras: Option<Value>, ) -> Result<Value>
Sends a notification. Requires an app token (not a client token).
§Errors
Returns GotifyError::MissingAppToken if no app token is
configured; see GotifyError for the other failure cases this can
return.
Sourcepub async fn delete_message(&self, id: i64) -> Result<Value>
pub async fn delete_message(&self, id: i64) -> Result<Value>
Deletes one message. Requires a client token.
§Errors
Returns GotifyError::MissingClientToken if no client token is
configured; see GotifyError for the other failure cases this can
return.
Sourcepub async fn delete_all_messages(&self) -> Result<Value>
pub async fn delete_all_messages(&self) -> Result<Value>
Deletes every message. Requires a client token.
§Errors
Returns GotifyError::MissingClientToken if no client token is
configured; see GotifyError for the other failure cases this can
return.
Sourcepub async fn applications(&self) -> Result<Value>
pub async fn applications(&self) -> Result<Value>
Lists applications. Requires a client token.
§Errors
Returns GotifyError::MissingClientToken if no client token is
configured; see GotifyError for the other failure cases this can
return.
Sourcepub async fn create_application(
&self,
name: &str,
description: Option<&str>,
default_priority: Option<i64>,
) -> Result<Value>
pub async fn create_application( &self, name: &str, description: Option<&str>, default_priority: Option<i64>, ) -> Result<Value>
Creates an application. Requires a client token.
§Errors
Returns GotifyError::MissingClientToken if no client token is
configured; see GotifyError for the other failure cases this can
return.
Sourcepub async fn update_application(
&self,
app_id: i64,
name: Option<&str>,
description: Option<&str>,
default_priority: Option<i64>,
) -> Result<Value>
pub async fn update_application( &self, app_id: i64, name: Option<&str>, description: Option<&str>, default_priority: Option<i64>, ) -> Result<Value>
Updates an application. Requires a client token.
§Errors
Returns GotifyError::MissingClientToken if no client token is
configured; see GotifyError for the other failure cases this can
return.
Sourcepub async fn delete_application(&self, app_id: i64) -> Result<Value>
pub async fn delete_application(&self, app_id: i64) -> Result<Value>
Deletes an application. Requires a client token.
§Errors
Returns GotifyError::MissingClientToken if no client token is
configured; see GotifyError for the other failure cases this can
return.
Sourcepub async fn clients(&self) -> Result<Value>
pub async fn clients(&self) -> Result<Value>
Lists clients. Requires a client token.
§Errors
Returns GotifyError::MissingClientToken if no client token is
configured; see GotifyError for the other failure cases this can
return.
Sourcepub async fn create_client(&self, name: &str) -> Result<Value>
pub async fn create_client(&self, name: &str) -> Result<Value>
Creates a client. Requires a client token.
§Errors
Returns GotifyError::MissingClientToken if no client token is
configured; see GotifyError for the other failure cases this can
return.
Sourcepub async fn delete_client(&self, client_id: i64) -> Result<Value>
pub async fn delete_client(&self, client_id: i64) -> Result<Value>
Deletes a client. Requires a client token.
§Errors
Returns GotifyError::MissingClientToken if no client token is
configured; see GotifyError for the other failure cases this can
return.
Trait Implementations§
Source§impl Clone for GotifyClient
impl Clone for GotifyClient
Source§fn clone(&self) -> GotifyClient
fn clone(&self) -> GotifyClient
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more