From be471e5f1ecfa96eb3d57426c3291cbfcafc9f37 Mon Sep 17 00:00:00 2001 From: Dev Goldy Date: Fri, 17 Nov 2023 13:38:20 +0000 Subject: [PATCH] refractor!, fix: random method category not takes String and search method now fixed --- README.md | 2 +- src/client.rs | 16 ++++++++-------- src/lib.rs | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 24933e5..31ce2db 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ async fn main() -> Result<(), Box> { ``` You can also retrieve specific categories of anime girls holding programming books like so: ```rust -let book = aghpb::random(Some("rust")).await?; +let book = aghpb::random(Some("rust".into())).await?; ```
diff --git a/src/client.rs b/src/client.rs index 1045c81..ffa90d3 100644 --- a/src/client.rs +++ b/src/client.rs @@ -33,11 +33,11 @@ impl Client { /// Grabs a random anime girl holding a programming book. /// /// Uses the ``/v1/random`` endpoint. - pub async fn random(&self, category: Option<&str>) -> Result> { - let mut queries: Vec<(&str, &str)> = Vec::new(); + pub async fn random(&self, category: Option) -> Result> { + let mut queries: Vec<(String, String)> = Vec::new(); if let Some(category) = category { - queries.push(("category", category)); + queries.push(("category".into(), category)); } let response = self.client.get(self.api_url.clone() + "/v1/random").query(&queries).send().await?; @@ -72,16 +72,16 @@ impl Client { /// Allows you to search for anime girls holding programming books. /// /// Uses the ``/v1/search`` endpoint. - pub async fn search(&self, query: &str, category: Option<&str>, limit: Option) -> Result, reqwest::Error> { - let mut queries: Vec<(&str, &str)> = Vec::new(); - queries.push(("query", query)); + pub async fn search(&self, query: String, category: Option, limit: Option) -> Result, reqwest::Error> { + let mut queries: Vec<(String, String)> = Vec::new(); + queries.push(("query".into(), query)); if let Some(category) = category { - queries.push(("category", category)); + queries.push(("category".into(), category)); } if let Some(limit) = limit { - queries.push(("limit", limit.to_string().as_str())); + queries.push(("limit".into(), limit.to_string())); } let res = self.client.get(self.api_url.clone() + "/v1/search").query(&queries).send().await?; diff --git a/src/lib.rs b/src/lib.rs index 1262f3b..f393338 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -70,7 +70,7 @@ fn get_client() -> Client { /// your own client. /// /// Uses the ``/v1/random`` endpoint. -pub async fn random(category: Option<&str>) -> Result> { +pub async fn random(category: Option) -> Result> { get_client().random(category).await } @@ -92,6 +92,6 @@ pub async fn categories() -> Result, reqwest::Error> { /// your own client. /// /// Uses the ``/v1/search`` endpoint. -pub async fn search(query: &str, category: Option<&str>, limit: Option) -> Result, reqwest::Error> { +pub async fn search(query: String, category: Option, limit: Option) -> Result, reqwest::Error> { get_client().search(query, category, limit).await } \ No newline at end of file