use crate::{Client, Error, Response, UserPrivate, UserPublic};
#[derive(Debug, Clone, Copy)]
pub struct UsersProfile<'a>(pub &'a Client);
impl UsersProfile<'_> {
pub async fn get_current_user(self) -> Result<Response<UserPrivate>, Error> {
self.0
.send_json(self.0.client.get(endpoint!("/v1/me")))
.await
}
pub async fn get_user(self, id: &str) -> Result<Response<UserPublic>, Error> {
self.0
.send_json(self.0.client.get(endpoint!("/v1/users/{}", id)))
.await
}
}
#[cfg(test)]
mod tests {
use crate::endpoints::client;
#[tokio::test]
async fn test_get_user() {
let user = client()
.users_profile()
.get_user("spotify")
.await
.unwrap()
.data;
assert_eq!(user.display_name.unwrap(), "Spotify");
assert_eq!(user.external_urls.len(), 1);
assert_eq!(
user.external_urls["spotify"],
"https://open.spotify.com/user/spotify"
);
assert_eq!(user.id, "spotify");
assert_eq!(user.images.len(), 1);
assert_eq!(
user.images[0].url,
"https://i.scdn.co/image/ab6775700000ee8555c25988a6ac314394d3fbf5"
);
}
#[tokio::test]
async fn test_get_current() {
let user = client()
.users_profile()
.get_current_user()
.await
.unwrap()
.data;
assert_eq!(user.external_urls.len(), 1);
assert_eq!(
user.external_urls["spotify"],
format!("https://open.spotify.com/user/{}", user.id)
);
}
}