Add endpoint to get information for an entry

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

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

@ -32,3 +32,11 @@ async fn it_returns_artists_by_slug() {
assert!(result.songs.is_some());
}
#[tokio::test]
async fn it_returns_entries_by_id() {
let client = AnimeThemesClient::default();
let result = client.entry(11948, &["videos"]).await.unwrap();
assert!(result.videos.is_some())
}

Loading…
Cancel
Save