helium_api/
ouis.rs

1use crate::{
2    models::{Oui, OuiStats},
3    *,
4};
5
6/// Get a stream of all ouis
7pub fn all(client: &Client) -> Stream<Oui> {
8    client.fetch_stream("/ouis", NO_QUERY)
9}
10
11/// Get a specific oui
12pub async fn get(client: &Client, oui: u64) -> Result<Oui> {
13    client.fetch(&format!("/ouis/{}", oui), NO_QUERY).await
14}
15
16/// Get the last assigned oui
17pub async fn last(client: &Client) -> Result<Oui> {
18    client.fetch("/ouis/last", NO_QUERY).await
19}
20
21/// Get statistics for ouis
22pub async fn stats(client: &Client) -> Result<OuiStats> {
23    client.fetch("/ouis/stats", NO_QUERY).await
24}
25
26#[cfg(test)]
27mod test {
28    use super::*;
29    use tokio::test;
30
31    #[test]
32    async fn all() {
33        let client = get_test_client();
34        let ouis = ouis::all(&client).into_vec().await.expect("ouis");
35        assert!(ouis.len() > 0);
36    }
37
38    #[test]
39    async fn get() {
40        let client = get_test_client();
41        let oui = ouis::get(&client, 1).await.expect("oui");
42        assert_eq!(
43            oui.owner,
44            "13tyMLKRFYURNBQqLSqNJg9k41maP1A7Bh8QYxR13oWv7EnFooc"
45        );
46    }
47
48    #[test]
49    async fn last() {
50        let client = get_test_client();
51        let oui = ouis::last(&client).await.expect("oui");
52        assert!(oui.oui >= 1,);
53    }
54
55    #[test]
56    async fn stats() {
57        let client = get_test_client();
58        let stats = ouis::stats(&client).await.expect("stats");
59        assert!(stats.count >= 1,);
60    }
61}