uarp_sdk/generated/api/
webhooks.rs1#![allow(unused_imports, clippy::too_many_arguments)]
6
7use reqwest::Method;
8use serde::{Deserialize, Serialize};
9
10use crate::client::{Client, Request, NO_BODY, NO_QUERY};
11use crate::error::Result;
12use crate::generated::models;
13use crate::multipart::{field_text, FilePart};
14use crate::util::encode_path;
15
16#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
18pub struct SensorWebhookParams {
19 #[serde(skip)]
21 pub x_sensor_signature: String,
22}
23
24#[derive(Debug, Clone)]
26pub struct WebhooksApi {
27 pub(crate) client: Client,
28}
29
30impl Client {
31 pub fn webhooks(&self) -> WebhooksApi {
33 WebhooksApi { client: self.clone() }
34 }
35}
36
37impl WebhooksApi {
38 pub async fn create(&self, body: &models::CreateWebhookRequest) -> Result<models::WebhookSubscription> {
44 self.client
45 .request_json(Request {
46 method: Method::POST,
47 path: "/api/v1/webhooks".to_string(),
48 query: NO_QUERY,
49 body: Some(body),
50 headers: Vec::new(),
51 idempotent: true,
52 })
53 .await
54 }
55
56 pub async fn delete(&self, webhook_id: &str) -> Result<models::DeleteWebhookResponse> {
62 self.client
63 .request_json(Request {
64 method: Method::DELETE,
65 path: format!("/api/v1/webhooks/{}", encode_path(webhook_id)),
66 query: NO_QUERY,
67 body: NO_BODY,
68 headers: Vec::new(),
69 idempotent: true,
70 })
71 .await
72 }
73
74 pub async fn get(&self, webhook_id: &str) -> Result<models::WebhookSubscription> {
80 self.client
81 .request_json(Request {
82 method: Method::GET,
83 path: format!("/api/v1/webhooks/{}", encode_path(webhook_id)),
84 query: NO_QUERY,
85 body: NO_BODY,
86 headers: Vec::new(),
87 idempotent: false,
88 })
89 .await
90 }
91
92 pub async fn list(&self) -> Result<models::ListWebhooksResponse> {
98 self.client
99 .request_json(Request {
100 method: Method::GET,
101 path: "/api/v1/webhooks".to_string(),
102 query: NO_QUERY,
103 body: NO_BODY,
104 headers: Vec::new(),
105 idempotent: false,
106 })
107 .await
108 }
109
110 pub async fn list_webhook_deliveries(&self, webhook_id: &str) -> Result<models::ListWebhookDeliveriesResponse> {
116 self.client
117 .request_json(Request {
118 method: Method::GET,
119 path: format!("/api/v1/webhooks/{}/deliveries", encode_path(webhook_id)),
120 query: NO_QUERY,
121 body: NO_BODY,
122 headers: Vec::new(),
123 idempotent: false,
124 })
125 .await
126 }
127
128 pub async fn sensor_webhook(&self, webhook_id: &str, body: &serde_json::Map<String, serde_json::Value>, params: &SensorWebhookParams) -> Result<models::SensorWebhookResponse> {
136 let mut headers: Vec<(&'static str, String)> = Vec::new();
137 headers.push(("X-Sensor-Signature", params.x_sensor_signature.clone()));
138 self.client
139 .request_json(Request {
140 method: Method::POST,
141 path: format!("/api/v1/webhooks/sensor/{}", encode_path(webhook_id)),
142 query: NO_QUERY,
143 body: Some(body),
144 headers,
145 idempotent: true,
146 })
147 .await
148 }
149
150 pub async fn test_webhook(&self, webhook_id: &str) -> Result<models::TestWebhookResponse> {
165 self.client
166 .request_json(Request {
167 method: Method::POST,
168 path: format!("/api/v1/webhooks/{}/test", encode_path(webhook_id)),
169 query: NO_QUERY,
170 body: NO_BODY,
171 headers: Vec::new(),
172 idempotent: true,
173 })
174 .await
175 }
176}