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