use super::*;
#[cfg(feature = "_async")]
use super::bootstrap::retry_with_config_async;
#[cfg(feature = "_blocking")]
use super::bootstrap::retry_with_config_blocking;
#[cfg(feature = "_async")]
#[derive(Clone)]
pub struct RawApi {
client: Client,
}
#[cfg(feature = "_async")]
impl RawApi {
pub(crate) fn new(client: Client) -> Self {
Self { client }
}
pub async fn call_json<R, P>(&self, method: &str, payload: &P) -> Result<R>
where
R: DeserializeOwned,
P: Serialize + ?Sized,
{
self.client.call_method(method, payload).await
}
pub async fn call_json_with_retry<R, P>(
&self,
method: &str,
payload: &P,
retry: RetryConfig,
) -> Result<R>
where
R: DeserializeOwned,
P: Serialize + ?Sized,
{
retry_with_config_async(&retry, || async {
self.client.call_method(method, payload).await
})
.await
}
pub async fn call_no_params<R>(&self, method: &str) -> Result<R>
where
R: DeserializeOwned,
{
self.client.call_method_no_params(method).await
}
pub async fn call_no_params_with_retry<R>(&self, method: &str, retry: RetryConfig) -> Result<R>
where
R: DeserializeOwned,
{
retry_with_config_async(&retry, || async {
self.client.call_method_no_params(method).await
})
.await
}
pub async fn call_multipart<R, P>(
&self,
method: &str,
payload: &P,
file_field_name: &str,
file: &UploadFile,
) -> Result<R>
where
R: DeserializeOwned,
P: Serialize + ?Sized,
{
self.client
.call_method_multipart(method, payload, file_field_name, file)
.await
}
pub async fn call_multipart_with_retry<R, P>(
&self,
method: &str,
payload: &P,
file_field_name: &str,
file: &UploadFile,
retry: RetryConfig,
) -> Result<R>
where
R: DeserializeOwned,
P: Serialize + ?Sized,
{
retry_with_config_async(&retry, || async {
self.client
.call_method_multipart(method, payload, file_field_name, file)
.await
})
.await
}
}
#[cfg(feature = "_blocking")]
#[derive(Clone)]
pub struct BlockingRawApi {
client: BlockingClient,
}
#[cfg(feature = "_blocking")]
impl BlockingRawApi {
pub(crate) fn new(client: BlockingClient) -> Self {
Self { client }
}
pub fn call_json<R, P>(&self, method: &str, payload: &P) -> Result<R>
where
R: DeserializeOwned,
P: Serialize + ?Sized,
{
self.client.call_method(method, payload)
}
pub fn call_json_with_retry<R, P>(
&self,
method: &str,
payload: &P,
retry: RetryConfig,
) -> Result<R>
where
R: DeserializeOwned,
P: Serialize + ?Sized,
{
retry_with_config_blocking(&retry, || self.client.call_method(method, payload))
}
pub fn call_no_params<R>(&self, method: &str) -> Result<R>
where
R: DeserializeOwned,
{
self.client.call_method_no_params(method)
}
pub fn call_no_params_with_retry<R>(&self, method: &str, retry: RetryConfig) -> Result<R>
where
R: DeserializeOwned,
{
retry_with_config_blocking(&retry, || self.client.call_method_no_params(method))
}
pub fn call_multipart<R, P>(
&self,
method: &str,
payload: &P,
file_field_name: &str,
file: &UploadFile,
) -> Result<R>
where
R: DeserializeOwned,
P: Serialize + ?Sized,
{
self.client
.call_method_multipart(method, payload, file_field_name, file)
}
pub fn call_multipart_with_retry<R, P>(
&self,
method: &str,
payload: &P,
file_field_name: &str,
file: &UploadFile,
retry: RetryConfig,
) -> Result<R>
where
R: DeserializeOwned,
P: Serialize + ?Sized,
{
retry_with_config_blocking(&retry, || {
self.client
.call_method_multipart(method, payload, file_field_name, file)
})
}
}