1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use crate::models::Checklist;

pub struct Client {
    auth: String,
}

impl Client {
    pub fn new(login: String, api_key: String) -> Self {
        let credentials = base64::encode(format!("{}:{}", &login, &api_key));
        let auth = format!("Basic {}", credentials);

        Self {
            auth
        }
    }

    pub fn get_checklists(&self) -> Result<Vec<Checklist>, ureq::Error> {
        let checklists: Vec<Checklist> = ureq::get("https://checkvist.com/checklists.json")
            .set("Authorization", &self.auth)
            .call()?
            .into_json()?;
        Ok(checklists)
    }
}