cortex_sdk/client/
ingest.rs1use super::transport::decode_value;
2use super::CortexDbClient;
3use crate::http::path;
4use crate::{DeleteJobResponse, IngestResponse, IngestionJobResponse, SdkResult};
5
6impl CortexDbClient {
7 pub fn ingest_text(
8 &self,
9 scope: &str,
10 source: &str,
11 text: &str,
12 ) -> SdkResult<serde_json::Value> {
13 self.post(
14 &path("/v1/ingest/text", &[("scope", scope), ("source", source)]),
15 text,
16 )
17 }
18
19 pub fn ingest_text_response(
20 &self,
21 scope: &str,
22 source: &str,
23 text: &str,
24 ) -> SdkResult<IngestResponse> {
25 decode_value(self.ingest_text(scope, source, text)?)
26 }
27
28 pub fn ingest_json(
29 &self,
30 scope: &str,
31 source: &str,
32 document: &str,
33 ) -> SdkResult<serde_json::Value> {
34 self.post(
35 &path("/v1/ingest/json", &[("scope", scope), ("source", source)]),
36 document,
37 )
38 }
39
40 pub fn ingest_json_response(
41 &self,
42 scope: &str,
43 source: &str,
44 document: &str,
45 ) -> SdkResult<IngestResponse> {
46 decode_value(self.ingest_json(scope, source, document)?)
47 }
48
49 pub fn ingest_csv(
50 &self,
51 scope: &str,
52 source: &str,
53 document: &str,
54 ) -> SdkResult<serde_json::Value> {
55 self.post(
56 &path("/v1/ingest/csv", &[("scope", scope), ("source", source)]),
57 document,
58 )
59 }
60
61 pub fn ingest_csv_response(
62 &self,
63 scope: &str,
64 source: &str,
65 document: &str,
66 ) -> SdkResult<IngestResponse> {
67 decode_value(self.ingest_csv(scope, source, document)?)
68 }
69
70 pub fn ingestion_job(&self, job_id: u64) -> SdkResult<serde_json::Value> {
71 self.get(&format!("/v1/ingest/jobs/{job_id}"))
72 }
73
74 pub fn ingestion_job_response(&self, job_id: u64) -> SdkResult<IngestionJobResponse> {
75 decode_value(self.ingestion_job(job_id)?)
76 }
77
78 pub fn delete_ingestion_job(&self, job_id: u64) -> SdkResult<DeleteJobResponse> {
79 decode_value(self.delete(&format!("/v1/ingest/jobs/{job_id}"))?)
80 }
81
82 pub fn retry_ingestion_job(&self, job_id: u64) -> SdkResult<IngestionJobResponse> {
83 decode_value(self.post(&format!("/v1/ingest/jobs/{job_id}/retry"), "")?)
84 }
85}