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