use super::*;
#[cfg(feature = "_async")]
use super::super::retry::retry_method_async;
#[cfg(feature = "_blocking")]
use super::super::retry::retry_method_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_method_async(
method,
&retry,
self.client.total_timeout(),
|total_timeout| async move {
self.client
.call_method_attempt(method, payload, total_timeout)
.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_method_async(
method,
&retry,
self.client.total_timeout(),
|total_timeout| async move {
self.client
.call_method_no_params_attempt(method, total_timeout)
.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_files<R, P>(
&self,
method: &str,
payload: &P,
skip_fields: &[&str],
files: &[UploadPart],
) -> Result<R>
where
R: DeserializeOwned,
P: Serialize + ?Sized,
{
self.client
.call_method_multipart_files(method, payload, skip_fields, files)
.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_method_async(
method,
&retry,
self.client.total_timeout(),
|total_timeout| async move {
self.client
.call_method_multipart_attempt(
method,
payload,
file_field_name,
file,
total_timeout,
)
.await
},
)
.await
}
pub async fn call_multipart_files_with_retry<R, P>(
&self,
method: &str,
payload: &P,
skip_fields: &[&str],
files: &[UploadPart],
retry: RetryConfig,
) -> Result<R>
where
R: DeserializeOwned,
P: Serialize + ?Sized,
{
retry_method_async(
method,
&retry,
self.client.total_timeout(),
|total_timeout| async move {
self.client
.call_method_multipart_files_attempt(
method,
payload,
skip_fields,
files,
total_timeout,
)
.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_method_blocking(
method,
&retry,
self.client.total_timeout(),
|total_timeout| {
self.client
.call_method_attempt(method, payload, total_timeout)
},
)
}
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_method_blocking(
method,
&retry,
self.client.total_timeout(),
|total_timeout| {
self.client
.call_method_no_params_attempt(method, total_timeout)
},
)
}
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_files<R, P>(
&self,
method: &str,
payload: &P,
skip_fields: &[&str],
files: &[UploadPart],
) -> Result<R>
where
R: DeserializeOwned,
P: Serialize + ?Sized,
{
self.client
.call_method_multipart_files(method, payload, skip_fields, files)
}
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_method_blocking(
method,
&retry,
self.client.total_timeout(),
|total_timeout| {
self.client.call_method_multipart_attempt(
method,
payload,
file_field_name,
file,
total_timeout,
)
},
)
}
pub fn call_multipart_files_with_retry<R, P>(
&self,
method: &str,
payload: &P,
skip_fields: &[&str],
files: &[UploadPart],
retry: RetryConfig,
) -> Result<R>
where
R: DeserializeOwned,
P: Serialize + ?Sized,
{
retry_method_blocking(
method,
&retry,
self.client.total_timeout(),
|total_timeout| {
self.client.call_method_multipart_files_attempt(
method,
payload,
skip_fields,
files,
total_timeout,
)
},
)
}
}