seamapi_rs/
action_attempts.rs1use anyhow::{bail, Context, Result};
2use serde::{Deserialize, Serialize};
3use serde_json::Value;
4
5pub struct ActionAttempts(pub String, pub String);
6
7#[derive(Deserialize, Serialize, Debug)]
8pub struct ActionAttempt {
9 pub status: String,
10 pub action_type: String,
11 pub action_attempt_id: String,
12 pub result: Value,
13 pub error: Value,
14}
15
16impl ActionAttempts {
17 pub fn get(self, action_attempt_id: String) -> Result<ActionAttempt> {
18 let url = format!(
19 "{}/action_attempts/get?action_attempt_id={}",
20 self.1, action_attempt_id
21 );
22 let header = format!("Bearer {}", self.0);
23
24 let req = reqwest::blocking::Client::new()
25 .get(url)
26 .header("authorization", header)
27 .send()
28 .context("Failed to send get request")?;
29
30 if req.status() == reqwest::StatusCode::NOT_FOUND {
31 bail!("Action Attempt not found");
32 } else if req.status() != reqwest::StatusCode::OK {
33 bail!("{}", req.text().context("Really bad API failue")?);
34 }
35
36 let json: crate::Response = req.json().context("Failed to deserialize")?;
37 Ok(json.action_attempt.unwrap())
38 }
39}