apify_client/clients/
schedule_collection.rs1use serde::Serialize;
4
5use crate::clients::base::{create_resource, list_resource, ResourceContext};
6use crate::clients::pagination::{list_iterator, ListIterator};
7use crate::common::{ListOptions, PaginationList, QueryParams};
8use crate::error::ApifyClientResult;
9use crate::http_client::HttpClient;
10use crate::models::Schedule;
11
12#[derive(Debug, Clone)]
14pub struct ScheduleCollectionClient {
15 ctx: ResourceContext,
16}
17
18impl ScheduleCollectionClient {
19 pub(crate) fn new(http: HttpClient, base_url: &str) -> Self {
20 Self {
21 ctx: ResourceContext::collection(http, base_url, "schedules"),
22 }
23 }
24
25 pub async fn list(&self, options: ListOptions) -> ApifyClientResult<PaginationList<Schedule>> {
27 let mut params = QueryParams::new();
28 params
29 .add_int("offset", options.offset)
30 .add_int("limit", options.limit)
31 .add_bool("desc", options.desc);
32 list_resource(&self.ctx, None, ¶ms).await
33 }
34
35 pub fn iterate(&self, options: ListOptions) -> ListIterator<Schedule> {
42 list_iterator!(self, options, list)
43 }
44
45 pub async fn create<T: Serialize>(&self, schedule: &T) -> ApifyClientResult<Schedule> {
47 create_resource(&self.ctx, &QueryParams::new(), schedule).await
48 }
49}