feat: implemented bulk requests
This commit is contained in:
parent
4dd4fd37d4
commit
c17f93f600
10 changed files with 767 additions and 176 deletions
|
|
@ -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)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue