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
use crate::{blocking::LTAClient, Client, LTAError, LTAResult};
use reqwest::blocking::{Client as ReqwestBlocking, RequestBuilder};

impl Client for LTAClient<ReqwestBlocking> {
    type InternalClient = ReqwestBlocking;
    type RB = RequestBuilder;

    fn new(
        api_key: impl Into<String>,
        client: Self::InternalClient,
        base_url: impl Into<String>,
    ) -> Self {
        let api_key = api_key.into();
        let base_url = base_url.into();

        LTAClient {
            api_key,
            client,
            base_url,
        }
    }

    fn with_api_key(api_key: impl Into<String>, base_url: impl Into<String>) -> LTAResult<Self> {
        let api_key = api_key.into();
        let base_url = base_url.into();

        if api_key.is_empty() {
            return Err(LTAError::InvalidAPIKey);
        }

        let client = ReqwestBlocking::new();

        Ok(LTAClient {
            api_key,
            client,
            base_url,
        })
    }

    fn req_builder(&self, url: &str) -> Self::RB {
        self.client
            .get(url)
            .header("AccountKey", self.api_key.as_str())
    }

    fn base_url(&self) -> &str {
        &self.base_url
    }
}