use crate::_prelude::*;
mod create;
pub use create::*;
mod event;
pub use event::*;
mod object;
pub use object::*;
mod r#type;
pub use r#type::*;
pub trait ApiResponse
where
Self: ApiBase,
{
fn create_response(
&self,
mut request: ResponseRequest,
) -> impl Send + Future<Output = Result<ResponseObject>> {
async {
request.stream = None;
let resp = self.post_json("/responses", request).await?;
tracing::debug!("{resp}");
Ok(serde_json::from_str::<ApiResult<ResponseObject>>(&resp)?.as_result()?)
}
}
fn create_response_stream<H>(
&self,
mut request: ResponseRequest,
options: SseOptions<H>,
) -> impl Send + Future<Output = Result<EventStream<H::Event>>>
where
H: 'static + EventHandler,
{
async move {
request.stream = Some(true);
self.sse("/responses", request, options).await
}
}
}
impl<T> ApiResponse for T where T: ApiBase {}