diff --git a/connectbox/src/error.rs b/connectbox/src/error.rs index ab63fc4..d3a2cff 100644 --- a/connectbox/src/error.rs +++ b/connectbox/src/error.rs @@ -1,6 +1,7 @@ use reqwest::header::ToStrError; use thiserror::Error; +/// The error type used globally by the library. #[derive(Error, Debug)] pub enum Error { #[error("session token not found, are you logged in?")] diff --git a/connectbox/src/lib.rs b/connectbox/src/lib.rs index 3f24b12..b0155f3 100644 --- a/connectbox/src/lib.rs +++ b/connectbox/src/lib.rs @@ -2,7 +2,7 @@ use std::{borrow::Cow, fmt::Display, sync::Arc}; -use error::Error; +pub use error::Error; use reqwest::{ cookie::{CookieStore, Jar}, redirect::Policy, @@ -10,11 +10,13 @@ use reqwest::{ }; use serde::de::DeserializeOwned; -pub mod error; +mod error; mod functions; +/// Data structures used by the library. pub mod models; -pub(crate) type Result = std::result::Result; +// A Result type based on the library's Error +pub type Result = std::result::Result; type Field<'a, 'b> = (Cow<'a, str>, Cow<'b, str>); @@ -30,6 +32,9 @@ pub struct ConnectBox { } impl ConnectBox { + /// Create a new client associated with the specified address. You must call [`login`](Self::login()) before use. + /// * `code` - the router password + /// * `auto_reauth` - whether to automatically re-authenticate when the session expires pub fn new(address: impl Display, code: String, auto_reauth: bool) -> Result { let cookie_store = Arc::new(Jar::default()); let http = Client::builder() @@ -144,6 +149,7 @@ impl ConnectBox { Ok(()) } + /// Login to the router. This method must be called before using the client. pub async fn login(&self) -> Result<()> { // get the session cookie self.http @@ -154,6 +160,7 @@ impl ConnectBox { self._login().await } + /// Get all devices connected to the router. pub async fn get_devices(&self) -> Result { self.xml_getter(functions::LAN_TABLE).await }