apify_client/clients/
webhook.rs1use serde::Serialize;
4
5use crate::clients::base::{
6 delete_resource, get_resource, post_action, update_resource, ResourceContext,
7};
8use crate::clients::webhook_dispatch_collection::WebhookDispatchCollectionClient;
9use crate::common::QueryParams;
10use crate::error::ApifyClientResult;
11use crate::http_client::HttpClient;
12use crate::models::{Webhook, WebhookDispatch};
13
14#[derive(Debug, Clone)]
16pub struct WebhookClient {
17 ctx: ResourceContext,
18}
19
20impl WebhookClient {
21 pub(crate) fn new(http: HttpClient, base_url: &str, id: &str) -> Self {
22 Self {
23 ctx: ResourceContext::single(http, base_url, "webhooks", id),
24 }
25 }
26
27 pub async fn get(&self) -> ApifyClientResult<Option<Webhook>> {
29 get_resource(&self.ctx, None, &QueryParams::new()).await
30 }
31
32 pub async fn update<T: Serialize>(&self, new_fields: &T) -> ApifyClientResult<Webhook> {
34 update_resource(&self.ctx, None, new_fields).await
35 }
36
37 pub async fn delete(&self) -> ApifyClientResult<()> {
39 delete_resource(&self.ctx, None).await
40 }
41
42 pub async fn test(&self) -> ApifyClientResult<WebhookDispatch> {
44 post_action(&self.ctx, Some("test"), &QueryParams::new(), None, None).await
45 }
46
47 pub fn dispatches(&self) -> WebhookDispatchCollectionClient {
49 WebhookDispatchCollectionClient::with_base(
50 self.ctx.http.clone(),
51 &self.ctx.url(None),
52 "dispatches",
53 )
54 }
55}