feat: abstract method to perform action
This commit is contained in:
@@ -9,7 +9,7 @@ pub mod model;
|
||||
mod error;
|
||||
pub use error::ApiError;
|
||||
use nyquest::{
|
||||
Body,
|
||||
AsyncClient, Body,
|
||||
r#async::Request,
|
||||
header::{ACCEPT_ENCODING, CONTENT_ENCODING, EXPECT, USER_AGENT},
|
||||
};
|
||||
@@ -62,6 +62,23 @@ pub trait MaiVersionExt: MaiVersion {
|
||||
|
||||
Ok(req)
|
||||
}
|
||||
|
||||
fn request<D>(
|
||||
client: &AsyncClient,
|
||||
api: APIMethod,
|
||||
agent_extra: impl Display,
|
||||
data: D,
|
||||
) -> impl Future<Output = Result<Vec<u8>, ApiError>>
|
||||
where
|
||||
D: Serialize,
|
||||
{
|
||||
async {
|
||||
let req = Self::api_request(api, agent_extra, data)?;
|
||||
let data = client.request(req).await?.bytes().await?;
|
||||
let decoded = Self::decode(data)?;
|
||||
Ok(decoded)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Sdgb1_40;
|
||||
|
||||
Reference in New Issue
Block a user