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
use crate::media_container::{Device, DevicesMediaContainer};
use crate::{
my_plex::{HasMyPlexToken, MyPlexAccount, MyPlexApiErrorResponse},
InternalHttpApi,
};
use quick_xml;
use reqwest::StatusCode;
const DEVICES_URL: &str = "devices.xml";
impl MyPlexAccount {
pub async fn get_devices(&self) -> crate::Result<Vec<Device>> {
let response = self.get(DEVICES_URL).await?;
if response.status() == StatusCode::OK {
let mc: DevicesMediaContainer =
quick_xml::de::from_str(response.text().await?.as_str())?;
let mut devices: Vec<Device> = mc.get_devices().unwrap_or_default();
devices
.iter_mut()
.for_each(|d| d.set_auth_token(&self.auth_token));
Ok(devices)
} else {
let err: MyPlexApiErrorResponse =
quick_xml::de::from_str(response.text().await?.as_str())?;
Err(core::convert::From::from(err))
}
}
}