1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use crate::{
    models::{Oui, OuiStats},
    *,
};

/// Get a stream of all ouis
pub fn all(client: &Client) -> Stream<Oui> {
    client.fetch_stream("/ouis", NO_QUERY)
}

/// Get a specific oui
pub async fn get(client: &Client, oui: u64) -> Result<Oui> {
    client.fetch(&format!("/ouis/{}", oui), NO_QUERY).await
}

/// Get the last assigned oui
pub async fn last(client: &Client) -> Result<Oui> {
    client.fetch("/ouis/last", NO_QUERY).await
}

/// Get statistics for ouis
pub async fn stats(client: &Client) -> Result<OuiStats> {
    client.fetch("/ouis/stats", NO_QUERY).await
}

#[cfg(test)]
mod test {
    use super::*;
    use tokio::test;

    #[test]
    async fn all() {
        let client = get_test_client();
        let ouis = ouis::all(&client).into_vec().await.expect("ouis");
        assert!(ouis.len() > 0);
    }

    #[test]
    async fn get() {
        let client = get_test_client();
        let oui = ouis::get(&client, 1).await.expect("oui");
        assert_eq!(
            oui.owner,
            "13tyMLKRFYURNBQqLSqNJg9k41maP1A7Bh8QYxR13oWv7EnFooc"
        );
    }

    #[test]
    async fn last() {
        let client = get_test_client();
        let oui = ouis::last(&client).await.expect("oui");
        assert!(oui.oui >= 1,);
    }

    #[test]
    async fn stats() {
        let client = get_test_client();
        let stats = ouis::stats(&client).await.expect("stats");
        assert!(stats.count >= 1,);
    }
}