Skip to main content

apify_client/clients/
webhook_dispatch_collection.rs

1//! Client for the webhook dispatch collection (`/v2/webhook-dispatches`).
2
3use crate::clients::base::{list_resource, ResourceContext};
4use crate::clients::pagination::{list_iterator, ListIterator};
5use crate::common::{ListOptions, PaginationList, QueryParams};
6use crate::error::ApifyClientResult;
7use crate::http_client::HttpClient;
8use crate::models::WebhookDispatch;
9
10/// Client for listing webhook dispatches.
11#[derive(Debug, Clone)]
12pub struct WebhookDispatchCollectionClient {
13    ctx: ResourceContext,
14}
15
16impl WebhookDispatchCollectionClient {
17    pub(crate) fn new(http: HttpClient, base_url: &str) -> Self {
18        Self {
19            ctx: ResourceContext::collection(http, base_url, "webhook-dispatches"),
20        }
21    }
22
23    /// Creates a dispatch collection client nested under a webhook.
24    pub(crate) fn with_base(http: HttpClient, base_url: &str, resource_path: &str) -> Self {
25        Self {
26            ctx: ResourceContext::collection(http, base_url, resource_path),
27        }
28    }
29
30    /// Lists webhook dispatches with offset/limit pagination.
31    pub async fn list(
32        &self,
33        options: ListOptions,
34    ) -> ApifyClientResult<PaginationList<WebhookDispatch>> {
35        let mut params = QueryParams::new();
36        params
37            .add_int("offset", options.offset)
38            .add_int("limit", options.limit)
39            .add_bool("desc", options.desc);
40        list_resource(&self.ctx, None, &params).await
41    }
42
43    /// Lazily iterates over all webhook dispatches matching `options`, fetching pages on demand.
44    ///
45    /// `options.limit` caps the *total* number of items yielded across all pages, unlike
46    /// [`list`](Self::list) where `limit` is a single page's size. Set the per-page fetch size
47    /// with [`with_chunk_size`](crate::ListIterator::with_chunk_size); see
48    /// [`ListIterator`] for details.
49    pub fn iterate(&self, options: ListOptions) -> ListIterator<WebhookDispatch> {
50        list_iterator!(self, options, list)
51    }
52}