apify_client/clients/
dataset_collection.rs1use crate::clients::base::{get_or_create_named, list_resource, ResourceContext};
4use crate::clients::pagination::{list_iterator, ListIterator};
5use crate::common::{PaginationList, QueryParams, StorageListOptions};
6use crate::error::ApifyClientResult;
7use crate::http_client::HttpClient;
8use crate::models::Dataset;
9
10#[derive(Debug, Clone)]
12pub struct DatasetCollectionClient {
13 ctx: ResourceContext,
14}
15
16impl DatasetCollectionClient {
17 pub(crate) fn new(http: HttpClient, base_url: &str) -> Self {
18 Self {
19 ctx: ResourceContext::collection(http, base_url, "datasets"),
20 }
21 }
22
23 pub async fn list(
25 &self,
26 options: StorageListOptions,
27 ) -> ApifyClientResult<PaginationList<Dataset>> {
28 let mut params = QueryParams::new();
29 options.apply(&mut params);
30 list_resource(&self.ctx, None, ¶ms).await
31 }
32
33 pub fn iterate(&self, options: StorageListOptions) -> ListIterator<Dataset> {
40 list_iterator!(self, options, list)
41 }
42
43 pub async fn get_or_create(&self, name: Option<&str>) -> ApifyClientResult<Dataset> {
47 get_or_create_named(&self.ctx, name).await
48 }
49}