feat: implemented bulk requests

This commit is contained in:
TotallyNot 2025-04-29 18:26:00 +02:00
parent 4dd4fd37d4
commit c17f93f600
Signed by: pyrite
GPG key ID: 7F1BA9170CD35D15
10 changed files with 767 additions and 176 deletions

View file

@ -5,13 +5,12 @@ use http::StatusCode;
pub mod models;
#[derive(Default)]
pub struct ApiRequest<D = ()> {
pub disriminant: D,
pub struct ApiRequest {
pub path: String,
pub parameters: Vec<(&'static str, String)>,
}
impl<D> ApiRequest<D> {
impl ApiRequest {
pub fn url(&self) -> String {
let mut url = format!("https://api.torn.com/v2{}?", self.path);
@ -23,8 +22,7 @@ impl<D> ApiRequest<D> {
}
}
pub struct ApiResponse<D = ()> {
pub discriminant: D,
pub struct ApiResponse {
pub body: Option<Bytes>,
pub status: StatusCode,
}
@ -32,7 +30,26 @@ pub struct ApiResponse<D = ()> {
pub trait IntoRequest: Send {
type Discriminant: Send;
type Response: for<'de> serde::Deserialize<'de> + Send;
fn into_request(self) -> ApiRequest<Self::Discriminant>;
fn into_request(self) -> (Self::Discriminant, ApiRequest);
}
pub(crate) struct WrappedApiRequest<R>
where
R: IntoRequest,
{
discriminant: R::Discriminant,
request: ApiRequest,
}
impl<R> IntoRequest for WrappedApiRequest<R>
where
R: IntoRequest,
{
type Discriminant = R::Discriminant;
type Response = R::Response;
fn into_request(self) -> (Self::Discriminant, ApiRequest) {
(self.discriminant, self.request)
}
}
#[cfg(test)]