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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//! Client for the Actor collection endpoint (`/v2/actors`).
use serde::Serialize;
use crate::clients::base::{create_resource, list_resource, ResourceContext};
use crate::clients::pagination::{list_iterator, ListIterator};
use crate::common::{PaginationList, QueryParams};
use crate::error::ApifyClientResult;
use crate::http_client::HttpClient;
use crate::models::Actor;
/// Options for listing Actors (`GET /v2/actors`).
#[derive(Debug, Default, Clone)]
pub struct ActorListOptions {
/// Number of Actors to skip.
pub offset: Option<i64>,
/// Maximum number of Actors to return.
pub limit: Option<i64>,
/// Return Actors newest-first.
pub desc: Option<bool>,
/// If `true`, return only Actors owned by the current user.
pub my: Option<bool>,
/// Sort key, e.g. `createdAt` or `stats.lastRunStartedAt`.
pub sort_by: Option<String>,
}
/// Client for listing and creating Actors.
#[derive(Debug, Clone)]
pub struct ActorCollectionClient {
ctx: ResourceContext,
}
impl ActorCollectionClient {
pub(crate) fn new(http: HttpClient, base_url: &str) -> Self {
Self {
ctx: ResourceContext::collection(http, base_url, "actors"),
}
}
/// Lists the Actors in your account.
///
/// Use [`ActorListOptions::my`] to restrict the result to Actors you own.
pub async fn list(
&self,
options: ActorListOptions,
) -> ApifyClientResult<PaginationList<Actor>> {
let mut params = QueryParams::new();
params
.add_int("offset", options.offset)
.add_int("limit", options.limit)
.add_bool("desc", options.desc)
.add_bool("my", options.my)
.add_str("sortBy", options.sort_by);
list_resource(&self.ctx, None, ¶ms).await
}
/// Lazily iterates over all Actors matching `options`, fetching pages on demand.
///
/// Returns a [`ListIterator`] whose `next()` yields one Actor at a time, transparently
/// fetching subsequent pages until the listing is exhausted.
///
/// `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: ActorListOptions) -> ListIterator<Actor> {
list_iterator!(self, options, list)
}
/// Creates a new Actor with the given definition.
///
/// `actor` is any JSON-serializable Actor definition (at minimum a `name`).
pub async fn create<T: Serialize>(&self, actor: &T) -> ApifyClientResult<Actor> {
create_resource(&self.ctx, &QueryParams::new(), actor).await
}
}