Skip to main content

context69_sdk/client/
search.rs

1use context69_contracts::{DocumentResponse, SearchRequest, SearchResponse};
2use reqwest::Method;
3
4use crate::{Context69Client, Error};
5
6pub struct SearchApi<'a> {
7    client: &'a Context69Client,
8}
9
10impl<'a> SearchApi<'a> {
11    pub(crate) fn new(client: &'a Context69Client) -> Self {
12        Self { client }
13    }
14
15    pub async fn search(&self, request: SearchRequest) -> Result<SearchResponse, Error> {
16        self.client
17            .execute_json(
18                self.client
19                    .authorized_request(Method::POST, "/v1/search")
20                    .await?
21                    .json(&request),
22            )
23            .await
24    }
25
26    pub async fn get_document(&self, document_id: i64) -> Result<DocumentResponse, Error> {
27        let path = format!("/v1/documents/{document_id}");
28        self.client
29            .execute_json(self.client.authorized_request(Method::GET, &path).await?)
30            .await
31    }
32}