objectiveai_api/functions/function_fetcher/
objectiveai.rs1use crate::ctx;
4use objectiveai::error::StatusError;
5use std::sync::Arc;
6
7pub struct ObjectiveAiFetcher {
9 pub client: Arc<objectiveai::HttpClient>,
11}
12
13impl ObjectiveAiFetcher {
14 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}