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
use reqwest::StatusCode;
use serde::{Deserialize, Serialize};

pub mod routes;
pub mod validate;

#[derive(Clone)]
pub struct Client {
    host: String,
}

impl Client {
    pub fn new(host: String) -> Client {
        Client { host: host }
    }

    fn endpoint(&self, url: &str, values: Vec<String>) -> String {
        let segments: Vec<&str> = url.split("{}").collect();

        let mut endpoint = String::new();
        endpoint.push_str(&self.host);

        for index in 0..segments.len() {
            if index > 0 {
                endpoint.push_str(values.get(index - 1).expect("Not enough values provided"));
            }
            endpoint.push_str(segments.get(index).unwrap());
        }

        endpoint
    }
}

fn req() -> reqwest::Client {
    reqwest::Client::new()
}