Skip to main content

efi_bank/
cob.rs

1use reqwest::Method;
2
3use crate::client::Client;
4use crate::error::Error;
5use crate::types::{CobPayload, CobResponse};
6
7impl Client {
8    pub async fn cob_create(&self, payload: &CobPayload) -> Result<CobResponse, Error> {
9        self.send_authenticated(Method::POST, "/v2/cob", Some(payload))
10            .await
11    }
12
13    pub async fn cob_update(&self, txid: &str, payload: &CobPayload) -> Result<CobResponse, Error> {
14        let path = format!("/v2/cob/{txid}");
15        self.send_authenticated(Method::PUT, &path, Some(payload))
16            .await
17    }
18
19    pub async fn cob_patch(&self, txid: &str, payload: &CobPayload) -> Result<CobResponse, Error> {
20        let path = format!("/v2/cob/{txid}");
21        self.send_authenticated(Method::PATCH, &path, Some(payload))
22            .await
23    }
24
25    pub async fn cob_get(&self, txid: &str) -> Result<CobResponse, Error> {
26        let path = format!("/v2/cob/{txid}");
27        self.send_authenticated::<serde_json::Value, CobResponse>(Method::GET, &path, None)
28            .await
29    }
30
31    pub async fn cob_list(
32        &self,
33        cpf: Option<&str>,
34        status: Option<&str>,
35        limit: Option<i32>,
36    ) -> Result<Vec<CobResponse>, Error> {
37        let mut path = String::from("/v2/cob");
38        let mut params = Vec::new();
39
40        if let Some(c) = cpf {
41            params.push(format!("cpf={c}"));
42        }
43        if let Some(s) = status {
44            params.push(format!("status={s}"));
45        }
46        if let Some(l) = limit {
47            params.push(format!("limit={l}"));
48        }
49
50        if !params.is_empty() {
51            path.push('?');
52            path.push_str(&params.join("&"));
53        }
54
55        self.send_authenticated::<serde_json::Value, Vec<CobResponse>>(Method::GET, &path, None)
56            .await
57    }
58}