1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use crate::media_container::{MediaContainer, User};
use crate::{
my_plex::{MyPlexAccount, MyPlexApiErrorResponse},
InternalHttpApi,
};
use reqwest::StatusCode;
use serde_xml_rs;
const USERS_URL: &str = "api/users/";
impl MyPlexAccount {
pub fn get_users(&self) -> crate::Result<Vec<User>> {
let mut response = self.get(USERS_URL)?;
if response.status() == StatusCode::OK {
let mc: MediaContainer = serde_xml_rs::from_str(response.text()?.as_str())?;
let users = mc.get_users();
Ok(users.unwrap_or_default())
} else {
let err: MyPlexApiErrorResponse = serde_xml_rs::from_str(response.text()?.as_str())?;
Err(crate::error::PlexApiError::from(err))
}
}
}