(&self, path: &str)
| 17 | } |
| 18 | |
| 19 | pub async fn get<T: DeserializeOwned>(&self, path: &str) -> anyhow::Result<T> { |
| 20 | let req = self |
| 21 | .client |
| 22 | .request(reqwest::Method::GET, format!("{}/{}", self.base_url, path)) |
| 23 | .header("Authorization", &self.token); |
| 24 | |
| 25 | let resp = req.send().await?; |
| 26 | if !resp.status().is_success() { |
| 27 | let status = resp.status(); |
| 28 | let body = resp.text().await?; |
| 29 | return Err(anyhow::anyhow!( |
| 30 | "API request failed: status {status}, body: {body}", |
| 31 | )); |
| 32 | } |
| 33 | |
| 34 | Ok(resp.json().await?) |
| 35 | } |
| 36 | |
| 37 | pub async fn get_self_user(&self) -> anyhow::Result<CurrentUser> { |
| 38 | self.get("api/current_user").await |
no test coverage detected