From 94f333f983aa7f4fcfc541b9d6f52f2261d3095a Mon Sep 17 00:00:00 2001 From: "Rodrigo Rodriguez (Pragmatismo)" Date: Wed, 24 Dec 2025 09:29:29 -0300 Subject: [PATCH] Update http_client and version modules --- src/http_client.rs | 49 ++++++++++++++++++++++++++++++---------------- src/version.rs | 8 ++++---- 2 files changed, 36 insertions(+), 21 deletions(-) diff --git a/src/http_client.rs b/src/http_client.rs index 36b6053..ff0e3dd 100644 --- a/src/http_client.rs +++ b/src/http_client.rs @@ -1,4 +1,3 @@ - use crate::error::BotError; use log::{debug, error}; use serde::{de::DeserializeOwned, Serialize}; @@ -44,8 +43,10 @@ impl BotServerClient { &self.base_url } - - + /// Perform a GET request to the specified endpoint. + /// + /// # Errors + /// Returns an error if the request fails or the response cannot be parsed. pub async fn get(&self, endpoint: &str) -> Result { let url = format!("{}{endpoint}", self.base_url); debug!("GET {url}"); @@ -54,8 +55,10 @@ impl BotServerClient { self.handle_response(response).await } - - + /// Perform a POST request to the specified endpoint. + /// + /// # Errors + /// Returns an error if the request fails or the response cannot be parsed. pub async fn post( &self, endpoint: &str, @@ -68,8 +71,10 @@ impl BotServerClient { self.handle_response(response).await } - - + /// Perform a PUT request to the specified endpoint. + /// + /// # Errors + /// Returns an error if the request fails or the response cannot be parsed. pub async fn put( &self, endpoint: &str, @@ -82,8 +87,10 @@ impl BotServerClient { self.handle_response(response).await } - - + /// Perform a PATCH request to the specified endpoint. + /// + /// # Errors + /// Returns an error if the request fails or the response cannot be parsed. pub async fn patch( &self, endpoint: &str, @@ -96,8 +103,10 @@ impl BotServerClient { self.handle_response(response).await } - - + /// Perform a DELETE request to the specified endpoint. + /// + /// # Errors + /// Returns an error if the request fails or the response cannot be parsed. pub async fn delete(&self, endpoint: &str) -> Result { let url = format!("{}{endpoint}", self.base_url); debug!("DELETE {url}"); @@ -106,8 +115,10 @@ impl BotServerClient { self.handle_response(response).await } - - + /// Perform an authorized GET request with a bearer token. + /// + /// # Errors + /// Returns an error if the request fails or the response cannot be parsed. pub async fn get_authorized( &self, endpoint: &str, @@ -120,8 +131,10 @@ impl BotServerClient { self.handle_response(response).await } - - + /// Perform an authorized POST request with a bearer token. + /// + /// # Errors + /// Returns an error if the request fails or the response cannot be parsed. pub async fn post_authorized( &self, endpoint: &str, @@ -141,8 +154,10 @@ impl BotServerClient { self.handle_response(response).await } - - + /// Perform an authorized DELETE request with a bearer token. + /// + /// # Errors + /// Returns an error if the request fails or the response cannot be parsed. pub async fn delete_authorized( &self, endpoint: &str, diff --git a/src/version.rs b/src/version.rs index f41943e..4cc30c9 100644 --- a/src/version.rs +++ b/src/version.rs @@ -1,4 +1,3 @@ - use chrono::{DateTime, Utc}; use log::debug; use serde::{Deserialize, Serialize}; @@ -197,14 +196,15 @@ impl VersionRegistry { ) } - - + /// Serialize the registry to a JSON string. + /// + /// # Errors + /// Returns an error if serialization fails. pub fn to_json(&self) -> Result { serde_json::to_string_pretty(self) } } - pub fn init_version_registry() { let registry = VersionRegistry::new(); if let Ok(mut guard) = VERSION_REGISTRY.write() {