Skip to content

Commit

Permalink
refractor!, fix: random method category not takes String and search m…
Browse files Browse the repository at this point in the history
…ethod now fixed
  • Loading branch information
THEGOLDENPRO committed Nov 17, 2023
1 parent 7db80db commit be471e5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
```
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?;
```

<br>
Expand Down
16 changes: 8 additions & 8 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Book, Box<dyn Error>> {
let mut queries: Vec<(&str, &str)> = Vec::new();
pub async fn random(&self, category: Option<String>) -> Result<Book, Box<dyn Error>> {
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?;
Expand Down Expand Up @@ -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<u8>) -> Result<Vec<BookResult>, reqwest::Error> {
let mut queries: Vec<(&str, &str)> = Vec::new();
queries.push(("query", query));
pub async fn search(&self, query: String, category: Option<String>, limit: Option<u8>) -> Result<Vec<BookResult>, 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?;
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fn get_client() -> Client {
/// your own client.
///
/// Uses the ``/v1/random`` endpoint.
pub async fn random(category: Option<&str>) -> Result<Book, Box<dyn Error>> {
pub async fn random(category: Option<String>) -> Result<Book, Box<dyn Error>> {
get_client().random(category).await
}

Expand All @@ -92,6 +92,6 @@ pub async fn categories() -> Result<Vec<String>, reqwest::Error> {
/// your own client.
///
/// Uses the ``/v1/search`` endpoint.
pub async fn search(query: &str, category: Option<&str>, limit: Option<u8>) -> Result<Vec<BookResult>, reqwest::Error> {
pub async fn search(query: String, category: Option<String>, limit: Option<u8>) -> Result<Vec<BookResult>, reqwest::Error> {
get_client().search(query, category, limit).await
}

0 comments on commit be471e5

Please sign in to comment.