Skip to main content

prismer_sdk/
parse.rs

1use crate::{PrismerClient, types::*};
2use serde_json::json;
3
4pub struct ParseClient<'a> {
5    pub(crate) client: &'a PrismerClient,
6}
7
8impl<'a> ParseClient<'a> {
9    /// Submit a document for parsing (URL or base64).
10    pub async fn submit(&self, input: &str, mode: Option<&str>) -> Result<ApiResponse<ParseResult>, PrismerError> {
11        self.client.request(
12            reqwest::Method::POST,
13            "/api/parse",
14            Some(json!({
15                "input": input,
16                "mode": mode.unwrap_or("fast"),
17            })),
18        ).await
19    }
20
21    /// Check parse task status.
22    pub async fn status(&self, task_id: &str) -> Result<ApiResponse<ParseResult>, PrismerError> {
23        self.client.request(
24            reqwest::Method::GET,
25            &format!("/api/parse/status/{}", task_id),
26            None,
27        ).await
28    }
29
30    /// Get parse result.
31    pub async fn result(&self, task_id: &str) -> Result<ApiResponse<ParseResult>, PrismerError> {
32        self.client.request(
33            reqwest::Method::GET,
34            &format!("/api/parse/result/{}", task_id),
35            None,
36        ).await
37    }
38}