#![allow(unused_imports)]
use http::Method;
use serde::de::DeserializeOwned;
use serde_json::Value;
use std::collections::BTreeMap;
use crate::common::{config::ConfigurationRestApi, models::RestApiResponse, utils::send_request};
mod apis;
mod models;
pub use apis::*;
pub use models::*;
#[derive(Debug, Clone)]
pub struct RestApi {
configuration: ConfigurationRestApi,
fiat_api_client: FiatApiClient,
}
impl RestApi {
pub fn new(configuration: ConfigurationRestApi) -> Self {
let fiat_api_client = FiatApiClient::new(configuration.clone());
Self {
configuration,
fiat_api_client,
}
}
pub async fn send_request<R: DeserializeOwned + Send + 'static>(
&self,
endpoint: &str,
method: Method,
query_params: BTreeMap<String, Value>,
body_params: BTreeMap<String, Value>,
) -> anyhow::Result<RestApiResponse<R>> {
send_request::<R>(
&self.configuration,
endpoint,
method,
query_params,
body_params,
None,
false,
)
.await
}
pub async fn send_signed_request<R: DeserializeOwned + Send + 'static>(
&self,
endpoint: &str,
method: Method,
query_params: BTreeMap<String, Value>,
body_params: BTreeMap<String, Value>,
) -> anyhow::Result<RestApiResponse<R>> {
send_request::<R>(
&self.configuration,
endpoint,
method,
query_params,
body_params,
None,
true,
)
.await
}
pub async fn deposit(
&self,
params: DepositParams,
) -> anyhow::Result<RestApiResponse<models::DepositResponse>> {
self.fiat_api_client.deposit(params).await
}
pub async fn fiat_withdraw(
&self,
params: FiatWithdrawParams,
) -> anyhow::Result<RestApiResponse<models::FiatWithdrawResponse>> {
self.fiat_api_client.fiat_withdraw(params).await
}
pub async fn get_fiat_deposit_withdraw_history(
&self,
params: GetFiatDepositWithdrawHistoryParams,
) -> anyhow::Result<RestApiResponse<models::GetFiatDepositWithdrawHistoryResponse>> {
self.fiat_api_client
.get_fiat_deposit_withdraw_history(params)
.await
}
pub async fn get_fiat_payments_history(
&self,
params: GetFiatPaymentsHistoryParams,
) -> anyhow::Result<RestApiResponse<models::GetFiatPaymentsHistoryResponse>> {
self.fiat_api_client.get_fiat_payments_history(params).await
}
pub async fn get_order_detail(
&self,
params: GetOrderDetailParams,
) -> anyhow::Result<RestApiResponse<models::GetOrderDetailResponse>> {
self.fiat_api_client.get_order_detail(params).await
}
}