1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//! Client for the dataset collection (`/v2/datasets`).
use crate::clients::base::{get_or_create_named, list_resource, ResourceContext};
use crate::clients::pagination::{list_iterator, ListIterator};
use crate::common::{PaginationList, QueryParams, StorageListOptions};
use crate::error::ApifyClientResult;
use crate::http_client::HttpClient;
use crate::models::Dataset;
/// Client for listing datasets and getting-or-creating a dataset by name.
#[derive(Debug, Clone)]
pub struct DatasetCollectionClient {
ctx: ResourceContext,
}
impl DatasetCollectionClient {
pub(crate) fn new(http: HttpClient, base_url: &str) -> Self {
Self {
ctx: ResourceContext::collection(http, base_url, "datasets"),
}
}
/// Lists datasets with offset/limit pagination, optionally filtering by `unnamed`/`ownership`.
pub async fn list(
&self,
options: StorageListOptions,
) -> ApifyClientResult<PaginationList<Dataset>> {
let mut params = QueryParams::new();
options.apply(&mut params);
list_resource(&self.ctx, None, ¶ms).await
}
/// Lazily iterates over all datasets matching `options`, fetching pages on demand.
///
/// `options.limit` caps the *total* number of items yielded across all pages, unlike
/// [`list`](Self::list) where `limit` is a single page's size. Set the per-page fetch size
/// with [`with_chunk_size`](crate::ListIterator::with_chunk_size); see
/// [`ListIterator`] for details.
pub fn iterate(&self, options: StorageListOptions) -> ListIterator<Dataset> {
list_iterator!(self, options, list)
}
/// Gets the dataset with the given `name`, creating it if it does not exist.
///
/// Passing `None` for `name` creates an unnamed dataset.
pub async fn get_or_create(&self, name: Option<&str>) -> ApifyClientResult<Dataset> {
get_or_create_named(&self.ctx, name).await
}
}