ipcs_api/
lib.rs

1pub struct IpcsApi {
2    url: url::Url,
3    client: reqwest::Client,
4}
5
6impl IpcsApi {
7    pub fn new(url: &str) -> Result<Self, url::ParseError> {
8        Ok(IpcsApi {
9            url: url::Url::parse(url)?,
10            client: reqwest::Client::new(),
11        })
12    }
13
14    pub async fn exec(&self, method: &str, args: &[&str]) -> Result<String, reqwest::Error> {
15        let mut url = self.url.clone();
16        url.set_path("/api/v0/exec");
17
18        let response = self
19            .client
20            .post(url)
21            .json(&apidefs::ExecReq {
22                method: method.to_string(),
23                args: args.iter().map(|v| v.to_string()).collect(),
24            })
25            .send()
26            .await?;
27
28        if response.status().is_client_error() || response.status().is_server_error() {
29            return Ok(response.text().await?);
30        }
31
32        let res: apidefs::ExecResp = response.json().await?;
33        Ok(res.hash)
34    }
35}