context69-sdk 0.2.0

Async Rust SDK for the Context69 HTTP API.
Documentation
use context69_contracts::{
    DoclingSettingsResponse, ProviderAccountResponse, RuntimeSettingsResponse,
    SearchSettingsResponse, UpdateDoclingSettingsRequest, UpdateRuntimeSettingsRequest,
    UpdateSearchSettingsRequest, UpsertProviderAccountRequest,
};
use reqwest::Method;

use crate::{Context69Client, Error};

impl Context69Client {
    pub async fn get_runtime_settings(&self) -> Result<RuntimeSettingsResponse, Error> {
        self.execute_json(
            self.authorized_request(Method::GET, "/v1/settings/runtime")
                .await?,
        )
        .await
    }

    pub async fn update_runtime_settings(
        &self,
        request: &UpdateRuntimeSettingsRequest,
    ) -> Result<RuntimeSettingsResponse, Error> {
        self.execute_json(
            self.authorized_request(Method::PUT, "/v1/settings/runtime")
                .await?
                .json(request),
        )
        .await
    }

    pub async fn list_provider_accounts(&self) -> Result<Vec<ProviderAccountResponse>, Error> {
        self.execute_json(
            self.authorized_request(Method::GET, "/v1/settings/provider-accounts")
                .await?,
        )
        .await
    }

    pub async fn create_provider_account(
        &self,
        request: &UpsertProviderAccountRequest,
    ) -> Result<ProviderAccountResponse, Error> {
        self.execute_json(
            self.authorized_request(Method::POST, "/v1/settings/provider-accounts")
                .await?
                .json(request),
        )
        .await
    }

    pub async fn update_provider_account(
        &self,
        request: &UpsertProviderAccountRequest,
    ) -> Result<ProviderAccountResponse, Error> {
        self.execute_json(
            self.authorized_request(Method::PUT, "/v1/settings/provider-accounts")
                .await?
                .json(request),
        )
        .await
    }

    pub async fn delete_provider_account(&self, account_key: &str) -> Result<(), Error> {
        let path = format!("/v1/settings/provider-accounts/{account_key}");
        self.execute_empty(self.authorized_request(Method::DELETE, &path).await?)
            .await
    }

    pub async fn get_docling_settings(&self) -> Result<DoclingSettingsResponse, Error> {
        self.execute_json(
            self.authorized_request(Method::GET, "/v1/settings/docling")
                .await?,
        )
        .await
    }

    pub async fn update_docling_settings(
        &self,
        request: &UpdateDoclingSettingsRequest,
    ) -> Result<DoclingSettingsResponse, Error> {
        self.execute_json(
            self.authorized_request(Method::PUT, "/v1/settings/docling")
                .await?
                .json(request),
        )
        .await
    }

    pub async fn get_search_settings(&self) -> Result<SearchSettingsResponse, Error> {
        self.execute_json(
            self.authorized_request(Method::GET, "/v1/settings/search")
                .await?,
        )
        .await
    }

    pub async fn update_search_settings(
        &self,
        request: &UpdateSearchSettingsRequest,
    ) -> Result<SearchSettingsResponse, Error> {
        self.execute_json(
            self.authorized_request(Method::PUT, "/v1/settings/search")
                .await?
                .json(request),
        )
        .await
    }
}