apify_client/clients/
schedule.rs1use serde::Serialize;
4
5use crate::clients::base::{
6 delete_resource, get_raw, get_resource, update_resource, ResourceContext,
7};
8use crate::common::QueryParams;
9use crate::error::ApifyClientResult;
10use crate::http_client::HttpClient;
11use crate::models::Schedule;
12
13#[derive(Debug, Clone)]
15pub struct ScheduleClient {
16 ctx: ResourceContext,
17}
18
19impl ScheduleClient {
20 pub(crate) fn new(http: HttpClient, base_url: &str, id: &str) -> Self {
21 Self {
22 ctx: ResourceContext::single(http, base_url, "schedules", id),
23 }
24 }
25
26 pub async fn get(&self) -> ApifyClientResult<Option<Schedule>> {
28 get_resource(&self.ctx, None, &QueryParams::new()).await
29 }
30
31 pub async fn update<T: Serialize>(&self, new_fields: &T) -> ApifyClientResult<Schedule> {
33 update_resource(&self.ctx, None, new_fields).await
34 }
35
36 pub async fn delete(&self) -> ApifyClientResult<()> {
38 delete_resource(&self.ctx, None).await
39 }
40
41 pub async fn get_log(&self) -> ApifyClientResult<Option<String>> {
43 let response = get_raw(&self.ctx, Some("log"), &QueryParams::new()).await?;
44 match response {
45 Some(r) => Ok(Some(String::from_utf8_lossy(&r.body).into_owned())),
46 None => Ok(None),
47 }
48 }
49}