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