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