use crate::{
auth::{
options::{Options, SerializableOptions},
response::GrantResponse,
},
send_and_translate_response, Deepgram,
};
pub mod options;
pub mod response;
#[derive(Debug, Clone)]
pub struct Auth<'a>(&'a Deepgram);
impl Deepgram {
pub fn auth(&self) -> Auth<'_> {
self.into()
}
}
impl<'a> From<&'a Deepgram> for Auth<'a> {
fn from(deepgram: &'a Deepgram) -> Self {
Self(deepgram)
}
}
impl Auth<'_> {
pub async fn grant(&self, options: Option<&Options>) -> crate::Result<GrantResponse> {
let url = "https://api.deepgram.com/v1/auth/grant";
let request = if let Some(opts) = options {
self.0
.client
.post(url)
.json(&SerializableOptions::from(opts))
} else {
self.0.client.post(url).json(&serde_json::json!({}))
};
send_and_translate_response(request).await
}
}