Skip to main content

hinge_rs/client/
settings.rs

1use super::HingeClient;
2use crate::errors::HingeError;
3use crate::models::{
4    AccountInfo, AuthSettings, ExportStatus, NotificationSettings, UserSettings, UserTrait,
5};
6use crate::storage::Storage;
7
8impl<S: Storage + Clone> HingeClient<S> {
9    pub async fn get_content_settings(&self) -> Result<UserSettings, HingeError> {
10        let url = format!("{}/content/v1/settings", self.settings.base_url);
11        let res = self.http_get(&url).await?;
12        self.parse_response(res).await
13    }
14
15    pub async fn update_content_settings(
16        &self,
17        settings: UserSettings,
18    ) -> Result<serde_json::Value, HingeError> {
19        let url = format!("{}/content/v1/settings", self.settings.base_url);
20        let payload =
21            serde_json::to_value(&settings).map_err(|e| HingeError::Serde(e.to_string()))?;
22        let res = self.http_patch(&url, &payload).await?;
23        self.parse_response(res).await
24    }
25
26    pub async fn get_auth_settings(&self) -> Result<AuthSettings, HingeError> {
27        let url = format!("{}/auth/settings", self.settings.base_url);
28        let res = self.http_get(&url).await?;
29        self.parse_response(res).await
30    }
31
32    pub async fn get_notification_settings(&self) -> Result<NotificationSettings, HingeError> {
33        let url = format!("{}/notification/v1/settings", self.settings.base_url);
34        let res = self.http_get(&url).await?;
35        self.parse_response(res).await
36    }
37
38    pub async fn get_user_traits(&self) -> Result<Vec<UserTrait>, HingeError> {
39        let url = format!("{}/user/v2/traits", self.settings.base_url);
40        let res = self.http_get(&url).await?;
41        self.parse_response(res).await
42    }
43
44    pub async fn get_account_info(&self) -> Result<AccountInfo, HingeError> {
45        let url = format!("{}/store/v2/account", self.settings.base_url);
46        let res = self.http_get(&url).await?;
47        self.parse_response(res).await
48    }
49
50    pub async fn get_export_status(&self) -> Result<ExportStatus, HingeError> {
51        let url = format!("{}/user/export/status", self.settings.base_url);
52        let res = self.http_get(&url).await?;
53        self.parse_response(res).await
54    }
55}