eagle_api/api/library/
switch.rs

1use serde::Serialize;
2
3use crate::{EagleApi, EagleResponse, Result};
4
5#[derive(Debug, Serialize)]
6#[serde(rename_all = "camelCase")]
7struct LibrarySwitchRequest {
8    library_path: String,
9}
10
11impl EagleApi {
12    pub async fn library_switch(&self, path: impl Into<String>) -> Result<()> {
13        let url = format!("{}/api/library/switch", self.inner.host);
14
15        let query = LibrarySwitchRequest {
16            library_path: path.into(),
17        };
18
19        let resp: EagleResponse<()> = self
20            .inner
21            .client
22            .post(&url)
23            .json(&query)
24            .send()
25            .await?
26            .json()
27            .await?;
28
29        resp.ok_without_data()
30    }
31}
32
33#[cfg(test)]
34mod tests {
35    use super::*;
36
37    #[tokio::test]
38    #[ignore]
39    async fn test_library_switch() {
40        let api = EagleApi::new(&std::env::var("EAGLE_API_TEST_HOST").unwrap());
41        let libs = api.library_history().await.unwrap();
42        let res = api.library_switch(&libs[0]).await;
43        res.unwrap();
44    }
45}