use crate::{
client::Client,
error::Error,
request::{GetGatewayAuthed, Request, TryIntoRequest},
response::{Response, ResponseFuture},
routing::Route,
};
use std::future::IntoFuture;
use twilight_model::gateway::connection_info::ConnectionInfo;
#[must_use = "requests must be configured and executed"]
pub struct GetGateway<'a> {
http: &'a Client,
}
impl<'a> GetGateway<'a> {
pub(crate) const fn new(http: &'a Client) -> Self {
Self { http }
}
pub const fn authed(self) -> GetGatewayAuthed<'a> {
GetGatewayAuthed::new(self.http)
}
}
impl IntoFuture for GetGateway<'_> {
type Output = Result<Response<ConnectionInfo>, Error>;
type IntoFuture = ResponseFuture<ConnectionInfo>;
fn into_future(self) -> Self::IntoFuture {
let http = self.http;
match self.try_into_request() {
Ok(request) => http.request(request),
Err(source) => ResponseFuture::error(source),
}
}
}
impl TryIntoRequest for GetGateway<'_> {
fn try_into_request(self) -> Result<Request, Error> {
Ok(Request::from_route(&Route::GetGateway))
}
}