modio/request/auth/
email_exchange.rs1use std::future::IntoFuture;
2
3use serde_derive::Serialize;
4
5use crate::client::Client;
6use crate::request::{Output, RequestBuilder, Route};
7use crate::response::ResponseFuture;
8use crate::types::auth::AccessToken;
9
10pub struct EmailExchange<'a> {
12 http: &'a Client,
13 fields: EmailExchangeFields<'a>,
14}
15
16#[derive(Serialize)]
17struct EmailExchangeFields<'a> {
18 security_code: &'a str,
19 #[serde(rename = "date_expires", skip_serializing_if = "Option::is_none")]
20 expired_at: Option<u64>,
21}
22
23impl<'a> EmailExchange<'a> {
24 pub(crate) const fn new(http: &'a Client, security_code: &'a str) -> Self {
25 Self {
26 http,
27 fields: EmailExchangeFields {
28 security_code,
29 expired_at: None,
30 },
31 }
32 }
33
34 pub const fn expired_at(mut self, expired_at: u64) -> Self {
35 self.fields.expired_at = Some(expired_at);
36 self
37 }
38}
39
40impl IntoFuture for EmailExchange<'_> {
41 type Output = Output<AccessToken>;
42 type IntoFuture = ResponseFuture<AccessToken>;
43
44 fn into_future(self) -> Self::IntoFuture {
45 let route = Route::OAuthEmailExchange;
46 match RequestBuilder::from_route(&route).form(&self.fields) {
47 Ok(req) => self.http.request(req),
48 Err(err) => ResponseFuture::failed(err),
49 }
50 }
51}