1use serde_json::Value as JsonValue;
2use ureq;
3
4#[derive(Clone)]
7pub struct APIClient {
8 endpoint: String,
9}
10
11impl APIClient {
12 pub fn new(endpoint: &str) -> Self {
13 APIClient {
14 endpoint: endpoint.trim_end_matches('/').to_owned(),
15 }
16 }
17
18 fn fullpath(&self, path: &str) -> String {
19 format!("{}{}", &self.endpoint, path)
20 }
21
22 pub fn get(&self, path: &str) -> Result<JsonValue, ureq::Error> {
23 ureq::get(self.fullpath(path))
24 .call()?
25 .body_mut()
26 .read_json()
27 }
28
29 pub fn call(&self, path: &str, params: &JsonValue) -> Result<JsonValue, ureq::Error> {
30 ureq::post(self.fullpath(path))
31 .send_json(params)?
32 .body_mut()
33 .read_json()
34 }
35
36
37 pub fn jungle() -> Self {
43 APIClient::new("https://jungle4.greymass.com")
44 }
45
46 pub fn vaulta() -> Self {
47 APIClient::new("https://vaulta.greymass.com")
48 }
49}