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
48
49
50
51
52
53
54
55
56
use crate::{
my_plex::{MyPlexAccount, MyPlexApiErrorResponse},
InternalHttpApi,
};
use reqwest::StatusCode;
use std::collections::HashMap;
#[derive(Debug, Deserialize)]
#[cfg_attr(all(test, feature = "test_new_attributes"), serde(deny_unknown_fields))]
#[serde(rename_all = "camelCase")]
pub struct Privacy {
opt_out_playback: bool,
opt_out_library_stats: bool,
domain: String,
base_url: String,
metrics: Vec<Metric>,
}
#[derive(Debug, Deserialize)]
#[cfg_attr(all(test, feature = "test_new_attributes"), serde(deny_unknown_fields))]
struct Metric {
event: String,
status: String,
}
const PRIVACY_URL: &str = "api/v2/user/privacy";
impl MyPlexAccount {
pub async fn get_privacy(&self) -> crate::Result<Privacy> {
let response = self.get(PRIVACY_URL).await?;
if response.status() == StatusCode::OK {
let p: Privacy = response.json().await?;
Ok(p)
} else {
let err: MyPlexApiErrorResponse = response.json().await?;
Err(core::convert::From::from(err))
}
}
pub async fn set_privacy(
&self,
opt_out_playback: bool,
opt_out_library_stats: bool,
) -> crate::Result<()> {
let mut params = HashMap::new();
params.insert("optOutPlayback", if opt_out_playback { "1" } else { "0" });
params.insert(
"optOutLibraryStats",
if opt_out_library_stats { "1" } else { "0" },
);
self.put_form(PRIVACY_URL, ¶ms).await?;
Ok(())
}
}