summaryrefslogtreecommitdiff
path: root/src/helix/namespaces/users.rs
blob: 2e922d6e70a0c83e1334877fe873594391bb2c0f (plain)
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
use super::*;
use super::models::{DataContainer, User};
use std::string::ToString;

pub struct Users {}
type UsersNamespace = Namespace<Users>;

impl UsersNamespace {
    pub fn users<S: ToString>(self, ids: &[S], logins: &[S]) -> ApiRequest<DataContainer<User>> {
        use self::users;
        users(self.client, ids, logins)
    }
}

impl Client {
    pub fn users(&self) -> UsersNamespace {
        UsersNamespace::new(self)
    }
}

pub fn users<S: ToString>(
        client: Client,
        ids: &[S],
        logins: &[S],
    ) -> ApiRequest<DataContainer<User>> {
        let client = client.inner;
        let url =
            String::from("https://") + client.domain() + &String::from("/helix/users");

        let mut params: BTreeMap<&str, &dyn ToString> = BTreeMap::new();
        for id in ids {
            params.insert("id", id);
        }

        for login in logins {
            params.insert("login", login);
        }

        ApiRequest::new(url, params, client, Method::GET, Some(RatelimitKey::Default))
}

pub fn authed_as(client: Client) -> ApiRequest<DataContainer<User>> {
    users(client, &[""], &[""])
}