1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//! `Preferences` resource — per-principal key/value UI/runtime
//! preferences.
//!
//! Mirrors the Python SDK's `client.preferences.*` surface. These are
//! org/user-scoped, not memory-scoped.
use serde_json::{json, Value};
use crate::error::Result;
use crate::http::HttpClient;
/// Preference key/value store.
///
/// Access via [`crate::Areev::preferences`].
pub struct Preferences<'a> {
http: &'a HttpClient,
}
impl<'a> Preferences<'a> {
/// Internal constructor — use [`crate::Areev::preferences`].
pub(crate) fn new(http: &'a HttpClient) -> Self {
Self { http }
}
/// All preferences for the calling principal.
pub async fn list(&self) -> Result<Value> {
self.http._get("/preferences", None).await
}
/// Read one preference by key.
pub async fn get(&self, key: &str) -> Result<Value> {
let path = format!("/preferences/{key}");
self.http._get(&path, None).await
}
/// Upsert one or more preference key/values.
pub async fn update(&self, preferences: Value) -> Result<Value> {
let body = json!({ "preferences": preferences });
self.http._put("/preferences", Some(&body)).await
}
/// Delete one preference by key.
pub async fn delete(&self, key: &str) -> Result<()> {
let path = format!("/preferences/{key}");
self.http._delete(&path).await.map(|_| ())
}
}