summaryrefslogtreecommitdiff
path: root/src/helix/namespaces/videos.rs
blob: a8021f3e09b25cd6ad05bf2b218db6afa402a06e (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
76
77
78
79
use super::super::models::{PaginationContainer, Video};
use super::super::Client; 
use super::Namespace;

use crate::client::{ClientTrait, RatelimitKey, IterableApiRequest};
use std::collections::BTreeMap;
use reqwest::Method;


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

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

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

    pub fn for_game(self, game_id: &str) 
        -> 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(client: Client, ids: Vec<&str>) 
    -> IterableApiRequest<PaginationContainer<Video>> {
    let client = client.inner;
    let url =
        String::from("https://") + client.domain() + &String::from("/helix/videos");

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

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

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

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

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

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

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

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