Add endpoint to get information for an artist

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

@ -1,5 +1,5 @@
use crate::error::ApiResult;
use crate::models::{Anime, SearchResponse};
use crate::models::{Anime, Artist, SearchResponse};
use reqwest::Response;
use serde::Serialize;
use std::collections::HashMap;
@ -68,12 +68,12 @@ impl AnimeThemesClient {
Ok(response.remove("search").unwrap())
}
/// Returns an anime by a given slug title
/// Returns an anime by a given slug string
pub async fn anime(&self, slug: &str, include: &[&str]) -> ApiResult<Anime> {
let mut response: HashMap<String, Anime> = self
.api_get(
format!("/anime/{}", slug).as_str(),
&[("include", include.join(",").as_str())],
&[("include", include.join(","))],
)
.await?
.json()
@ -82,6 +82,20 @@ impl AnimeThemesClient {
Ok(response.remove("anime").unwrap())
}
/// Returns an artist by a given slug string
pub async fn artist(&self, slug: &str, include: &[&str]) -> ApiResult<Artist> {
let mut response: HashMap<String, Artist> = self
.api_get(
format!("/artist/{}", slug).as_str(),
&[("include", include.join(","))],
)
.await?
.json()
.await?;
Ok(response.remove("artist").unwrap())
}
/// Posts a get request to the API endpoint
async fn api_get<T: Serialize + ?Sized>(&self, path: &str, query: &T) -> ApiResult<Response> {
let response = self

@ -71,9 +71,10 @@ pub struct Artist {
#[serde(flatten)]
pub meta: EntryMetadata,
pub name: String,
pub slog: String,
pub slug: String,
#[serde(alias = "as")]
pub as_character: String,
pub as_character: Option<String>,
pub songs: Option<Vec<Song>>,
}
#[derive(Debug, Clone, Deserialize)]

@ -24,3 +24,11 @@ async fn it_returns_anime_by_slug() {
assert!(result.themes.is_some());
}
#[tokio::test]
async fn it_returns_artists_by_slug() {
let client = AnimeThemesClient::default();
let result = client.artist("lisa", &["songs"]).await.unwrap();
assert!(result.songs.is_some());
}

Loading…
Cancel
Save