Skip to main content

apify_client/clients/
request_queue_collection.rs

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