Add endpoint to get information for a series

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/1/head
trivernis 3 years ago
parent 27b33488ce
commit ec1dafe7d6
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -1,5 +1,5 @@
use crate::error::ApiResult;
use crate::models::{Anime, Artist, Image, Resource, SearchResponse, ThemeEntry};
use crate::models::{Anime, Artist, Image, Resource, SearchResponse, Series, ThemeEntry};
use reqwest::Response;
use serde::de::DeserializeOwned;
use serde::Serialize;
@ -95,6 +95,11 @@ impl AnimeThemesClient {
self.entry_by_id_with_include("resource", id, include).await
}
/// Returns a series by slug
pub async fn series(&self, slug: &str, include: &[&str]) -> ApiResult<Series> {
self.entry_by_id_with_include("series", slug, include).await
}
/// Generic endpoint with the format /<endpoint>/<id> returning the type on the json field <endpoint>
async fn entry_by_id_with_include<T: DeserializeOwned, I: Display>(
&self,

@ -132,6 +132,7 @@ pub struct Series {
pub meta: EntryMetadata,
pub name: String,
pub slug: String,
pub anime: Option<Vec<Anime>>,
}
#[derive(Debug, Clone, Deserialize)]

@ -56,3 +56,14 @@ async fn it_returns_resources_by_id() {
assert!(result.anime.is_some())
}
#[tokio::test]
async fn it_returns_series_by_slug() {
let client = AnimeThemesClient::default();
let result = client
.series("shingeki_no_kyojin", &["anime"])
.await
.unwrap();
assert!(result.anime.is_some())
}

Loading…
Cancel
Save