objectiveai_api/functions/profiles/
client.rs1use crate::ctx;
4use std::sync::Arc;
5
6pub struct Client<CTXEXT, PFN, RTRVL> {
11 pub profile_fetcher: Arc<PFN>,
13 pub retrieval_client: Arc<RTRVL>,
15 pub _ctx_ext: std::marker::PhantomData<CTXEXT>,
17}
18
19impl<CTXEXT, PFN, RTRVL> Client<CTXEXT, PFN, RTRVL> {
20 pub fn new(
22 profile_fetcher: Arc<PFN>,
23 retrieval_client: Arc<RTRVL>,
24 ) -> Self {
25 Self {
26 profile_fetcher,
27 retrieval_client,
28 _ctx_ext: std::marker::PhantomData,
29 }
30 }
31}
32
33impl<CTXEXT, PFN, RTRVL> Client<CTXEXT, PFN, RTRVL>
34where
35 CTXEXT: Send + Sync + 'static,
36 PFN: crate::functions::profile_fetcher::Fetcher<CTXEXT> + Send + Sync + 'static,
37 RTRVL: super::retrieval_client::Client<CTXEXT> + Send + Sync + 'static,
38{
39 pub async fn list_profiles(
41 &self,
42 ctx: ctx::Context<CTXEXT>,
43 ) -> Result<
44 objectiveai::functions::profiles::response::ListProfile,
45 objectiveai::error::ResponseError,
46 > {
47 self.retrieval_client.list_profiles(ctx).await
48 }
49
50 pub async fn get_profile(
52 &self,
53 ctx: ctx::Context<CTXEXT>,
54 owner: &str,
55 repository: &str,
56 commit: Option<&str>,
57 ) -> Result<
58 objectiveai::functions::profiles::response::GetProfile,
59 objectiveai::error::ResponseError,
60 > {
61 self.profile_fetcher
62 .fetch(ctx, owner, repository, commit)
63 .await?
64 .ok_or_else(|| objectiveai::error::ResponseError {
65 code: 404,
66 message: serde_json::json!({
67 "kind": "profiles",
68 "error": "Profile not found"
69 }),
70 })
71 }
72
73 pub async fn get_profile_usage(
75 &self,
76 ctx: ctx::Context<CTXEXT>,
77 owner: &str,
78 repository: &str,
79 commit: Option<&str>,
80 ) -> Result<
81 objectiveai::functions::profiles::response::UsageProfile,
82 objectiveai::error::ResponseError,
83 > {
84 self.retrieval_client
85 .get_profile_usage(ctx, owner, repository, commit)
86 .await
87 }
88}