apify_client/clients/
build.rs1use crate::clients::base::{
4 delete_resource, get_resource, post_action, wait_for_finish, ResourceContext,
5};
6use crate::clients::log::LogClient;
7use crate::common::QueryParams;
8use crate::error::ApifyClientResult;
9use crate::http_client::HttpClient;
10use crate::models::Build;
11
12#[derive(Debug, Clone)]
14pub struct BuildClient {
15 ctx: ResourceContext,
16}
17
18impl BuildClient {
19 pub(crate) fn new(http: HttpClient, base_url: &str, id: &str) -> Self {
20 Self {
21 ctx: ResourceContext::single(http, base_url, "actor-builds", id),
22 }
23 }
24
25 pub async fn get(&self) -> ApifyClientResult<Option<Build>> {
27 get_resource(&self.ctx, None, &QueryParams::new()).await
28 }
29
30 pub async fn abort(&self) -> ApifyClientResult<Build> {
32 post_action(&self.ctx, Some("abort"), &QueryParams::new(), None, None).await
33 }
34
35 pub async fn delete(&self) -> ApifyClientResult<()> {
37 delete_resource(&self.ctx, None).await
38 }
39
40 pub async fn wait_for_finish(&self, wait_secs: Option<i64>) -> ApifyClientResult<Build> {
48 wait_for_finish(&self.ctx, wait_secs, |b: &Build| b.is_terminal()).await
49 }
50
51 pub async fn get_openapi_definition(&self) -> ApifyClientResult<Option<serde_json::Value>> {
56 let response =
57 crate::clients::base::get_raw(&self.ctx, Some("openapi.json"), &QueryParams::new())
58 .await?;
59 match response {
60 Some(r) => Ok(Some(serde_json::from_slice(&r.body)?)),
61 None => Ok(None),
62 }
63 }
64
65 pub fn log(&self) -> LogClient {
67 LogClient::nested(self.ctx.http.clone(), &self.ctx.url(None), "log")
68 }
69}