use crate::clients::base::{
delete_resource, get_resource, post_action, wait_for_finish, ResourceContext,
};
use crate::clients::log::LogClient;
use crate::common::QueryParams;
use crate::error::ApifyClientResult;
use crate::http_client::HttpClient;
use crate::models::Build;
#[derive(Debug, Clone)]
pub struct BuildClient {
ctx: ResourceContext,
}
impl BuildClient {
pub(crate) fn new(http: HttpClient, base_url: &str, id: &str) -> Self {
Self {
ctx: ResourceContext::single(http, base_url, "actor-builds", id),
}
}
pub async fn get(&self) -> ApifyClientResult<Option<Build>> {
get_resource(&self.ctx, None, &QueryParams::new()).await
}
pub async fn abort(&self) -> ApifyClientResult<Build> {
post_action(&self.ctx, Some("abort"), &QueryParams::new(), None, None).await
}
pub async fn delete(&self) -> ApifyClientResult<()> {
delete_resource(&self.ctx, None).await
}
pub async fn wait_for_finish(&self, wait_secs: Option<i64>) -> ApifyClientResult<Build> {
wait_for_finish(&self.ctx, wait_secs, |b: &Build| b.is_terminal()).await
}
pub async fn get_openapi_definition(&self) -> ApifyClientResult<Option<serde_json::Value>> {
let response =
crate::clients::base::get_raw(&self.ctx, Some("openapi.json"), &QueryParams::new())
.await?;
match response {
Some(r) => Ok(Some(serde_json::from_slice(&r.body)?)),
None => Ok(None),
}
}
pub fn log(&self) -> LogClient {
LogClient::nested(self.ctx.http.clone(), &self.ctx.url(None), "log")
}
}