summaryrefslogtreecommitdiff
path: root/src/kraken/mod.rs
blob: 59d00c006a22ff767418107136ceb8a0a223b67d (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
use reqwest::header;
use std::sync::Arc;
use reqwest::r#async::RequestBuilder;
use reqwest::r#async::Client as ReqwestClient;
pub use super::types;

mod endpoints;
mod models;


const ACCEPT: &str = "application/vnd.twitchtv.v5+json";
pub const API_DOMAIN: &str = "api.twitch.tv";

#[derive(Clone)]
pub struct Client {
    inner: Arc<ClientRef>,
}

struct ClientRef {
    id: String,
    client: ReqwestClient
}

impl Client {
    pub fn new(id: &str) -> Client {
        Client {
            inner: Arc::new(ClientRef {
                id: id.to_owned(),
                client: ReqwestClient::new(),
            })
        }
    }

    pub fn new_with_client(id: &str, client: ReqwestClient) -> Client {
        Client {
            inner: Arc::new(ClientRef {
                id: id.to_owned(),
                client: client,
            })
        }
    }

   fn apply_standard_headers(&self, request: RequestBuilder) 
       -> RequestBuilder 
    {
        let client_header = header::HeaderValue::from_str(&self.inner.id).unwrap();
        let accept_header = header::HeaderValue::from_str(ACCEPT).unwrap();

        request
            .header("Accept", accept_header)
            .header("Client-ID", client_header)
    }
}