Merge pull request #3 from Trivernis/develop

Fixes for latest api version
main
Julius Riegel 3 years ago committed by GitHub
commit 46d7bd52f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

4
Cargo.lock generated

@ -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",

@ -1,6 +1,6 @@
[package]
name = "animethemes-rs"
version = "0.2.1"
version = "0.3.0"
authors = ["trivernis <trivernis@protonmail.com>"]
edition = "2018"
readme = "README.md"

@ -85,7 +85,8 @@ impl AnimeThemesClient {
/// Returns an entry by a given id
pub async fn entry(&self, id: u32, include: &[&str]) -> ApiResult<ThemeEntry> {
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<AnimeSynonym> {
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<Theme> {
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

@ -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";

@ -20,4 +20,5 @@ mod utils;
pub mod client;
pub mod error;
pub mod includes;
pub mod models;

@ -17,7 +17,9 @@ pub struct Anime {
pub year: u16,
pub season: AnimeSeason,
pub synopsis: String,
#[serde(alias = "animesynonyms")]
pub synonyms: Option<Vec<AnimeSynonym>>,
#[serde(alias = "animethemes")]
pub themes: Option<Vec<Theme>>,
pub series: Option<Vec<Series>>,
pub resource: Option<Vec<Resource>>,
@ -47,10 +49,11 @@ pub struct Theme {
pub theme_type: ThemeType,
#[serde(deserialize_with = "crate::utils::empty_string_as_none")]
pub sequence: Option<u16>,
pub group: String,
pub group: Option<String>,
pub slug: String,
pub song: Option<Song>,
pub anime: Option<Anime>,
#[serde(alias = "animethemeentries")]
pub entries: Option<Vec<ThemeEntry>>,
}
@ -66,6 +69,7 @@ pub struct Song {
pub meta: EntryMetadata,
pub title: String,
pub artists: Option<Vec<Artist>>,
#[serde(alias = "animethemes")]
pub themes: Option<Vec<Theme>>,
}
@ -91,6 +95,7 @@ pub struct ThemeEntry {
pub spoiler: bool,
pub notes: String,
pub videos: Option<Vec<Video>>,
#[serde(alias = "animetheme")]
pub theme: Option<Theme>,
}
@ -112,6 +117,7 @@ pub struct Video {
pub source: Option<VideoSource>,
pub overlap: VideoOverlap,
pub link: String,
#[serde(alias = "animethemeentries")]
pub entries: Option<Vec<ThemeEntry>>,
}
@ -175,10 +181,9 @@ pub enum ImageFacet {
pub struct SearchResponse {
pub anime: Option<Vec<Anime>>,
pub artists: Option<Vec<Artist>>,
pub entries: Option<Vec<ThemeEntry>>,
pub series: Option<Vec<Series>>,
pub songs: Option<Vec<Song>>,
pub synonyms: Option<Vec<AnimeSynonym>>,
#[serde(alias = "animethemes")]
pub themes: Option<Vec<Theme>>,
pub videos: Option<Vec<Video>>,
}

@ -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();

Loading…
Cancel
Save