dzlib-rs/src/objects/chart.rs
2021-07-15 00:10:10 +02:00

63 lines
No EOL
1.9 KiB
Rust

use serde::Deserialize;
use super::{DzArray, Track, Album, Artist, Playlist, Podcast};
use crate::errors::ErrorKind;
use reqwest::Method;
#[derive(Deserialize, Debug)]
pub struct Chart {
pub tracks: DzArray<ChartTrack>,
pub albums: DzArray<ChartAlbum>,
pub artists: DzArray<ChartArtist>,
pub playlists: DzArray<Playlist>,
pub podcasts: DzArray<Podcast>,
}
impl Chart {
pub async fn get(client: &mut crate::Client, id: u64) -> Result<Self, ErrorKind> {
client.api_call(Method::GET, &format!("chart/{}", id), &()).await
}
pub async fn tracks(client: &mut crate::Client, id: u64) -> Result<DzArray<ChartTrack>, ErrorKind> {
client.api_call(Method::GET, &format!("chart/{}/tracks", id), &()).await
}
pub async fn albums(client: &mut crate::Client, id: u64) -> Result<DzArray<ChartAlbum>, ErrorKind> {
client.api_call(Method::GET, &format!("chart/{}/albums", id), &()).await
}
pub async fn artists(client: &mut crate::Client, id: u64) -> Result<DzArray<ChartArtist>, ErrorKind> {
client.api_call(Method::GET, &format!("chart/{}/artists", id), &()).await
}
pub async fn playlists(client: &mut crate::Client, id: u64) -> Result<DzArray<Playlist>, ErrorKind> {
client.api_call(Method::GET, &format!("chart/{}/playlists", id), &()).await
}
pub async fn podcasts(client: &mut crate::Client, id: u64) -> Result<DzArray<Podcast>, ErrorKind> {
client.api_call(Method::GET, &format!("chart/{}/podcasts", id), &()).await
}
}
#[derive(Deserialize, Debug)]
pub struct ChartTrack {
#[serde(flatten)]
pub track: Track,
pub position: u64,
}
#[derive(Deserialize, Debug)]
pub struct ChartAlbum {
#[serde(flatten)]
pub album: Album,
pub position: u64,
}
#[derive(Deserialize, Debug)]
pub struct ChartArtist {
#[serde(flatten)]
pub artist: Artist,
pub position: u64,
}