Skip to main content

neptunium_http/endpoints/webhooks/
update_webhook.rs

1use bon::Builder;
2use neptunium_model::{
3    guild::webhook::Webhook,
4    id::{
5        Id,
6        marker::{ChannelMarker, WebhookMarker},
7    },
8};
9use reqwest::Method;
10use serde::Serialize;
11
12use crate::{endpoints::Endpoint, request::Request};
13
14#[derive(Serialize, Builder, Clone, Debug)]
15pub struct UpdateWebhookBody {
16    #[builder(into)]
17    #[serde(skip_serializing_if = "Option::is_none")]
18    pub name: Option<String>,
19    // TODO: Check whether webhook avatars can be removed, and if yes, how?
20    #[builder(into)]
21    #[serde(skip_serializing_if = "Option::is_none")]
22    pub avatar: Option<String>,
23    #[serde(skip_serializing_if = "Option::is_none")]
24    pub channel_id: Option<Id<ChannelMarker>>,
25}
26
27#[derive(Builder, Clone, Debug)]
28pub struct UpdateWebhook {
29    pub webhook_id: Id<WebhookMarker>,
30    pub body: UpdateWebhookBody,
31}
32
33impl Endpoint for UpdateWebhook {
34    type Response = Webhook;
35
36    fn into_request(self) -> crate::request::Request {
37        Request::builder()
38            .method(Method::PATCH)
39            .body(serde_json::to_string(&self.body).unwrap())
40            .path(format!("/webhooks/{}", self.webhook_id))
41            .build()
42    }
43}