doc: turns out ye can have doctests, code in teh documentationt aht can be tested

wild
This commit is contained in:
silver 2024-11-23 18:40:35 +00:00
parent bcf8fba4f0
commit df28a6e11b
Signed by: silver
GPG key ID: 36F93D61BAD3FD7D
3 changed files with 66 additions and 5 deletions

47
Cargo.lock generated
View file

@ -17,6 +17,28 @@ version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627"
[[package]]
name = "async-stream"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b5a71a6f37880a80d1d7f19efd781e4b5de42c88f0722cc13bcb6cc2cfe8476"
dependencies = [
"async-stream-impl",
"futures-core",
"pin-project-lite",
]
[[package]]
name = "async-stream-impl"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7c24de15d275a1ecfd47a380fb4d5ec9bfe0933f309ed5e705b775596a3574d"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "atomic-waker"
version = "1.1.2"
@ -1073,6 +1095,30 @@ dependencies = [
"tokio",
]
[[package]]
name = "tokio-stream"
version = "0.1.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4f4e6ce100d0eb49a2734f8c0812bcd324cf357d21810932c5df6b96ef2b86f1"
dependencies = [
"futures-core",
"pin-project-lite",
"tokio",
]
[[package]]
name = "tokio-test"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2468baabc3311435b55dd935f702f42cd1b8abb7e754fb7dfb16bd36aa88f9f7"
dependencies = [
"async-stream",
"bytes",
"futures-core",
"tokio",
"tokio-stream",
]
[[package]]
name = "tokio-util"
version = "0.7.12"
@ -1369,6 +1415,7 @@ dependencies = [
"reqwest",
"serde",
"serde_json",
"tokio-test",
]
[[package]]

View file

@ -7,6 +7,10 @@ edition = "2021"
# for making teh requests
reqwest = { version = "0.12", features = ["json"] }
# for testing async stuff
tokio-test = "0.4"
# parsing teh results
serde_json = { version = "1.0", features = ["raw_value"] }
serde = { version = "1.0.215", features = ["derive"] }

View file

@ -135,9 +135,11 @@ impl Client {
/// # Examples
///
/// ```rust
/// # tokio_test::block_on(async {
/// use wolves_oxidised::{Client, WolvesUser};
/// let client = Client::new("https://cp.ulwolves.ie/api", None);
/// let result: Vec<WolvesUser> = client.get_members("api_key_club_1");
/// let result: Vec<WolvesUser> = client.get_members("api_key_club_1").await;
/// # })
/// ```
pub async fn get_members(&self, api_key: &str) -> Vec<WolvesUser> {
self.get_bulk::<WolvesUser>("get_members", api_key).await
@ -148,17 +150,21 @@ impl Client {
/// # Examples
/// No instance API key set
/// ```rust
/// # tokio_test::block_on(async {
/// use wolves_oxidised::{Client, WolvesCNS};
/// let client = Client::new("https://cp.ulwolves.ie/api", None);
/// let result: Vec<WolvesCNS> = client.get_committees();
/// let result: Vec<WolvesCNS> = client.get_committees().await;
/// assert_eq!(result.len(), 0);
/// # })
/// ```
///
/// Instance API key set, will return details if there are no other errors
/// ```rust
/// # tokio_test::block_on(async {
/// use wolves_oxidised::{Client, WolvesCNS};
/// let client = Client::new("https://cp.ulwolves.ie/api", Some("api_key_instance"));
/// let result: Vec<WolvesCNS> = client.get_committees();
/// let result: Vec<WolvesCNS> = client.get_committees().await;
/// # })
/// ```
pub async fn get_committees(&self) -> Vec<WolvesCNS> {
if let Some(api_key) = &self.base_key {
@ -176,17 +182,21 @@ impl Client {
/// # Examples
/// No instance API key set
/// ```rust
/// # tokio_test::block_on(async {
/// use wolves_oxidised::Client;
/// let client = Client::new("https://cp.ulwolves.ie/api", None);
/// let result: Option<i64> = client.get_member("example@example.ie");
/// let result: Option<i64> = client.get_member("example@example.ie").await;
/// assert!(result.is_none());
/// # })
/// ```
///
/// Instance API key set, will return details if there are no other errors
/// ```rust
/// # tokio_test::block_on(async {
/// use wolves_oxidised::Client;
/// let client = Client::new("https://cp.ulwolves.ie/api", Some("api_key_instance"));
/// let result: Option<i64> = client.get_member("example@example.ie");
/// let result: Option<i64> = client.get_member("example@example.ie").await;
/// # })
/// ```
pub async fn get_member(self, email: &str) -> Option<i64> {
// if the key isnt set then we cant do anything.