summaryrefslogtreecommitdiff
path: root/src/helix/namespaces/videos.rs
blob: b603b8f4c872ebdd66dd9a2488a0fd77113c0b06 (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use super::*;
use super::models::{PaginationContainer, Video};
use crate::types::{UserId, GameId, VideoId};


pub struct Videos {}
type VideosNamespace = Namespace<Videos>;

impl VideosNamespace {
    pub fn by_id<S: ToString>(self, ids: &[S])
        -> IterableApiRequest<PaginationContainer<Video>> {
        use self::by_id;
        by_id(self.client, ids)
    }

    pub fn by_user<S: ToString>(self, user_id: &S)
        -> IterableApiRequest<PaginationContainer<Video>> {
        use self::by_user;
        by_user(self.client, user_id)
    }

    pub fn for_game<S: ToString>(self, game_id: &S) 
        -> IterableApiRequest<PaginationContainer<Video>> {
        use self::for_game;
        for_game(self.client, game_id)
    }
}

impl Client {

    pub fn videos(&self) -> VideosNamespace {
        VideosNamespace::new(self)
    }
}

pub fn by_id<S: ToString>(client: Client, ids: &[S]) 
    -> IterableApiRequest<PaginationContainer<Video>> {
    let client = client.inner;
    let url =
        String::from("https://") + client.domain() + &String::from("/helix/videos");

    let mut params: ParamList = BTreeMap::new();
    for id in ids {
        params.insert("id", id);
    }

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

pub fn by_user<S: ToString>(client: Client, user_id: &S) 
    -> IterableApiRequest<PaginationContainer<Video>> {
    let client = client.inner;
    let url =
        String::from("https://") + client.domain() + &String::from("/helix/videos");

    let mut params: ParamList = BTreeMap::new();
    params.insert("user_id", user_id);

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

pub fn for_game<S: ToString>(client: Client, game_id: &S) 
    -> IterableApiRequest<PaginationContainer<Video>> {
    let client = client.inner;
    let url =
        String::from("https://") + client.domain() + &String::from("/helix/videos");

    let mut params: ParamList = BTreeMap::new();
    params.insert("game_id", game_id);

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