use crate::client::Scope;
use crate::error::Error;
use crate::generated::routes;
use crate::generated::types::*;
pub struct SessionsService<'a> {
scope: Scope<'a>,
}
impl<'a> SessionsService<'a> {
pub(crate) fn new(scope: Scope<'a>) -> Self {
Self { scope }
}
pub fn scope(&self) -> &Scope<'a> {
&self.scope
}
pub async fn complete_join(&self, body: &CompleteJoinRequestContent) -> Result<(), Error> {
let mut operation = self.scope.operation(&routes::COMPLETE_JOIN, &[])?;
operation.json(body)?;
self.scope.client().send_unit(operation).await
}
pub async fn complete_signup(&self, body: &CompleteSignupRequestContent) -> Result<(), Error> {
let mut operation = self.scope.operation(&routes::COMPLETE_SIGNUP, &[])?;
operation.json(body)?;
self.scope.client().send_unit(operation).await
}
pub async fn create(
&self,
body: &CreateSessionRequestContent,
) -> Result<PendingAuthentication, Error> {
let mut operation = self.scope.operation(&routes::CREATE_SESSION, &[])?;
operation.json(body)?;
self.scope.client().send(operation).await
}
pub async fn destroy(&self) -> Result<(), Error> {
let operation = self.scope.operation(&routes::DESTROY_SESSION, &[])?;
self.scope.client().send_unit(operation).await
}
pub async fn redeem_magic_link(
&self,
body: &RedeemMagicLinkRequestContent,
) -> Result<SessionAuthorization, Error> {
let mut operation = self.scope.operation(&routes::REDEEM_MAGIC_LINK, &[])?;
operation.json(body)?;
self.scope.client().send(operation).await
}
}