1#![allow(unused_assignments)]
2use anyhow::Result;
3use serde::de::DeserializeOwned;
4use serde::Serialize;
5
6pub mod model;
7pub mod request;
8pub mod response;
9pub mod shared;
10pub mod traits;
11
12pub use model::User;
13pub use shared::Platform;
14
15pub(crate) const BASE_URL: &str = "https://api.warframe.market/v1";
16
17pub(crate) async fn get_endpoint<T: DeserializeOwned>(
18 client: &reqwest::Client,
19 url: &str,
20 jwt: &str,
21) -> Result<T> {
22 let mut headers = reqwest::header::HeaderMap::new();
23 headers.insert("authorization", jwt.parse()?);
24 headers.insert("Content-Type", "application/json".parse()?);
25
26 let raw = client
27 .get(format!("{}{}", BASE_URL, url))
28 .headers(headers)
29 .send()
30 .await?
31 .text()
32 .await?;
33
34 let base: response::ResponseWrapper<T> = serde_json::from_str(&raw)?;
35
36 Ok(base.payload)
37}
38
39pub(crate) async fn post_endpoint<T: DeserializeOwned, B: Serialize>(
40 client: &reqwest::Client,
41 url: &str,
42 jwt: &str,
43 body: &B,
44) -> Result<T> {
45 let mut headers = reqwest::header::HeaderMap::new();
46 headers.insert("authorization", jwt.parse()?);
47 headers.insert("Content-Type", "application/json".parse()?);
48
49 let raw = client
50 .post(format!("{}{}", BASE_URL, url))
51 .headers(headers)
52 .body(serde_json::to_string(body)?)
53 .send()
54 .await?
55 .text()
56 .await?;
57
58 let base: response::ResponseWrapper<T> = serde_json::from_str(&raw)?;
59
60 Ok(base.payload)
61}
62
63pub(crate) async fn delete_endpoint<T: DeserializeOwned>(
64 client: &reqwest::Client,
65 url: &str,
66 jwt: &str,
67) -> Result<T> {
68 let mut headers = reqwest::header::HeaderMap::new();
69 headers.insert("authorization", jwt.parse()?);
70 headers.insert("Content-Type", "application/json".parse()?);
71
72 let raw = client
73 .delete(format!("{}{}", BASE_URL, url))
74 .headers(headers)
75 .send()
76 .await?
77 .text()
78 .await?;
79
80 let base: response::ResponseWrapper<T> = serde_json::from_str(&raw)?;
81
82 Ok(base.payload)
83}
84
85pub(crate) async fn put_endpoint<T: Serialize>(
86 client: &reqwest::Client,
87 url: &str,
88 jwt: &str,
89 body: &T,
90) -> Result<()> {
91 let mut headers = reqwest::header::HeaderMap::new();
92 headers.insert("authorization", jwt.parse()?);
93 headers.insert("Content-Type", "application/json".parse()?);
94
95 let raw = client
96 .put(format!("{}{}", BASE_URL, url))
97 .headers(headers)
98 .body(serde_json::to_string(body)?)
99 .send()
100 .await?
101 .error_for_status()?;
102
103 Ok(())
104}