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