From 7725daa2bb80028e6b28a86596b4f14d65d5e7bf Mon Sep 17 00:00:00 2001 From: trivernis Date: Sat, 22 May 2021 11:54:45 +0200 Subject: [PATCH] Add endpoint to get information for a song Signed-off-by: trivernis --- src/client.rs | 7 ++++++- src/models.rs | 2 +- src/tests/test_client.rs | 10 +++++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/client.rs b/src/client.rs index 833f690..a33192f 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1,6 +1,6 @@ use crate::error::ApiResult; use crate::models::{ - Anime, AnimeSynonym, Artist, Image, Resource, SearchResponse, Series, ThemeEntry, + Anime, AnimeSynonym, Artist, Image, Resource, SearchResponse, Series, Song, ThemeEntry, }; use reqwest::Response; use serde::de::DeserializeOwned; @@ -102,6 +102,11 @@ impl AnimeThemesClient { self.entry_by_id_with_include("series", slug, include).await } + /// Returns a song by id + pub async fn song(&self, id: u32, include: &[&str]) -> ApiResult { + self.entry_by_id_with_include("song", id, include).await + } + /// Returns a synonym by id pub async fn synonym(&self, id: u32, include: &[&str]) -> ApiResult { self.entry_by_id_with_include("synonym", id, include).await diff --git a/src/models.rs b/src/models.rs index 37827b7..5827528 100644 --- a/src/models.rs +++ b/src/models.rs @@ -64,7 +64,7 @@ pub struct Song { pub meta: EntryMetadata, pub title: String, pub artists: Option>, - pub entries: Option>, + pub themes: Option>, } #[derive(Debug, Clone, Deserialize)] diff --git a/src/tests/test_client.rs b/src/tests/test_client.rs index 1285e18..1084a94 100644 --- a/src/tests/test_client.rs +++ b/src/tests/test_client.rs @@ -69,9 +69,17 @@ async fn it_returns_series_by_slug() { } #[tokio::test] -async fn it_returns_synonyms_b_id() { +async fn it_returns_synonyms_by_id() { let client = AnimeThemesClient::default(); let result = client.synonym(2462, &["anime"]).await.unwrap(); assert!(result.anime.is_some()) } + +#[tokio::test] +async fn it_returns_songs_by_id() { + let client = AnimeThemesClient::default(); + let result = client.song(8188, &["themes"]).await.unwrap(); + + assert!(result.themes.is_some()) +}