aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib.rs
blob: 60ac3880c33616dc9f57778e1e0946ddf2a4b55a (plain) (blame)
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
extern crate reqwest;

use std::io::Read;

const ZOTAPI_CHANNEL_STREAM_PATH : &str = "/api/z/1.0/channel/stream";

pub struct Client {
    base_url: String,
}

impl Client {
    pub fn channel_stream(&self) -> String {
        let mut res = reqwest::get(&self.channel_stream_url()).unwrap();
        let mut body = String::new();
        res.read_to_string(&mut body).unwrap();
        body
    }

    fn channel_stream_url(&self) -> String {
        self.base_url.clone() + ZOTAPI_CHANNEL_STREAM_PATH
    }
}

pub fn client<T>(url: T) -> Client
where
    T: Into<String>
{
    Client {
        base_url: url.into(),
    }
}

#[cfg(test)]
mod tests {
    #[test]
    fn it_works() {
        assert_eq!(2 + 2, 4);
    }
}