diff --git a/Cargo.lock b/Cargo.lock index c6c1220..e935a6d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,8 +1,10 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "animethemes-rs" -version = "0.2.1" +version = "0.3.0" dependencies = [ "reqwest", "serde", diff --git a/Cargo.toml b/Cargo.toml index 4516f59..3d723f3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "animethemes-rs" -version = "0.2.1" +version = "0.3.0" authors = ["trivernis "] edition = "2018" readme = "README.md" diff --git a/src/client.rs b/src/client.rs index e45df36..4252e14 100644 --- a/src/client.rs +++ b/src/client.rs @@ -85,7 +85,8 @@ impl AnimeThemesClient { /// Returns an entry by a given id pub async fn entry(&self, id: u32, include: &[&str]) -> ApiResult { - self.entry_by_id_with_include("entry", id, include).await + self.entry_by_id_with_include("animethemeentry", id, include) + .await } /// Returns an image by id @@ -110,12 +111,14 @@ impl AnimeThemesClient { /// 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 + self.entry_by_id_with_include("animesynonym", id, include) + .await } /// Returns a theme by id pub async fn theme(&self, id: u32, include: &[&str]) -> ApiResult { - self.entry_by_id_with_include("theme", id, include).await + self.entry_by_id_with_include("animetheme", id, include) + .await } /// Returns a video by basename diff --git a/src/includes.rs b/src/includes.rs new file mode 100644 index 0000000..b52eaa1 --- /dev/null +++ b/src/includes.rs @@ -0,0 +1,10 @@ +pub static THEMES: &str = "animethemes"; +pub static THEME: &str = "animetheme"; +pub static THEME_ENTRIES: &str = "animethemeentries"; +pub static SYNONYMS: &str = "animesynonyms"; +pub static RESOURCES: &str = "resources"; +pub static IMAGES: &str = "images"; +pub static SERIES: &str = "series"; +pub static SONGS: &str = "songs"; +pub static VIDEOS: &str = "videos"; +pub static ANIME: &str = "anime"; diff --git a/src/lib.rs b/src/lib.rs index 77d0b78..b733efb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,4 +20,5 @@ mod utils; pub mod client; pub mod error; +pub mod includes; pub mod models; diff --git a/src/models.rs b/src/models.rs index 5f200d5..c38efc4 100644 --- a/src/models.rs +++ b/src/models.rs @@ -17,7 +17,9 @@ pub struct Anime { pub year: u16, pub season: AnimeSeason, pub synopsis: String, + #[serde(alias = "animesynonyms")] pub synonyms: Option>, + #[serde(alias = "animethemes")] pub themes: Option>, pub series: Option>, pub resource: Option>, @@ -47,10 +49,11 @@ pub struct Theme { pub theme_type: ThemeType, #[serde(deserialize_with = "crate::utils::empty_string_as_none")] pub sequence: Option, - pub group: String, + pub group: Option, pub slug: String, pub song: Option, pub anime: Option, + #[serde(alias = "animethemeentries")] pub entries: Option>, } @@ -66,6 +69,7 @@ pub struct Song { pub meta: EntryMetadata, pub title: String, pub artists: Option>, + #[serde(alias = "animethemes")] pub themes: Option>, } @@ -91,6 +95,7 @@ pub struct ThemeEntry { pub spoiler: bool, pub notes: String, pub videos: Option>, + #[serde(alias = "animetheme")] pub theme: Option, } @@ -112,6 +117,7 @@ pub struct Video { pub source: Option, pub overlap: VideoOverlap, pub link: String, + #[serde(alias = "animethemeentries")] pub entries: Option>, } @@ -175,10 +181,9 @@ pub enum ImageFacet { pub struct SearchResponse { pub anime: Option>, pub artists: Option>, - pub entries: Option>, pub series: Option>, pub songs: Option>, - pub synonyms: Option>, + #[serde(alias = "animethemes")] pub themes: Option>, pub videos: Option>, } diff --git a/src/tests/test_client.rs b/src/tests/test_client.rs index 25695c5..25e653e 100644 --- a/src/tests/test_client.rs +++ b/src/tests/test_client.rs @@ -1,15 +1,14 @@ use crate::client::AnimeThemesClient; +use crate::includes::{ANIME, SONGS, THEME, THEMES, THEME_ENTRIES, VIDEOS}; #[tokio::test] async fn it_searches() { let client = AnimeThemesClient::default(); let result = client.search("Vivy", &[], &[]).await.unwrap(); - assert!(result.entries.is_some()); assert!(result.artists.is_some()); assert!(result.songs.is_some()); assert!(result.anime.is_some()); assert!(result.series.is_some()); - assert!(result.synonyms.is_some()); assert!(result.themes.is_some()); assert!(result.videos.is_some()); } @@ -18,7 +17,7 @@ async fn it_searches() { async fn it_returns_anime_by_slug() { let client = AnimeThemesClient::default(); let result = client - .anime("vivy_fluorite_eyes_song", &["themes"]) + .anime("vivy_fluorite_eyes_song", &[THEMES]) .await .unwrap(); @@ -28,7 +27,7 @@ async fn it_returns_anime_by_slug() { #[tokio::test] async fn it_returns_artists_by_slug() { let client = AnimeThemesClient::default(); - let result = client.artist("lisa", &["songs"]).await.unwrap(); + let result = client.artist("lisa", &[SONGS]).await.unwrap(); assert!(result.songs.is_some()); } @@ -36,7 +35,7 @@ async fn it_returns_artists_by_slug() { #[tokio::test] async fn it_returns_entries_by_id() { let client = AnimeThemesClient::default(); - let result = client.entry(11948, &["videos", "theme"]).await.unwrap(); + let result = client.entry(11948, &[VIDEOS, THEME]).await.unwrap(); assert!(result.videos.is_some()); assert!(result.theme.is_some()); @@ -45,7 +44,7 @@ async fn it_returns_entries_by_id() { #[tokio::test] async fn it_returns_images_by_id() { let client = AnimeThemesClient::default(); - let result = client.image(7247, &["anime"]).await.unwrap(); + let result = client.image(7247, &[ANIME]).await.unwrap(); assert!(result.anime.is_some()) } @@ -53,7 +52,7 @@ async fn it_returns_images_by_id() { #[tokio::test] async fn it_returns_resources_by_id() { let client = AnimeThemesClient::default(); - let result = client.resource(3588, &["anime"]).await.unwrap(); + let result = client.resource(3588, &[ANIME]).await.unwrap(); assert!(result.anime.is_some()) } @@ -61,10 +60,7 @@ async fn it_returns_resources_by_id() { #[tokio::test] async fn it_returns_series_by_slug() { let client = AnimeThemesClient::default(); - let result = client - .series("shingeki_no_kyojin", &["anime"]) - .await - .unwrap(); + let result = client.series("shingeki_no_kyojin", &[ANIME]).await.unwrap(); assert!(result.anime.is_some()) } @@ -72,7 +68,7 @@ async fn it_returns_series_by_slug() { #[tokio::test] async fn it_returns_synonyms_by_id() { let client = AnimeThemesClient::default(); - let result = client.synonym(2462, &["anime"]).await.unwrap(); + let result = client.synonym(2462, &[ANIME]).await.unwrap(); assert!(result.anime.is_some()) } @@ -80,7 +76,7 @@ async fn it_returns_synonyms_by_id() { #[tokio::test] async fn it_returns_songs_by_id() { let client = AnimeThemesClient::default(); - let result = client.song(8188, &["themes"]).await.unwrap(); + let result = client.song(8188, &[THEMES]).await.unwrap(); assert!(result.themes.is_some()) } @@ -88,7 +84,7 @@ async fn it_returns_songs_by_id() { #[tokio::test] async fn it_returns_themes_by_id() { let client = AnimeThemesClient::default(); - let result = client.theme(8187, &["entries"]).await.unwrap(); + let result = client.theme(8187, &[THEME_ENTRIES]).await.unwrap(); assert!(result.entries.is_some()) } @@ -97,7 +93,7 @@ async fn it_returns_themes_by_id() { async fn it_returns_videos_by_basename() { let client = AnimeThemesClient::default(); let result = client - .video("KimiUso-OP2.webm", &["entries"]) + .video("KimiUso-OP2.webm", &[THEME_ENTRIES]) .await .unwrap();