Skip to main content

zai_rs/knowledge/
document_retrieve.rs

1use super::types::DocumentDetailResponse;
2use crate::client::ZaiClient;
3
4/// Retrieve document detail by id.
5///
6/// Credentials and transport live on the [`ZaiClient`], passed to
7/// [`send_via`](Self::send_via).
8pub struct DocumentRetrieveRequest {
9    document_id: String,
10}
11
12impl DocumentRetrieveRequest {
13    /// Create a new request targeting the given document id.
14    pub fn new(document_id: impl Into<String>) -> Self {
15        Self {
16            document_id: document_id.into(),
17        }
18    }
19
20    /// Send via a [`ZaiClient`] and parse the typed response.
21    pub async fn send_via(&self, client: &ZaiClient) -> crate::ZaiResult<DocumentDetailResponse> {
22        let route = crate::client::routes::DOCUMENTS_GET;
23        let url = client
24            .endpoints()
25            .resolve_route(route, &[&self.document_id])?;
26        client
27            .send_empty::<DocumentDetailResponse>(route.method(), url)
28            .await
29    }
30}