twilight_http/request/
get_current_authorization_information.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::oauth::CurrentAuthorizationInformation;
11
12#[must_use = "requests must be configured and executed"]
42pub struct GetCurrentAuthorizationInformation<'a> {
43 http: &'a Client,
44}
45
46impl<'a> GetCurrentAuthorizationInformation<'a> {
47 pub(crate) const fn new(http: &'a Client) -> Self {
48 Self { http }
49 }
50}
51
52#[cfg(not(target_os = "wasi"))]
53impl IntoFuture for GetCurrentAuthorizationInformation<'_> {
54 type Output = Result<Response<CurrentAuthorizationInformation>, Error>;
55
56 type IntoFuture = ResponseFuture<CurrentAuthorizationInformation>;
57
58 fn into_future(self) -> Self::IntoFuture {
59 let http = self.http;
60
61 match self.try_into_request() {
62 Ok(request) => http.request(request),
63 Err(source) => ResponseFuture::error(source),
64 }
65 }
66}
67
68impl TryIntoRequest for GetCurrentAuthorizationInformation<'_> {
69 fn try_into_request(self) -> Result<Request, Error> {
70 Ok(Request::from_route(
71 &Route::GetCurrentAuthorizationInformation,
72 ))
73 }
74}
75
76#[cfg(test)]
77mod tests {
78 use super::GetCurrentAuthorizationInformation;
79 use crate::{client::Client, request::TryIntoRequest};
80 use static_assertions::assert_impl_all;
81 use std::{error::Error, future::IntoFuture};
82 use twilight_http_ratelimiting::Method;
83
84 assert_impl_all!(GetCurrentAuthorizationInformation<'_>: IntoFuture, Send, Sync, TryIntoRequest);
85
86 #[test]
87 fn get_current_authorization_information() -> Result<(), Box<dyn Error>> {
88 let client = Client::new(String::new());
89 let req = client.current_authorization().try_into_request()?;
90
91 assert!(req.use_authorization_token());
92 assert!(req.body().is_none());
93 assert!(req.form().is_none());
94 assert!(req.headers().is_none());
95 assert_eq!(Method::Get, req.method());
96
97 Ok(())
98 }
99}