Skip to main content

hinge_rs/api/
recommendations.rs

1use crate::client::HingeClient;
2use crate::errors::HingeError;
3use crate::models::{RecommendationSubject, RecommendationsResponse, RecsV2Params};
4use crate::storage::Storage;
5use std::collections::HashMap;
6
7pub struct RecommendationsApi<'a, S: Storage + Clone> {
8    pub(super) client: &'a mut HingeClient<S>,
9}
10
11impl<S: Storage + Clone> RecommendationsApi<'_, S> {
12    pub async fn get(&mut self) -> Result<RecommendationsResponse, HingeError> {
13        self.client.get_recommendations().await
14    }
15
16    pub async fn get_with_params(
17        &mut self,
18        params: RecsV2Params,
19    ) -> Result<RecommendationsResponse, HingeError> {
20        self.client.get_recommendations_v2_params(params).await
21    }
22
23    pub async fn repeat_profiles(&mut self) -> Result<serde_json::Value, HingeError> {
24        self.client.repeat_profiles().await
25    }
26
27    pub fn apply_and_save(
28        &mut self,
29        recs: &mut RecommendationsResponse,
30        path: Option<&str>,
31    ) -> Result<(), HingeError> {
32        self.client.apply_recommendations_and_save(recs, path)
33    }
34
35    pub fn save(&self, path: &str) -> Result<(), HingeError> {
36        self.client.save_recommendations(path)
37    }
38
39    pub fn load(&mut self, path: &str) -> Result<(), HingeError> {
40        self.client.load_recommendations(path)
41    }
42
43    pub fn remove(&mut self, subject_id: &str) {
44        self.client.remove_recommendation(subject_id);
45    }
46
47    pub fn cached(&self) -> &HashMap<String, RecommendationSubject> {
48        &self.client.recommendations
49    }
50}