twilight_http/request/application/interaction/
delete_response.rs1#[cfg(not(target_os = "wasi"))]
2use crate::response::{Response, ResponseFuture, marker::EmptyBody};
3use crate::{
4 client::Client,
5 error::Error,
6 request::{Request, TryIntoRequest},
7 routing::Route,
8};
9use std::future::IntoFuture;
10use twilight_model::id::{Id, marker::ApplicationMarker};
11
12#[must_use = "requests must be configured and executed"]
35pub struct DeleteResponse<'a> {
36 application_id: Id<ApplicationMarker>,
37 http: &'a Client,
38 token: &'a str,
39}
40
41impl<'a> DeleteResponse<'a> {
42 pub(crate) const fn new(
43 http: &'a Client,
44 application_id: Id<ApplicationMarker>,
45 token: &'a str,
46 ) -> Self {
47 Self {
48 application_id,
49 http,
50 token,
51 }
52 }
53}
54
55#[cfg(not(target_os = "wasi"))]
56impl IntoFuture for DeleteResponse<'_> {
57 type Output = Result<Response<EmptyBody>, Error>;
58
59 type IntoFuture = ResponseFuture<EmptyBody>;
60
61 fn into_future(self) -> Self::IntoFuture {
62 let http = self.http;
63
64 match self.try_into_request() {
65 Ok(request) => http.request(request),
66 Err(source) => ResponseFuture::error(source),
67 }
68 }
69}
70
71impl TryIntoRequest for DeleteResponse<'_> {
72 fn try_into_request(self) -> Result<Request, Error> {
73 Request::builder(&Route::DeleteInteractionOriginal {
74 application_id: self.application_id.get(),
75 interaction_token: self.token,
76 })
77 .use_authorization_token(false)
78 .build()
79 }
80}
81
82#[cfg(test)]
83mod tests {
84 use crate::{client::Client, request::TryIntoRequest};
85 use std::error::Error;
86 use twilight_model::id::Id;
87
88 #[test]
89 fn delete_followup_message() -> Result<(), Box<dyn Error>> {
90 let application_id = Id::new(1);
91 let token = "foo".to_owned();
92
93 let client = Client::new(String::new());
94 let req = client
95 .interaction(application_id)
96 .delete_response(&token)
97 .try_into_request()?;
98
99 assert!(!req.use_authorization_token());
100
101 Ok(())
102 }
103}