Skip to main content

objectiveai_api/functions/function_fetcher/
objectiveai.rs

1//! ObjectiveAI API implementation of the Function fetcher.
2
3use crate::ctx;
4use objectiveai::error::StatusError;
5use std::sync::Arc;
6
7/// Fetches Functions from the ObjectiveAI API.
8pub struct ObjectiveAiFetcher {
9    /// The HTTP client for API requests.
10    pub client: Arc<objectiveai::HttpClient>,
11}
12
13impl ObjectiveAiFetcher {
14    /// Creates a new ObjectiveAI Function fetcher.
15    pub fn new(client: Arc<objectiveai::HttpClient>) -> Self {
16        Self { client }
17    }
18}
19
20#[async_trait::async_trait]
21impl<CTXEXT> super::Fetcher<CTXEXT> for ObjectiveAiFetcher
22where
23    CTXEXT: Send + Sync + 'static,
24{
25    async fn fetch(
26        &self,
27        _ctx: ctx::Context<CTXEXT>,
28        owner: &str,
29        repository: &str,
30        commit: Option<&str>,
31    ) -> Result<
32        Option<objectiveai::functions::response::GetFunction>,
33        objectiveai::error::ResponseError,
34    > {
35        match objectiveai::functions::get_function(
36            &self.client,
37            owner,
38            repository,
39            commit,
40        )
41        .await
42        {
43            Ok(function) => Ok(Some(function)),
44            Err(e) if e.status() == 404 => Ok(None),
45            Err(e) => Err(objectiveai::error::ResponseError::from(&e)),
46        }
47    }
48}