use crate::RestApi;
use crate::errors::Error;
use crate::rest_api::HTTPMethod;
use crate::rest_api::builder::sobjects::SObjectsBuilder;
use crate::rest_api::responses::rest_response::RestResponse;
use serde::de::DeserializeOwned;
impl RestApi {
pub async fn sobject_by_id<'a, T: DeserializeOwned>(&self, sobject_name: &str, id: &str) -> Result<T, Error> {
self.build()
.sobjects()
.get_by_id(sobject_name, id)
.send()
.await?
.rest_response()
.await
}
}
impl<'a> SObjectsBuilder<'a> {
pub fn get_by_id(&self, sobject_type: &str, id: &str) -> SObjectSelectByIdBuilder<'_> {
SObjectSelectByIdBuilder::new(self, sobject_type, id)
}
}
pub struct SObjectSelectByIdBuilder<'a> {
builder: &'a SObjectsBuilder<'a>,
sobject_type: String,
id: String,
}
impl<'a> SObjectSelectByIdBuilder<'a> {
pub(crate) fn new(builder: &'a SObjectsBuilder, sobject_type: &str, id: &str) -> SObjectSelectByIdBuilder<'a> {
Self {
builder,
sobject_type: sobject_type.to_string(),
id: id.to_string(),
}
}
pub async fn send(&self) -> Result<RestResponse, Error> {
let param: Vec<(&str, &str)> = vec![];
let response = self
.builder
.send(HTTPMethod::GET, format!("{}/{}", self.sobject_type, self.id), ¶m)
.await?;
Ok(RestResponse::new(response))
}
}