use crate::internal::path_escape;
use crate::runtime::{self, Error};
#[derive(Clone, Debug, Default)]
pub struct InvitesCreateOptions {
pub fields: Option<Vec<String>>,
}
#[derive(Clone, Debug, Default)]
pub struct InvitesGetOptions {
pub fields: Option<Vec<String>>,
}
pub struct InvitesManager {
session: std::sync::Arc<runtime::Client>,
}
impl InvitesManager {
pub(crate) fn new(session: std::sync::Arc<runtime::Client>) -> Self {
Self { session }
}
pub async fn create(
&self,
body: crate::models::schemas::CreateInviteRequest,
opts: Option<InvitesCreateOptions>,
) -> Result<crate::models::schemas::Invite, Error> {
let mut url = self.session.base_url("api");
url.push_str("/invites");
let mut req = self.session.new_request("POST", &url);
let opts = opts.unwrap_or_default();
if let Some(value) = opts.fields {
req = runtime::with_query(req, "fields", &value.join(","));
}
let payload = serde_json::to_vec(&body)?;
req = runtime::with_json_body(req, &payload);
let resp = self.session.fetch(req).await?;
let data = runtime::response_bytes(&resp)?;
Ok(serde_json::from_slice(&data)?)
}
pub async fn get(
&self,
invite_id: String,
opts: Option<InvitesGetOptions>,
) -> Result<crate::models::schemas::Invite, Error> {
let mut url = self.session.base_url("api");
url.push_str("/invites");
url.push('/');
let seg = path_escape(&invite_id);
url.push_str(&seg);
let mut req = self.session.new_request("GET", &url);
let opts = opts.unwrap_or_default();
if let Some(value) = opts.fields {
req = runtime::with_query(req, "fields", &value.join(","));
}
let resp = self.session.fetch(req).await?;
let data = runtime::response_bytes(&resp)?;
Ok(serde_json::from_slice(&data)?)
}
}