From b0c98d775b0b14f9e3366c037730ff001253a4cd Mon Sep 17 00:00:00 2001 From: AndrielFR Date: Thu, 2 Jan 2025 17:57:08 -0300 Subject: [PATCH] chore: remove `mal_id` var --- queries/get_anime.graphql | 4 ++-- queries/get_manga.graphql | 4 ++-- src/client.rs | 40 ++++++++++++++------------------------- src/models/anime.rs | 7 ++----- src/models/manga.rs | 5 +---- tests/anime.rs | 2 +- tests/manga.rs | 2 +- 7 files changed, 23 insertions(+), 41 deletions(-) diff --git a/queries/get_anime.graphql b/queries/get_anime.graphql index ef75261..dacdf15 100644 --- a/queries/get_anime.graphql +++ b/queries/get_anime.graphql @@ -1,8 +1,8 @@ # SPDX-License-Identifier: MIT # Copyright (c) 2022-2025 Andriel Ferreira -query ($id: Int, $mal_id: Int) { - Media (id: $id, idMal: $mal_id, type: ANIME) { +query ($id: Int) { + Media (id: $id, type: ANIME) { id idMal title { diff --git a/queries/get_manga.graphql b/queries/get_manga.graphql index 0bc46cb..1d327cf 100644 --- a/queries/get_manga.graphql +++ b/queries/get_manga.graphql @@ -1,8 +1,8 @@ # SPDX-License-Identifier: MIT # Copyright (c) 2022-2025 Andriel Ferreira -query ($id: Int, $mal_id: Int) { - Media (id: $id, idMal: $mal_id, type: MANGA) { +query ($id: Int) { + Media (id: $id, type: MANGA) { id idMal title { diff --git a/src/client.rs b/src/client.rs index 8257036..d29198b 100644 --- a/src/client.rs +++ b/src/client.rs @@ -43,22 +43,18 @@ impl Client { /// /// ``` /// # async fn f(client: rust_anilist::Client) -> rust_anilist::Result<()> { - /// let anime = client.get_anime(Some(1), None).await?; + /// let anime = client.get_anime(1).await?; /// /// # Ok(()) /// # } /// ``` - pub async fn get_anime( - &self, - id: Option, - mal_id: Option, - ) -> Result { - let variables = match id { - Some(id) => serde_json::json!({ "id": id }), - None => serde_json::json!({ "mal_id": mal_id.unwrap_or(0) }), - }; + pub async fn get_anime(&self, id: i64) -> Result { let data = self - .request(MediaType::Anime, Action::Get, variables) + .request( + MediaType::Anime, + Action::Get, + serde_json::json!({ "id": id }), + ) .await .unwrap(); @@ -87,22 +83,18 @@ impl Client { /// /// ``` /// # async fn f(client: rust_anilist::Client) -> rust_anilist::Result<()> { - /// let manga = client.get_manga(Some(1), None).await?; + /// let manga = client.get_manga(1).await?; /// /// # Ok(()) /// # } /// ``` - pub async fn get_manga( - &self, - id: Option, - mal_id: Option, - ) -> Result { - let variables = match id { - Some(id) => serde_json::json!({ "id": id }), - None => serde_json::json!({ "mal_id": mal_id.unwrap_or(0) }), - }; + pub async fn get_manga(&self, id: i64) -> Result { let data = self - .request(MediaType::Manga, Action::Get, variables) + .request( + MediaType::Manga, + Action::Get, + serde_json::json!({ "id": id }), + ) .await .unwrap(); @@ -207,10 +199,6 @@ impl Client { .await .unwrap(); - std::fs::File::create("user.json") - .unwrap() - .write_all(data["data"]["User"].to_string().as_bytes()) - .unwrap(); match serde_json::from_str::(&data["data"]["User"].to_string()) { Ok(user) => Ok(user), Err(e) => Err(crate::Error::ApiError(e.to_string())), diff --git a/src/models/anime.rs b/src/models/anime.rs index ba3aedf..cbf4235 100644 --- a/src/models/anime.rs +++ b/src/models/anime.rs @@ -77,14 +77,11 @@ pub struct Anime { impl Anime { pub async fn load_full(self) -> Result { if !self.is_full_loaded { - let mut anime = Client::default() - .get_anime(Some(self.id), self.id_mal) - .await - .unwrap(); + let mut anime = Client::default().get_anime(self.id).await.unwrap(); anime.is_full_loaded = true; Ok(anime) } else { - panic!("This anime is already full loaded") + panic!("This anime is already full loaded!") } } } diff --git a/src/models/manga.rs b/src/models/manga.rs index 3c389c9..7bebb10 100644 --- a/src/models/manga.rs +++ b/src/models/manga.rs @@ -71,10 +71,7 @@ pub struct Manga { impl Manga { pub async fn load_full(self) -> Result { if !self.is_full_loaded { - let mut manga = Client::default() - .get_manga(Some(self.id), self.id_mal) - .await - .unwrap(); + let mut manga = Client::default().get_manga(self.id).await.unwrap(); manga.is_full_loaded = true; Ok(manga) diff --git a/tests/anime.rs b/tests/anime.rs index 5286f36..efd3578 100644 --- a/tests/anime.rs +++ b/tests/anime.rs @@ -2,6 +2,6 @@ use rust_anilist::Client; #[tokio::test] async fn get_anime() { - let anime = Client::default().get_anime(Some(20), None).await; + let anime = Client::default().get_anime(20).await; assert!(anime.is_ok()) } diff --git a/tests/manga.rs b/tests/manga.rs index cb2ed0a..0526646 100644 --- a/tests/manga.rs +++ b/tests/manga.rs @@ -2,6 +2,6 @@ use rust_anilist::Client; #[tokio::test] async fn get_manga() { - let manga = Client::default().get_manga(Some(30026), None).await; + let manga = Client::default().get_manga(30026).await; assert!(manga.is_ok()) }