use serde::Serialize;
use crate::{send_and_translate_response, Deepgram};
use response::Message;
pub mod response;
#[derive(Debug, Clone)]
pub struct Scopes<'a>(&'a Deepgram);
impl Deepgram {
pub fn scopes(&self) -> Scopes<'_> {
self.into()
}
}
impl<'a> From<&'a Deepgram> for Scopes<'a> {
fn from(deepgram: &'a Deepgram) -> Self {
Self(deepgram)
}
}
impl Scopes<'_> {
pub async fn get_scope(
&self,
project_id: &str,
member_id: &str,
) -> crate::Result<response::Scopes> {
let url = format!(
"https://api.deepgram.com/v1/projects/{project_id}/members/{member_id}/scopes "
);
send_and_translate_response(self.0.client.get(url)).await
}
pub async fn update_scope(
&self,
project_id: &str,
member_id: &str,
scope: &str,
) -> crate::Result<Message> {
#[derive(Serialize)]
struct Scope<'a> {
scope: &'a str,
}
let url =
format!("https://api.deepgram.com/v1/projects/{project_id}/members/{member_id}/scopes");
let request = self.0.client.put(url).json(&Scope { scope });
send_and_translate_response(request).await
}
}