apify_client/clients/
webhook_collection.rs1use serde::Serialize;
4
5use crate::clients::base::{create_resource, list_resource, ResourceContext};
6use crate::clients::pagination::{list_iterator, ListIterator};
7use crate::common::{ListOptions, PaginationList, QueryParams};
8use crate::error::ApifyClientResult;
9use crate::http_client::HttpClient;
10use crate::models::Webhook;
11
12#[derive(Debug, Clone)]
14pub struct WebhookCollectionClient {
15 ctx: ResourceContext,
16}
17
18impl WebhookCollectionClient {
19 pub(crate) fn new(http: HttpClient, base_url: &str) -> Self {
20 Self {
21 ctx: ResourceContext::collection(http, base_url, "webhooks"),
22 }
23 }
24
25 pub(crate) fn with_base(http: HttpClient, base_url: &str) -> Self {
27 Self {
28 ctx: ResourceContext::collection(http, base_url, "webhooks"),
29 }
30 }
31
32 pub async fn list(&self, options: ListOptions) -> ApifyClientResult<PaginationList<Webhook>> {
34 let mut params = QueryParams::new();
35 params
36 .add_int("offset", options.offset)
37 .add_int("limit", options.limit)
38 .add_bool("desc", options.desc);
39 list_resource(&self.ctx, None, ¶ms).await
40 }
41
42 pub fn iterate(&self, options: ListOptions) -> ListIterator<Webhook> {
49 list_iterator!(self, options, list)
50 }
51
52 pub async fn create<T: Serialize>(&self, webhook: &T) -> ApifyClientResult<Webhook> {
54 create_resource(&self.ctx, &QueryParams::new(), webhook).await
55 }
56}