use crate::client::client::Client;
use crate::errors::Error;
use responses::error_response::ErrorResponse;
use reqwest::Response;
use serde::de::DeserializeOwned;
pub mod responses;
#[derive(Default)]
pub struct RestApi {
pub(crate) client: Client,
}
async fn handle_json_response<T: DeserializeOwned>(response: Response) -> Result<T, Error> { if response.status().is_success() {
Ok(response.json().await?)
} else {
let errors: Vec<ErrorResponse> = response.json().await?;
Err(Error::ErrorResponses(errors))
}
}
async fn handle_empty_response(response: Response) -> Result<(), Error> {
if response.status().is_success() {
Ok(())
} else {
let errors: Vec<ErrorResponse> = response.json().await?;
Err(Error::ErrorResponses(errors))
}
}
impl RestApi {
pub fn new(client: Client) -> Self {
RestApi { client }
}
}
#[cfg(test)]
mod test;
pub mod sobjects;
pub mod composite;
pub mod query;
pub mod search;
pub mod services;
pub mod user_password;